aboutsummaryrefslogtreecommitdiff
path: root/inc/lib/hashmap.h
blob: db70bdd91e6a51c074f971a3e704bab0848cc40d (plain) (blame)
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
// Copyright 2020 Joshua J Baker. All rights reserved.
// Copyright 2023 Marvin Borner
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

#ifndef SHARING_HASHMAP_H
#define SHARING_HASHMAP_H

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

struct hashmap;

struct hashmap *hashmap_new(size_t elsize, size_t cap,
			    void (*elfree)(void *item));

void hashmap_free(struct hashmap *map);
void hashmap_clear(struct hashmap *map, bool update_cap);
size_t hashmap_count(struct hashmap *map);
bool hashmap_oom(struct hashmap *map);
void *hashmap_probe(struct hashmap *map, uint64_t position);
bool hashmap_scan(struct hashmap *map, bool (*iter)(void *item));
bool hashmap_iter(struct hashmap *map, size_t *i, void **item);

void *hashmap_get(struct hashmap *map, uint64_t hash);
void *hashmap_delete(struct hashmap *map, uint64_t hash);
void *hashmap_set(struct hashmap *map, void *item, uint64_t hash);
void hashmap_set_grow_by_power(struct hashmap *map, size_t power);

#endif