diff options
| author | Albert Cervin <albert@acervin.com> | 2023-04-06 23:23:46 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-05-01 22:19:14 +0200 |
| commit | a123725a12e948d78badb2cb686d38548f1c633b (patch) | |
| tree | c92c46134ef5536fbbf3bf08983c4f0dea1aaf58 /src/hashmap.h | |
| parent | b5ed4cf757afc50afb6ac499eee7b87a2648fa4c (diff) | |
| download | dged-a123725a12e948d78badb2cb686d38548f1c633b.tar.gz dged-a123725a12e948d78badb2cb686d38548f1c633b.tar.xz dged-a123725a12e948d78badb2cb686d38548f1c633b.zip | |
Implement window handling
Also implement searching.
fix undo boundaries
when it checked for other save point, it used && instead of == which
caused it to overwrite other types.
Fix bytes vs chars bug in text_get_region
Diffstat (limited to 'src/hashmap.h')
| -rw-r--r-- | src/hashmap.h | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/hashmap.h b/src/hashmap.h deleted file mode 100644 index 405c193..0000000 --- a/src/hashmap.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef _HASHMAP_H -#define _HASHMAP_H - -#include "vec.h" -#include <stdint.h> - -#define HASHMAP_ENTRY_TYPE(name, entry) \ - struct name { \ - uint32_t key; \ - entry value; \ - } - -#define HASHMAP(entry) \ - struct { \ - VEC(entry) entries; \ - uint32_t (*hash_fn)(const char *); \ - } - -#define HASHMAP_INIT(map, initial_capacity, hasher) \ - VEC_INIT(&(map)->entries, initial_capacity) \ - (map)->hash_fn = hasher; - -#define HASHMAP_DESTROY(map) VEC_DESTROY(&(map)->entries) - -#define HASHMAP_INSERT(map, type, k, v, hash_var) \ - uint32_t key = (map)->hash_fn(k); \ - bool duplicate = false; \ - VEC_FOR_EACH(&(map)->entries, type *pair) { \ - if (pair->key == key) { \ - duplicate = true; \ - break; \ - } \ - } \ - if (!duplicate) { \ - VEC_PUSH(&(map)->entries, ((type){.key = key, .value = v})); \ - } \ - hash_var = key; - -#define HASHMAP_APPEND(map, type, k, var) \ - uint32_t key = (map)->hash_fn(k); \ - bool duplicate = false; \ - VEC_FOR_EACH(&(map)->entries, type *pair) { \ - if (pair->key == key) { \ - duplicate = true; \ - break; \ - } \ - } \ - type *v = NULL; \ - if (!duplicate) { \ - VEC_APPEND(&(map)->entries, v); \ - v->key = key; \ - } \ - var = v; - -#define HASHMAP_GET(map, type, k, var) \ - HASHMAP_GET_BY_HASH(map, type, (map)->hash_fn(k), var) - -#define HASHMAP_GET_BY_HASH(map, type, h, var) \ - type *res = NULL; \ - uint32_t needle = h; \ - VEC_FOR_EACH(&(map)->entries, type *pair) { \ - if (needle == pair->key) { \ - res = pair; \ - break; \ - } \ - } \ - var = res != NULL ? &(res->value) : NULL; - -#define HASHMAP_CONTAINS_KEY(map, key) \ - uint32_t needle = (map)->hash_fn(key); \ - bool exists = false; \ - VEC_FOR_EACH((map)->entries, struct pair *pair) { \ - if (needle == pair->key) { \ - exists = true; \ - break; \ - } \ - } \ - exists - -#define HASHMAP_FOR_EACH(map, var) VEC_FOR_EACH_INDEXED(&(map)->entries, var, i) - -#define HASHMAP_SIZE(map) VEC_SIZE(&(map)->entries) -#define HASHMAP_CAPACITY(map) VEC_CAPACITY(&(map)->entries) -#define HASHMAP_EMPTY(map) HASHMAP_SIZE == 0 - -#endif |
