Clang format pool (#255)
* Update comment prefix + add github action * Clang Format pool * fix clang format version * Fix pool clang format
This commit is contained in:
@@ -20,6 +20,7 @@ jobs:
|
|||||||
run: >
|
run: >
|
||||||
clang-format --dry-run -Werror
|
clang-format --dry-run -Werror
|
||||||
include/bitset.h source/bitset.c
|
include/bitset.h source/bitset.c
|
||||||
|
include/pool.h source/pool.c
|
||||||
include/card.h source/card.c
|
include/card.h source/card.c
|
||||||
include/hand_analysis.h source/hand_analysis.c
|
include/hand_analysis.h source/hand_analysis.c
|
||||||
include/list.h source/list.c
|
include/list.h source/list.c
|
||||||
|
|||||||
+47
-46
@@ -1,65 +1,66 @@
|
|||||||
#ifndef POOL_H
|
#ifndef POOL_H
|
||||||
#define POOL_H
|
#define POOL_H
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "bitset.h"
|
#include "bitset.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef POOLS_TEST_ENV
|
#ifdef POOLS_TEST_ENV
|
||||||
#define POOLS_DEF_FILE "def_test_mempool.h"
|
#define POOLS_DEF_FILE "def_test_mempool.h"
|
||||||
#else
|
#else
|
||||||
#define POOLS_DEF_FILE "def_balatro_mempool.h"
|
#define POOLS_DEF_FILE "def_balatro_mempool.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define POOL_DECLARE_TYPE(type) \
|
#define POOL_DECLARE_TYPE(type) \
|
||||||
typedef struct \
|
typedef struct \
|
||||||
{ \
|
{ \
|
||||||
Bitset* bitset; \
|
Bitset* bitset; \
|
||||||
type * objects; \
|
type* objects; \
|
||||||
} type##Pool; \
|
} type##Pool; \
|
||||||
type *pool_get_##type(); \
|
type* pool_get_##type(); \
|
||||||
void pool_free_##type(type *obj); \
|
void pool_free_##type(type* obj); \
|
||||||
int pool_idx_##type(type *obj); \
|
int pool_idx_##type(type* obj); \
|
||||||
type *pool_at_##type(int idx);
|
type* pool_at_##type(int idx);
|
||||||
|
|
||||||
#define POOL_DEFINE_TYPE(type, capacity) \
|
#define POOL_DEFINE_TYPE(type, capacity) \
|
||||||
BITSET_DEFINE(type##_bitset, capacity) \
|
BITSET_DEFINE(type##_bitset, capacity) \
|
||||||
static type type##_storage[capacity]; \
|
static type type##_storage[capacity]; \
|
||||||
static type##Pool type##_pool = \
|
static type##Pool type##_pool = { \
|
||||||
{ \
|
.bitset = &type##_bitset, \
|
||||||
.bitset = & type##_bitset, \
|
.objects = type##_storage, \
|
||||||
.objects = type##_storage, \
|
}; \
|
||||||
}; \
|
type* pool_get_##type() \
|
||||||
type * pool_get_##type() \
|
{ \
|
||||||
{ \
|
int free_offset = bitset_set_next_free_idx(type##_pool.bitset); \
|
||||||
int free_offset = bitset_set_next_free_idx(type##_pool.bitset); \
|
if (free_offset == -1) \
|
||||||
if(free_offset == -1) return NULL; \
|
return NULL; \
|
||||||
return &type##_pool.objects[free_offset]; \
|
return &type##_pool.objects[free_offset]; \
|
||||||
} \
|
} \
|
||||||
void pool_free_##type(type *entry) \
|
void pool_free_##type(type* entry) \
|
||||||
{ \
|
{ \
|
||||||
if(entry == NULL) return; \
|
if (entry == NULL) \
|
||||||
int offset = entry - &type##_pool.objects[0]; \
|
return; \
|
||||||
bitset_set_idx(type##_pool.bitset, offset, false); \
|
int offset = entry - &type##_pool.objects[0]; \
|
||||||
} \
|
bitset_set_idx(type##_pool.bitset, offset, false); \
|
||||||
int pool_idx_##type(type *entry) \
|
} \
|
||||||
{ \
|
int pool_idx_##type(type* entry) \
|
||||||
return entry - &type##_pool.objects[0]; \
|
{ \
|
||||||
} \
|
return entry - &type##_pool.objects[0]; \
|
||||||
type *pool_at_##type(int idx) \
|
} \
|
||||||
{ \
|
type* pool_at_##type(int idx) \
|
||||||
if(idx < 0 || idx >= (type##_pool.bitset)->cap) return NULL; \
|
{ \
|
||||||
return &type##_pool.objects[idx]; \
|
if (idx < 0 || idx >= (type##_pool.bitset)->cap) \
|
||||||
|
return NULL; \
|
||||||
|
return &type##_pool.objects[idx]; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define POOL_GET(type) pool_get_##type()
|
#define POOL_GET(type) pool_get_##type()
|
||||||
#define POOL_FREE(type, obj) pool_free_##type(obj)
|
#define POOL_FREE(type, obj) pool_free_##type(obj)
|
||||||
#define POOL_IDX(type, obj) pool_idx_##type(obj) // the index of the object
|
#define POOL_IDX(type, obj) pool_idx_##type(obj) // the index of the object
|
||||||
#define POOL_AT(type, idx) pool_at_##type(idx) // the object at
|
#define POOL_AT(type, idx) pool_at_##type(idx) // the object at
|
||||||
|
|
||||||
#define POOL_ENTRY(name, capacity) \
|
#define POOL_ENTRY(name, capacity) POOL_DECLARE_TYPE(name);
|
||||||
POOL_DECLARE_TYPE(name);
|
|
||||||
#include POOLS_DEF_FILE
|
#include POOLS_DEF_FILE
|
||||||
#undef POOL_ENTRY
|
#undef POOL_ENTRY
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
|
|
||||||
#define POOL_ENTRY(name, capacity) \
|
#define POOL_ENTRY(name, capacity) POOL_DEFINE_TYPE(name, capacity);
|
||||||
POOL_DEFINE_TYPE(name, capacity);
|
|
||||||
#include POOLS_DEF_FILE
|
#include POOLS_DEF_FILE
|
||||||
#undef POOL_ENTRY
|
#undef POOL_ENTRY
|
||||||
|
|||||||
Reference in New Issue
Block a user