Testing ideas for array implementation
This commit is contained in:
parent
3a49dba366
commit
50e23d8a13
src/containers
52
src/containers/array/array.h
Normal file
52
src/containers/array/array.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
typedef struct int_array IntArray;
|
||||
struct int_array {
|
||||
int *items;
|
||||
u64 count;
|
||||
u64 capacity;
|
||||
};
|
||||
|
||||
#define U64_RSHIFT_OR_1(X) (((u64)X) | (((u64)X) >> 1))
|
||||
#define U64_RSHIFT_OR_2(X) (((u64)X) | (((u64)X) >> 2))
|
||||
#define U64_RSHIFT_OR_4(X) (((u64)X) | (((u64)X) >> 4))
|
||||
#define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8))
|
||||
#define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16))
|
||||
#define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32))
|
||||
#define U64_ROUND_UP_POW2(X) ( \
|
||||
( \
|
||||
U64_RSHIFT_OR_32( \
|
||||
U64_RSHIFT_OR_16( \
|
||||
U64_RSHIFT_OR_8( \
|
||||
U64_RSHIFT_OR_4( \
|
||||
U64_RSHIFT_OR_2( \
|
||||
U64_RSHIFT_OR_1(X - 1) \
|
||||
) \
|
||||
) \
|
||||
) \
|
||||
) \
|
||||
) \
|
||||
) + 1 \
|
||||
)
|
||||
|
||||
#define INT_ARRAY_COUNT_ARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int))
|
||||
|
||||
#define wapp_int_array(...) ((IntArray){ \
|
||||
.items = (int[U64_ROUND_UP_POW2(INT_ARRAY_COUNT_ARGS(__VA_ARGS__) * 2)]){__VA_ARGS__}, \
|
||||
.count = INT_ARRAY_COUNT_ARGS(__VA_ARGS__), \
|
||||
.capacity = U64_ROUND_UP_POW2(INT_ARRAY_COUNT_ARGS(__VA_ARGS__) * 2) \
|
||||
})
|
||||
#define wapp_int_array_with_capacity(CAPACITY) ((IntArray){.items = (int[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !ARRAY_H
|
@ -2,6 +2,7 @@
|
||||
#define WAPP_CONTAINERS_H
|
||||
|
||||
#include "dbl_list/dbl_list.h"
|
||||
#include "array/array.h"
|
||||
#include "../common/wapp_common.h"
|
||||
|
||||
#endif // !WAPP_CONTAINERS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user