104 lines
2.4 KiB
C
104 lines
2.4 KiB
C
#ifndef COLLECTIONS_H
|
|
#define COLLECTIONS_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
void *array_push(void **data,
|
|
size_t *capacity,
|
|
size_t *count,
|
|
void const *elem,
|
|
size_t elem_size);
|
|
|
|
void *array_insert_at(void **data,
|
|
size_t *capacity,
|
|
size_t *count,
|
|
size_t idx,
|
|
void const *elem,
|
|
size_t elem_size);
|
|
|
|
struct smallarray {
|
|
union {
|
|
size_t smalldata[3];
|
|
struct {
|
|
void **data;
|
|
size_t capacity;
|
|
size_t count;
|
|
};
|
|
};
|
|
};
|
|
|
|
void smallarray_construct(struct smallarray *a);
|
|
void smallarray_destroy(struct smallarray *a);
|
|
void smallarray_push(struct smallarray *a, void *value);
|
|
size_t smallarray_count(struct smallarray const *a);
|
|
void *smallarray_get(struct smallarray *a, size_t idx);
|
|
void const *smallarray_get_const(struct smallarray const *a, size_t idx);
|
|
|
|
struct hash_entry {
|
|
uint64_t hash;
|
|
void *value;
|
|
};
|
|
|
|
#define bucket_capacity 16
|
|
|
|
struct hash_bucket {
|
|
struct hash_entry entries[bucket_capacity];
|
|
size_t count;
|
|
uint64_t first_hash;
|
|
uint64_t last_hash;
|
|
};
|
|
|
|
struct hash_key_entry {
|
|
uint64_t hash;
|
|
char *value;
|
|
};
|
|
|
|
struct hashmap {
|
|
struct hash_bucket *buckets;
|
|
size_t buckets_capacity;
|
|
size_t buckets_count;
|
|
struct hash_key_entry *keys;
|
|
size_t keys_capacity;
|
|
size_t keys_count;
|
|
};
|
|
|
|
void hashmap_construct(struct hashmap *m);
|
|
void hashmap_destroy(struct hashmap *m);
|
|
void hashmap_set(struct hashmap *m, char const *key, void *value);
|
|
void hashmap_set_sized(
|
|
struct hashmap *m, char const *key, size_t key_size, void *value);
|
|
bool hashmap_has(struct hashmap *m, char const *key);
|
|
void *hashmap_get(struct hashmap *m, char const *key);
|
|
void *hashmap_get_sized(struct hashmap *m, char const *key, size_t key_size);
|
|
void *hashmap_get_hash(struct hashmap *m, size_t hash);
|
|
void const *hashmap_get_hash_const(struct hashmap const *m, size_t hash);
|
|
void hashmap_keys(
|
|
struct hashmap const *m, struct hash_key_entry const **keys, size_t *count);
|
|
|
|
#define blockalloc_default_block 4096
|
|
|
|
struct blockalloc_block;
|
|
|
|
struct blockalloc {
|
|
struct blockalloc_block *blocks;
|
|
size_t capacity;
|
|
size_t count;
|
|
size_t p;
|
|
};
|
|
|
|
void blockalloc_construct(struct blockalloc *a);
|
|
void blockalloc_destroy(struct blockalloc *a);
|
|
void *blockalloc_alloc(struct blockalloc *a, size_t size, size_t align);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|