File: hash.h

package info (click to toggle)
libsfdo 0.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 736 kB
  • sloc: ansic: 6,491; python: 111; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 662 bytes parent folder | download | duplicates (2)
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
#ifndef HASH_H
#define HASH_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

struct sfdo_hashmap_entry {
	uint32_t hash;
	const char *key; // Borrowed, NULL if empty
	size_t key_len;
};

struct sfdo_hashmap {
	char *mem;
	size_t len, cap;
	size_t entry_size;
};

void sfdo_hashmap_init(struct sfdo_hashmap *map, size_t entry_size);
void sfdo_hashmap_finish(struct sfdo_hashmap *map);

void sfdo_hashmap_clear(struct sfdo_hashmap *map);

// Returns a complete entry if it was found, entry with key == NULL if it was just added,
// NULL otherwise
void *sfdo_hashmap_get(struct sfdo_hashmap *map, const char *key, size_t key_len, bool add);

#endif