Compare commits
1 Commits
b141b10f70
...
e1b317d9a7
| Author | SHA1 | Date | |
|---|---|---|---|
| e1b317d9a7 |
@ -1,16 +1,10 @@
|
|||||||
#ifndef _acl_array_h
|
#ifndef _acl_array_h
|
||||||
#define _acl_array_h
|
#define _acl_array_h
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#define acl_arraylist_len_d size_t acl_arraylist_len(void *arraylist)
|
size_t acl_arraylist_len(void *arraylist);
|
||||||
acl_arraylist_len_d;
|
void acl_arraylist_free(void *arraylist);
|
||||||
#define acl_arraylist_free_d void acl_arraylist_free(void *arraylist)
|
void* acl_arraylist_remove(void *arraylist_void, size_t index);
|
||||||
acl_arraylist_free_d;
|
void* acl_arraylist_create(size_t array_size, size_t sizeof_one_element);
|
||||||
#define acl_arraylist_remove_d void* acl_arraylist_remove(void *arraylist_void, size_t index)
|
void* acl_arraylist_append(void *arraylist_void, void *element_void);
|
||||||
acl_arraylist_remove_d;
|
void* acl_arraylist_append_ptr(void *arraylist_void, void **append_element);
|
||||||
#define acl_arraylist_create_d void* acl_arraylist_create(size_t array_size, size_t sizeof_one_element)
|
|
||||||
acl_arraylist_create_d;
|
|
||||||
#define acl_arraylist_append_d void* acl_arraylist_append(void *arraylist_void, void *element)
|
|
||||||
acl_arraylist_append_d;
|
|
||||||
#define acl_arraylist_append_ptr_d void* acl_arraylist_append_ptr(void *arraylist_void, void **append_element)
|
|
||||||
acl_arraylist_append_ptr_d;
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
#ifndef _acl_file_h
|
#ifndef _acl_file_h
|
||||||
#define _acl_file_h
|
#define _acl_file_h
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#define acl_ReadTextFile_d char* acl_ReadTextFile(const char *filePath, bool *sucess)
|
char* acl_ReadTextFile(const char *filePath, bool *sucess);
|
||||||
acl_ReadTextFile_d;
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -10,8 +10,6 @@ union acl_hashmap_meta {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
/* set keySize to NULL for a dynamic keySize */
|
/* set keySize to NULL for a dynamic keySize */
|
||||||
#define acl_hashmap_create_d union acl_hashmap_meta* acl_hashmap_create(size_t bucketCount, size_t sizeOneElement, size_t keySize)
|
union acl_hashmap_meta* acl_hashmap_create(size_t bucketCount, size_t sizeOneElement, size_t keySize);
|
||||||
acl_hashmap_create_d;
|
void acl_hashmap_put(union acl_hashmap_meta *hashmap_meta, void *key, void *element);
|
||||||
#define acl_hashmap_put_d void acl_hashmap_put(union acl_hashmap_meta *hashmap_meta, void *key, void *element)
|
|
||||||
acl_hashmap_put_d;
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
19
src/array.c
19
src/array.c
@ -17,7 +17,7 @@ union arraylist_meta {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
acl_arraylist_create_d {
|
void* acl_arraylist_create(size_t array_size, size_t sizeof_one_element) {
|
||||||
union arraylist_meta *arraylist_new = malloc(array_size * sizeof_one_element + sizeof*arraylist_new);
|
union arraylist_meta *arraylist_new = malloc(array_size * sizeof_one_element + sizeof*arraylist_new);
|
||||||
if(arraylist_new == NULL) return NULL;
|
if(arraylist_new == NULL) return NULL;
|
||||||
arraylist_new->len = array_size;
|
arraylist_new->len = array_size;
|
||||||
@ -26,16 +26,15 @@ acl_arraylist_create_d {
|
|||||||
return arraylist_new+1;
|
return arraylist_new+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
acl_arraylist_append_d {
|
void* acl_arraylist_append(void *arraylist_void, void *element) {
|
||||||
void *append_pointer;
|
void *element_append;
|
||||||
void **element_append = &append_pointer;
|
union arraylist_meta *arraylist = acl_arraylist_append_ptr(arraylist_void, &element_append);
|
||||||
union arraylist_meta *arraylist = acl_arraylist_append_ptr(arraylist_void, element_append);
|
|
||||||
if(arraylist == NULL) return NULL;
|
if(arraylist == NULL) return NULL;
|
||||||
--arraylist;
|
--arraylist;
|
||||||
memcpy(*element_append, element, arraylist->sizeof_one_element);
|
memcpy(element_append, element, arraylist->sizeof_one_element);
|
||||||
return arraylist + 1;
|
return arraylist + 1;
|
||||||
}
|
}
|
||||||
acl_arraylist_append_ptr_d {
|
void* acl_arraylist_append_ptr(void *arraylist_void, void **append_element) {
|
||||||
union arraylist_meta *arraylist = arraylist_void;
|
union arraylist_meta *arraylist = arraylist_void;
|
||||||
--arraylist;
|
--arraylist;
|
||||||
if(arraylist->len == arraylist->cap) {
|
if(arraylist->len == arraylist->cap) {
|
||||||
@ -49,11 +48,11 @@ acl_arraylist_append_ptr_d {
|
|||||||
return arraylist + 1;
|
return arraylist + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
acl_arraylist_free_d {
|
void acl_arraylist_free(void *arraylist) {
|
||||||
free((union arraylist_meta*)arraylist-1);
|
free((union arraylist_meta*)arraylist-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
acl_arraylist_remove_d {
|
void* acl_arraylist_remove(void *arraylist_void, size_t index) {
|
||||||
union arraylist_meta *arraylist = (union arraylist_meta*)arraylist_void - 1;
|
union arraylist_meta *arraylist = (union arraylist_meta*)arraylist_void - 1;
|
||||||
char *arraylist_char = arraylist_void;
|
char *arraylist_char = arraylist_void;
|
||||||
if(index != arraylist->len - 1) {
|
if(index != arraylist->len - 1) {
|
||||||
@ -67,6 +66,6 @@ acl_arraylist_remove_d {
|
|||||||
return arraylist;
|
return arraylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
acl_arraylist_len_d {
|
size_t acl_arraylist_len(void *arraylist) {
|
||||||
return ((union arraylist_meta*)arraylist - 1)->len;
|
return ((union arraylist_meta*)arraylist - 1)->len;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <acl/file.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
acl_ReadTextFile_d {
|
char* acl_ReadTextFile(const char *filePath, bool *sucess){
|
||||||
FILE *fp = fopen(filePath, "rb");
|
FILE *fp = fopen(filePath, "rb");
|
||||||
size_t lSize;
|
size_t lSize;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
|||||||
@ -53,25 +53,21 @@ size_t acl_hash(void *data, size_t dataSize, size_t bucketBits) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
acl_hashmap_create_d {
|
union acl_hashmap_meta* acl_hashmap_create(size_t bucketCount, size_t sizeOneElement, size_t keySize) {
|
||||||
union acl_hashmap_meta *hashmap_meta = malloc(sizeof *hashmap_meta + bucketCount * sizeof(void*));
|
union acl_hashmap_meta *hashmap_meta = malloc(sizeof *hashmap_meta + bucketCount * sizeof(void*));
|
||||||
hashmap_meta->bucketCount = bucketCount;
|
hashmap_meta->bucketCount = bucketCount;
|
||||||
hashmap_meta->sizeOneElement = sizeOneElement;
|
hashmap_meta->sizeOneElement = sizeOneElement;
|
||||||
hashmap_meta->keyBits = log2(keySize);
|
hashmap_meta->keyBits = log2(keySize);
|
||||||
void **hashmap_buckets = (void**)(hashmap_meta + 1);
|
void **hashmap_buckets = (void**)(hashmap_meta + 1);
|
||||||
for(size_t i = 0; i < bucketCount; ++i) {
|
for(size_t i; i < bucketCount; ++i) {
|
||||||
hashmap_buckets[i] = acl_arraylist_create(0, sizeOneElement + sizeof(size_t));
|
hashmap_buckets[i] = acl_arraylist_create(0, sizeOneElement);
|
||||||
if(hashmap_buckets[i] == NULL) {
|
|
||||||
for(size_t j = 0; j < i; ++j) {
|
|
||||||
acl_arraylist_free(hashmap_buckets[j]);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return hashmap_meta;
|
return hashmap_meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
acl_hashmap_put_d {
|
void acl_hashmap_put(union acl_hashmap_meta *hashmap_meta, void *key, void *element) {
|
||||||
void **hashmap_buckets = (void**)(hashmap_meta + 1);
|
void **hashmap_buckets = (void**)(hashmap_meta + 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
int main() {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user