diff --git a/Makefile b/Makefile index ccbfd23..56065df 100644 --- a/Makefile +++ b/Makefile @@ -45,10 +45,8 @@ hdrs += include/jobq.h hdrs += include/linklist.h srcs += bytes.c -srcs += hmap.c srcs += haggis.c srcs += jobq.c -srcs += linklist.c srcs += linkmap.c objs = $(srcs:.c=.o) diff --git a/haggis.c b/haggis.c index 401ffbf..a4b8c15 100644 --- a/haggis.c +++ b/haggis.c @@ -57,7 +57,6 @@ #include "bytes.h" #include "haggis.h" -#include "linklist.h" static unsigned char header[7] = {0x89, 'h', 'a', 'g', 'g', 'i', 's'}; @@ -520,7 +519,7 @@ void haggis_node_deinit(haggis_node *node) { free(node); } -haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_hardlink_list *list) { +haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_linkmap *map) { struct stat *st = NULL; u16 mode; char *target; @@ -558,7 +557,7 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_hardlink_ switch (node->filetype.tag) { case normal: if (st->st_nlink > 1) { - target = haggis_linklist_get_or_put(list, st->st_ino, file); + target = haggis_linkmap_get_or_add(map, st->st_ino, file); if (target != NULL) { node->filetype.tag = hardlink; haggis_filename_init(target, &node->filetype.f_type.target); @@ -573,7 +572,7 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_hardlink_ break; case block: if (st->st_nlink > 1) { - target = haggis_linklist_get_or_put(list, st->st_ino, file); + target = haggis_linkmap_get_or_add(map, st->st_ino, file); if (target != NULL) { node->filetype.tag = hardlink; haggis_filename_init(target, &node->filetype.f_type.target); @@ -584,7 +583,7 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_hardlink_ break; case character: if (st->st_nlink > 1) { - target = haggis_linklist_get_or_put(list, st->st_ino, file); + target = haggis_linkmap_get_or_add(map, st->st_ino, file); if (target != NULL) { node->filetype.tag = hardlink; haggis_filename_init(target, &node->filetype.f_type.target); @@ -595,7 +594,7 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_hardlink_ break; case fifo: if (st->st_nlink > 1) { - target = haggis_linklist_get_or_put(list, st->st_ino, file); + target = haggis_linkmap_get_or_add(map, st->st_ino, file); if (target != NULL) { node->filetype.tag = hardlink; haggis_filename_init(target, &node->filetype.f_type.target); diff --git a/hmap.c b/hmap.c deleted file mode 100644 index 7653315..0000000 --- a/hmap.c +++ /dev/null @@ -1,241 +0,0 @@ -/* _,.---._ .-._ .--.-. ,--.--------. - * _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\ - * /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./ - * |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \ - * |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \ - * |==|,| | -|==| , '=' |==| - _ | |==|- | - * |==| '=' /\==\ - ,_ /|==| /\ , | |==|, | - * |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/ - * `-.`.____.' `--`--'' `--`./ `--` `--`--` - * _ __ ,---. .-._ .=-.-. _,.----. - * .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \ - * /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-' - * |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | . - * |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \ - * |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , | - * |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. / - * /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-' - * `--`---' `--` `--`./ `--``--`-` - * - * @(#)Copyright (c) 2023, Nathan D. Fisher. - * - * This is free software. It comes with NO WARRANTY. - * Permission to use, modify and distribute this source code - * is granted subject to the following conditions. - * 1/ that the above copyright notice and this notice - * are preserved in all copies and that due credit be given - * to the author. - * 2/ that any changes to this code are clearly commented - * as such so that the author does not get blamed for bugs - * other than his own. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "haggis.h" -#include "haggis_private.h" - -#define FNV64_OFFSET_BASIS 14695981039346656037u -#define FNV64_PRIME 1099511628211u - -uint64_t hash_fnv1a_64(uint8_t *key, size_t len) { - int i; - uint64_t hash = FNV64_OFFSET_BASIS; - - for (i = 0; i < len; i++) { - hash = hash ^ *key; - hash = hash * FNV64_PRIME; - key++; - } - return hash; -} - -uint64_t hash_str_fnv1a_64(char * s) { - uint64_t hash = FNV64_OFFSET_BASIS; - - while (*s != '\0') { - hash = hash ^ *s; - hash = hash * FNV64_PRIME; - s++; - } - return hash; -} - -hmap_node* hmap_node_init(void *key, size_t keysize, void *data) { - hmap_node *node; - uint64_t hash; - - hash = hash_fnv1a_64(key, keysize); - node = calloc(1, sizeof(hmap_node)); - if (node == NULL) return NULL; - node->key = key; - node->hash = hash; - node->data = data; - return node; -} - -void hmap_node_deinit(hmap_node *node) { - hmap_node *current = node; - while (current != NULL) { - current = node->next; - free(node); - node = current; - } -} - -void* hmap_node_attach(hmap_node *root, hmap_node *leaf, size_t keysize) { - void *ret = NULL; - - while (1) { - if (memcmp(root->key, leaf->key, keysize) == 0) { - ret = root->data; - root->data = leaf->data; - return ret; - } else if (root->next == NULL) { - root->next = leaf; - break; - } else { - root = root->next; - } - } - return NULL; - // todo -} - -void* hmap_node_search(hmap_node *root, void *key, size_t keysize) { - void *ret = NULL; - - while (1) { - if (memcmp(root->key, key, keysize) == 0) { - ret = root->data; - return ret; - } else if (root->next == NULL) { - return NULL; - } else { - root = root->next; - } - } -} - -hmap* hmap_init(size_t keysize) { - hmap* map; - - map = calloc(1, sizeof(hmap)); - if (map == NULL) return NULL; - map->len = 0; - map->capacity = 64; - map->keysize = keysize; - map->buckets = calloc(64, sizeof(hmap_node)); - if (map->buckets == NULL) { - free(map); - return NULL; - } - return map; -} - -void hmap_deinit(hmap *map) { - int i; - - for (i = 0; i < map->capacity; i++) { - if (map->buckets[i].next != NULL) { - hmap_node_deinit(map->buckets[i].next); - } - } - free(map->buckets); - free(map); -} - -int hmap_expand(hmap *map) { - hmap_node *old; - hmap_node *new; - hmap_node *current; - int i; - - new = calloc(map->capacity + 64, sizeof(hmap_node)); - if (new == NULL) return 1; - old = map->buckets; - map->buckets = new; - for (i = 0; i < map->capacity; i++) { - current = &old[i]; - while (current->key != NULL) { - hmap_insert(map, current->key, current->data); - current = current->next; - } - } - free(old); - return 0; -} - -void* hmap_insert(hmap *map, void *key, void *data) { - hmap_node *node; - size_t idx; - void *ret = NULL; - - if (map->len >= map->capacity / 2) { - if (hmap_expand(map)) return NULL; - } - node = hmap_node_init(key, map->keysize, data); - if (node == NULL) return NULL; - idx = node->hash % map->capacity; - if (map->buckets[idx].key == NULL) { - map->buckets[idx] = *node; - } else { - ret = hmap_node_attach(&map->buckets[idx], node, map->keysize); - } - if (ret == NULL) { - map->len++; - return NULL; - } else - return ret; -} - -void* hmap_get(hmap *map, void *key) { - uint64_t hash; - size_t idx; - void *ret; - - hash = hash_fnv1a_64(key, map->keysize); - idx = hash % map->capacity; - ret = hmap_node_search(&map->buckets[idx], key, map->keysize); - return ret; -} - -void* hmap_remove(hmap *map, void *key) { - uint64_t hash; - size_t idx; - void *ret = NULL; - hmap_node *previous = NULL; - hmap_node *current; - - hash = hash_fnv1a_64(key, map->keysize); - idx = hash % map->capacity; - current = &map->buckets[idx]; - if (current->key == NULL) return NULL; - if (memcmp(current->key, key, map->keysize) == 0) { - map->buckets[idx] = *current->next; - } - while (current->key != NULL) { - if (memcmp(current->key, key, map->keysize) == 0) { - ret = current->data; - map->len--; - if (previous != NULL) { - previous->next = current->next; - } else { - map->buckets[idx] = *current->next; - } - free(current); - break; - } else { - current = current->next; - previous = current; - } - } - - return ret; -} diff --git a/include/haggis.h b/include/haggis.h index 761da60..cd76d79 100644 --- a/include/haggis.h +++ b/include/haggis.h @@ -33,9 +33,10 @@ #ifndef HAGGIS_H #define HAGGIS_H 1 -#include "linklist.h" +#include // pthread_mutex_t #include // uint_t #include // FILE +#include // ino_t typedef uint8_t u8; @@ -115,8 +116,30 @@ typedef struct { haggis_filetype filetype; } haggis_node; +#define HAGGIS_BUCKETS_BASE 64 + +typedef struct __bucket { + union { + ino_t val; + uint8_t bytes[sizeof(ino_t)]; + } key; + uint64_t hash; + char * path; + struct __bucket * next; +} haggis_bucket; + +typedef struct { + pthread_mutex_t mutex; + size_t len; + size_t capacity; + haggis_bucket *buckets; +} haggis_linkmap; + +haggis_linkmap* haggis_linkmap_init(); +void haggis_linkmap_deinit(haggis_linkmap *map); +char* haggis_linkmap_get_or_add(haggis_linkmap *map, ino_t inode, char *path); void haggis_node_deinit(haggis_node *node); -haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_hardlink_list *list); +haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_linkmap *map); int haggis_extract_node(FILE *stram, haggis_node *node); int haggis_load_node(FILE *stream, haggis_node *node); int haggis_store_node(FILE *stream, haggis_node *node); diff --git a/include/linklist.h b/include/linklist.h deleted file mode 100644 index 86506b0..0000000 --- a/include/linklist.h +++ /dev/null @@ -1,57 +0,0 @@ -/* _,.---._ .-._ .--.-. ,--.--------. - * _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\ - * /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./ - * |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \ - * |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \ - * |==|,| | -|==| , '=' |==| - _ | |==|- | - * |==| '=' /\==\ - ,_ /|==| /\ , | |==|, | - * |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/ - * `-.`.____.' `--`--'' `--`./ `--` `--`--` - * _ __ ,---. .-._ .=-.-. _,.----. - * .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \ - * /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-' - * |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | . - * |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \ - * |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , | - * |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. / - * /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-' - * `--`---' `--` `--`./ `--``--`-` - * - * @(#)Copyright (c) 2023, Nathan D. Fisher. - * - * This is free software. It comes with NO WARRANTY. - * Permission to use, modify and distribute this source code - * is granted subject to the following conditions. - * 1/ that the above copyright notice and this notice - * are preserved in all copies and that due credit be given - * to the author. - * 2/ that any changes to this code are clearly commented - * as such so that the author does not get blamed for bugs - * other than his own. - */ - -#ifndef HAGGIS_LINKLIST -#define HAGGIS_LINKLIST - -#include // ino_t -#include // pthread_mutex_t - -struct _haggis_hardlink { - struct _haggis_hardlink *next; - ino_t inode; - char *fname; -}; - -typedef struct _haggis_hardlink haggis_hardlink; - -typedef struct { - pthread_mutex_t *mutex; - haggis_hardlink *head; -} haggis_hardlink_list; - -int haggis_linklist_push(haggis_hardlink_list *list, haggis_hardlink *link); -haggis_hardlink* haggis_linklist_get(haggis_hardlink_list *list, ino_t inode); -char* haggis_linklist_get_or_put(haggis_hardlink_list *list, ino_t inode, char *fname); -void haggis_linklist_drain(haggis_hardlink_list *list); - -#endif // !HAGGIS_LINKLIST diff --git a/include/linkmap.h b/include/linkmap.h deleted file mode 100644 index 73ba10c..0000000 --- a/include/linkmap.h +++ /dev/null @@ -1,62 +0,0 @@ -/* _,.---._ .-._ .--.-. ,--.--------. - * _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\ - * /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./ - * |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \ - * |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \ - * |==|,| | -|==| , '=' |==| - _ | |==|- | - * |==| '=' /\==\ - ,_ /|==| /\ , | |==|, | - * |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/ - * `-.`.____.' `--`--'' `--`./ `--` `--`--` - * _ __ ,---. .-._ .=-.-. _,.----. - * .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \ - * /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-' - * |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | . - * |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \ - * |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , | - * |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. / - * /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-' - * `--`---' `--` `--`./ `--``--`-` - * - * @(#)Copyright (c) 2023, Nathan D. Fisher. - * - * This is free software. It comes with NO WARRANTY. - * Permission to use, modify and distribute this source code - * is granted subject to the following conditions. - * 1/ that the above copyright notice and this notice - * are preserved in all copies and that due credit be given - * to the author. - * 2/ that any changes to this code are clearly commented - * as such so that the author does not get blamed for bugs - * other than his own. - */ - -#ifndef HAGGIS_LINKMAP -#define HAGGIS_LINKMAP 1 - -#include "haggis.h" -#include -#include -#include -#include -#include - -#define HAGGIS_BUCKETS_BASE 64 - -typedef struct __bucket { - union { - ino_t val; - u8 bytes[sizeof(ino_t)]; - } key; - uint64_t hash; - char * path; - struct __bucket * next; -} haggis_bucket; - -typedef struct { - pthread_mutex_t mutex; - size_t len; - size_t capacity; - haggis_bucket *buckets; -} haggis_linkmap; - -#endif // !HAGGIS_LINKMAP diff --git a/linklist.c b/linklist.c deleted file mode 100644 index 5ba2aba..0000000 --- a/linklist.c +++ /dev/null @@ -1,88 +0,0 @@ -/* _,.---._ .-._ .--.-. ,--.--------. - * _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\ - * /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./ - * |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \ - * |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \ - * |==|,| | -|==| , '=' |==| - _ | |==|- | - * |==| '=' /\==\ - ,_ /|==| /\ , | |==|, | - * |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/ - * `-.`.____.' `--`--'' `--`./ `--` `--`--` - * _ __ ,---. .-._ .=-.-. _,.----. - * .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \ - * /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-' - * |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | . - * |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \ - * |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , | - * |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. / - * /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-' - * `--`---' `--` `--`./ `--``--`-` - * - * @(#)Copyright (c) 2023, Nathan D. Fisher. - * - * This is free software. It comes with NO WARRANTY. - * Permission to use, modify and distribute this source code - * is granted subject to the following conditions. - * 1/ that the above copyright notice and this notice - * are preserved in all copies and that due credit be given - * to the author. - * 2/ that any changes to this code are clearly commented - * as such so that the author does not get blamed for bugs - * other than his own. - */ - -#include "linklist.h" -#include -#include -#include - -int haggis_linklist_push(haggis_hardlink_list *list, haggis_hardlink *link) { - pthread_mutex_lock(list->mutex); - link->next = list->head; - list->head = link; - return pthread_mutex_unlock(list->mutex); -} - -haggis_hardlink* haggis_linklist_get(haggis_hardlink_list *list, ino_t inode) { - haggis_hardlink *link; - - pthread_mutex_lock(list->mutex); - link = list->head; - while(link != NULL) { - if (link->inode == inode) { - return link; - } - link = link->next; - } - pthread_mutex_unlock(list->mutex); - return NULL; -} - -char* haggis_linklist_get_or_put(haggis_hardlink_list *list, ino_t inode, char *fname) { - haggis_hardlink *link; - - link = haggis_linklist_get(list, inode); - if (link == NULL) { - link = malloc(sizeof(haggis_hardlink)); - if (link == NULL) return NULL; - link->inode = inode; - link->next = NULL; - haggis_linklist_push(list, link); - } else { - return link->fname; - } - return NULL; -} - -void haggis_linklist_drain(haggis_hardlink_list *list) { - haggis_hardlink *link; - haggis_hardlink *next; - - pthread_mutex_lock(list->mutex); - link = list->head; - while (link != NULL) { - next = link->next; - free(link); - link = next; - } - pthread_mutex_unlock(list->mutex); -} diff --git a/linkmap.c b/linkmap.c index 33ae60d..54ad321 100644 --- a/linkmap.c +++ b/linkmap.c @@ -30,16 +30,37 @@ * other than his own. */ -#include "linkmap.h" #include "haggis_private.h" -#include -#include -#include -#include -#include -#include -#include -#include + +#include // PATH_MAX +#include // calloc, free +#include // strndup + +#define FNV64_OFFSET_BASIS 14695981039346656037u +#define FNV64_PRIME 1099511628211u + +uint64_t hash_fnv1a_64(uint8_t *key, size_t len) { + int i; + uint64_t hash = FNV64_OFFSET_BASIS; + + for (i = 0; i < len; i++) { + hash = hash ^ *key; + hash = hash * FNV64_PRIME; + key++; + } + return hash; +} + +uint64_t hash_str_fnv1a_64(char * s) { + uint64_t hash = FNV64_OFFSET_BASIS; + + while (*s != '\0') { + hash = hash ^ *s; + hash = hash * FNV64_PRIME; + s++; + } + return hash; +} haggis_bucket* haggis_bucket_init(ino_t inode, uint64_t hash, char * path) { haggis_bucket *bucket; @@ -88,6 +109,18 @@ haggis_linkmap* haggis_linkmap_init() { return map; } +void haggis_linkmap_deinit(haggis_linkmap *map) { + int i; + + for (i = 0; i < map->capacity; i++) { + if (map->buckets[i].next == NULL) { + haggis_bucket_deinit(map->buckets[i].next); + } + } + free(map->buckets); + free(map); +} + int haggis_linkmap_expand(haggis_linkmap *map) { haggis_bucket *buckets_new; haggis_bucket *buckets_old; @@ -128,17 +161,16 @@ char* haggis_linkmap_get_or_add(haggis_linkmap *map, ino_t inode, char * path) { idx = map->capacity % hash; if (map->buckets[idx].key.val == inode) { target = strndup(target, PATH_MAX - 1); - pthread_mutex_unlock(&map->mutex); } else if (map->buckets[idx].key.val == 0) { map->buckets[idx].key.val = inode; map->buckets[idx].hash = hash; map->buckets[idx].path = path; map->len++; - pthread_mutex_unlock(&map->mutex); } else { b = haggis_bucket_init(key.val, hash, path); if (b == NULL) return NULL; target = haggis_bucket_search_append(&map->buckets[idx], b); } + pthread_mutex_unlock(&map->mutex); return target; } diff --git a/test/Makefile b/test/Makefile index f08cb04..5885f3d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -61,10 +61,6 @@ tests += store_file_sha256 tests += load_file_sha256 tests += fnv1a_hash_inode tests += fnv1a_hash_str -tests += init_hmap -tests += hmap_insert -tests += hmap_get -tests += hmap_replace total != echo $(tests) | wc -w | awk '{ print $$1 }' diff --git a/test/hmap_get.c b/test/hmap_get.c deleted file mode 100644 index ce8f8ea..0000000 --- a/test/hmap_get.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "haggis.h" -#include "haggis_private.h" -#include -#include -#include -#include - -int main() { - hmap *map; - struct stat st; - char *data; - union { - ino_t val; - u8 bytes[sizeof(ino_t)]; - } nod; - char *ret; - - map = hmap_init(sizeof(ino_t)); - assert(map != NULL); - data = "Makefile"; - stat(data, &st); - nod.val = st.st_ino; - hmap_insert(map, &nod.bytes[0], data); - assert(map->len == 1); - ret = hmap_get(map, &nod.bytes[0]); - assert(memcmp(ret, data, 9) == 0); - hmap_deinit(map); - return 0; -} diff --git a/test/hmap_insert.c b/test/hmap_insert.c deleted file mode 100644 index 8a4bc2d..0000000 --- a/test/hmap_insert.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "haggis.h" -#include "haggis_private.h" -#include -#include -#include -#include - -int main() { - hmap *map; - struct stat st; - char *data; - union { - ino_t val; - u8 bytes[sizeof(ino_t)]; - } nod; - - map = hmap_init(sizeof(ino_t)); - assert(map != NULL); - data = "Makefile"; - stat(data, &st); - nod.val = st.st_ino; - hmap_insert(map, &nod.bytes[0], data); - assert(map->len == 1); - hmap_deinit(map); - return 0; -} diff --git a/test/hmap_replace.c b/test/hmap_replace.c deleted file mode 100644 index d9216b8..0000000 --- a/test/hmap_replace.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "haggis.h" -#include "haggis_private.h" -#include -#include -#include -#include -#include - -int main() { - hmap *map; - struct stat st; - char *data; - union { - ino_t val; - u8 bytes[sizeof(ino_t)]; - } nod; - char * ret = NULL; - - map = hmap_init(sizeof(ino_t)); - assert(map != NULL); - data = "Makefile"; - stat(data, &st); - nod.val = st.st_ino; - ret = hmap_insert(map, &nod.bytes[0], data); - assert(ret == NULL); - assert(map->len == 1); - ret = hmap_get(map, &nod.bytes[0]); - assert(memcmp(ret, data, 7) == 0); - ret = hmap_insert(map, &nod.bytes[0], "testdata"); - assert(ret != NULL); - assert(memcmp(ret, data, 8) == 0); - assert(map->len == 1); - ret = hmap_get(map, &nod.bytes[0]); - assert(memcmp(ret, "testdata", 9) == 0); - hmap_deinit(map); - return 0; -} diff --git a/test/init_hmap.c b/test/init_hmap.c deleted file mode 100644 index cbd0219..0000000 --- a/test/init_hmap.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "haggis_private.h" -#include -#include - -int main() { - hmap *map; - - map = hmap_init(sizeof(ino_t)); - assert(map != NULL); - hmap_deinit(map); - return 0; -}