renamed first argument of all methods to 'self'
This commit is contained in:
@@ -8,7 +8,7 @@ typedef struct Array_ {
|
||||
u32 size;
|
||||
} Array_;
|
||||
|
||||
/// creates Array_ from a const array
|
||||
/// creates Array_ from self const array
|
||||
#define ARRAY(T, A...) Array_construct_size(((T[])A), sizeof((T[])A))
|
||||
|
||||
#define Array_construct(DATA, T, COUNT) Array_construct_size(DATA, (COUNT) * sizeof(T))
|
||||
@@ -20,31 +20,31 @@ static inline Array_ Array_alloc_size(u32 size){
|
||||
return Array_construct_size(malloc(size), size);
|
||||
}
|
||||
|
||||
#define Array_realloc(AR, T, COUNT) Array_realloc_size(AR, (COUNT) * sizeof(T))
|
||||
#define Array_realloc(SELF, T, COUNT) Array_realloc_size(SELF, (COUNT) * sizeof(T))
|
||||
|
||||
static inline void Array_realloc_size(Array_* ar, u32 new_size){
|
||||
ar->data = realloc(ar->data, new_size);
|
||||
ar->size = new_size;
|
||||
static inline void Array_realloc_size(Array_* self, u32 new_size){
|
||||
self->data = realloc(self->data, new_size);
|
||||
self->size = new_size;
|
||||
}
|
||||
|
||||
static inline Array_ Array_copy(const Array_ src){
|
||||
Array_ copy = Array_alloc_size(src.size);
|
||||
static inline Array_ Array_copy(const Array_ self){
|
||||
Array_ copy = Array_alloc_size(self.size);
|
||||
if(copy.data != NULL)
|
||||
memcpy(copy.data, src.data, src.size);
|
||||
memcpy(copy.data, self.data, self.size);
|
||||
return copy;
|
||||
}
|
||||
|
||||
#define Array_len(A, T) (A.size / sizeof(T))
|
||||
#define Array_memset(A, VAL) memset(A.data, VAL, A.size)
|
||||
#define Array_len(SELF, T) (SELF.size / sizeof(T))
|
||||
#define Array_memset(SELF, VAL) memset(SELF.data, VAL, SELF.size)
|
||||
|
||||
#define struct_castTo_Array(STRUCT_PTR) Array_construct_size((STRUCT_PTR), sizeof(*STRUCT_PTR))
|
||||
|
||||
///@return a[0..i-1]
|
||||
static inline Array(u8) Array_sliceTo(const Array(u8) a, u32 i){
|
||||
return Array_construct_size(a.data, i);
|
||||
///@return self[0..i-1]
|
||||
static inline Array(u8) Array_sliceTo(const Array(u8) self, u32 i){
|
||||
return Array_construct_size(self.data, i);
|
||||
}
|
||||
|
||||
///@return a[i...]
|
||||
static inline Array(u8) Array_sliceFrom(const Array(u8) a, u32 i){
|
||||
return Array_construct_size((u8*)a.data + i, a.size - i);
|
||||
///@return self[i...]
|
||||
static inline Array(u8) Array_sliceFrom(const Array(u8) self, u32 i){
|
||||
return Array_construct_size((u8*)self.data + i, self.size - i);
|
||||
}
|
||||
|
||||
@@ -19,18 +19,18 @@ typedef struct HashMapBucket {
|
||||
#define HashMap(T) HashMap_
|
||||
|
||||
typedef struct HashMap_ {
|
||||
HashMapBucket* table;
|
||||
FreeFunction NULLABLE(value_destructor);
|
||||
NULLABLE(HashMapBucket*) table;
|
||||
NULLABLE(FreeFunction) value_destructor;
|
||||
u32 value_t_size;
|
||||
u32 height;
|
||||
u16 height_n;
|
||||
} HashMap_;
|
||||
|
||||
#define HashMap_construct(PTR, T, VALUE_DESTRUCTOR) HashMap_construct_size(PTR, sizeof(T), VALUE_DESTRUCTOR)
|
||||
void HashMap_construct_size(HashMap_* ptr, u32 value_t_size, FreeFunction NULLABLE(value_destructor));
|
||||
void HashMap_destroy(HashMap_* ptr);
|
||||
#define HashMap_construct(SELF, T, VALUE_DESTRUCTOR) HashMap_construct_size(SELF, sizeof(T), VALUE_DESTRUCTOR)
|
||||
void HashMap_construct_size(HashMap_* self, u32 value_t_size, FreeFunction NULLABLE(value_destructor));
|
||||
void HashMap_destroy(HashMap_* self);
|
||||
|
||||
bool HashMap_tryPush(HashMap_* ptr, const str key, void* value_ptr);
|
||||
void HashMap_pushOrUpdate(HashMap_* ptr, const str key, void* value_ptr);
|
||||
NULLABLE(void*) HashMap_tryGetPtr(const HashMap_* ptr, const str key);
|
||||
bool HashMap_tryDelete(HashMap_* ptr, const str key);
|
||||
bool HashMap_tryPush(HashMap_* self, const str key, void* value_ptr);
|
||||
void HashMap_pushOrUpdate(HashMap_* self, const str key, void* value_ptr);
|
||||
NULLABLE(void*) HashMap_tryGetPtr(const HashMap_* self, const str key);
|
||||
bool HashMap_tryDelete(HashMap_* self, const str key);
|
||||
|
||||
@@ -21,13 +21,13 @@ List_ List_alloc_size(u32 initial_size);
|
||||
|
||||
List_ List_copy(List_ src);
|
||||
|
||||
void* List_expand_size(List_* ptr, u32 size_to_add);
|
||||
#define List_push(L, T, VALUE) *(T*)(List_expand_size(L, sizeof(T))) = VALUE
|
||||
#define List_pushMany(L, T, VALUES_PTR, COUNT) List_push_size(L, VALUES_PTR, (COUNT) * sizeof(T))
|
||||
void List_push_size(List_* ptr, void* values, u32 size);
|
||||
void* List_expand_size(List_* self, u32 size_to_add);
|
||||
#define List_push(SELF, T, VALUE) *(T*)(List_expand_size(SELF, sizeof(T))) = VALUE
|
||||
#define List_pushMany(SELF, T, VALUES_PTR, COUNT) List_push_size(SELF, VALUES_PTR, (COUNT) * sizeof(T))
|
||||
void List_push_size(List_* self, void* values, u32 size);
|
||||
|
||||
#define List_removeAt(L, T, I, COUNT) List_removeAt_size(L, (I)*sizeof(T), (COUNT) * sizeof(T))
|
||||
bool List_removeAt_size(List_* ptr, u32 i, u32 remove_size);
|
||||
#define List_removeAt(SELF, T, I, COUNT) List_removeAt_size(SELF, (I)*sizeof(T), (COUNT) * sizeof(T))
|
||||
bool List_removeAt_size(List_* self, u32 i, u32 remove_size);
|
||||
|
||||
#define List_len(L, T) ((L)->size / sizeof(T))
|
||||
#define List_castTo_Array(l) Array_construct_size(l.data, l.size)
|
||||
#define List_len(SELF, T) (SELF.size / sizeof(T))
|
||||
#define List_castTo_Array(SELF) Array_construct_size(SELF.data, SELF.size)
|
||||
|
||||
Reference in New Issue
Block a user