-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhashmap.h
More file actions
37 lines (30 loc) · 839 Bytes
/
hashmap.h
File metadata and controls
37 lines (30 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* hashmap.h -- generic hash table
*
* Copyright (c) 2010, Janne Kulmala <janne.t.kulmala@tut.fi>.
* All rights reserved.
*
* See LICENSE.hashmap for the license.
*
*/
#ifndef _HASHMAP_H_
#define _HASHMAP_H_
#include <string.h>
struct hash_node {
size_t hash;
struct hash_node *next;
};
typedef size_t (*hash_func_t)(void *key);
typedef int (*cmp_func_t)(struct hash_node *node, void *key);
struct hashmap {
struct hash_node **table;
size_t len, count;
hash_func_t hash;
cmp_func_t cmp;
};
void hashmap_init(struct hashmap *map, hash_func_t hash, cmp_func_t cmp);
void hashmap_free(struct hashmap *map);
struct hash_node *hashmap_get(struct hashmap *map, void *key);
int hashmap_insert(struct hashmap *map, struct hash_node *node, void *key);
struct hash_node *hashmap_remove(struct hashmap *map, void *key);
#endif