-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttlmap.h
83 lines (72 loc) · 3.4 KB
/
ttlmap.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef TTL_MAP_H
#define TTL_MAP_H
#include <pthread.h>
#include "hashmap.h"
#include "timewheel.h"
typedef struct ttlmap {
struct hashmap *hmap;
size_t elsize;
int safe;
pthread_mutex_t hlock;
timewheel_t *tw;
} ttlmap;
ttlmap *ttlmap_new(size_t elsize, size_t cap,
uint64_t seed0, uint64_t seed1,
uint64_t (*hash)(const void *item,
uint64_t seed0, uint64_t seed1),
int (*compare)(const void *a, const void *b,
void *udata),
void (*elfree)(void *item),
void *udata,
timewheel_t *twptr);
struct ttlmap *ttlmap_new_with_allocator(
void *(*malloc)(size_t),
void *(*realloc)(void *, size_t),
void (*free)(void*),
size_t elsize, size_t cap,
uint64_t seed0, uint64_t seed1,
uint64_t (*hash)(const void *item,
uint64_t seed0, uint64_t seed1),
int (*compare)(const void *a, const void *b,
void *udata),
void (*elfree)(void *item),
void *udata,
timewheel_t *twptr);
ttlmap *ttlmap_new_threadunsafe(size_t elsize, size_t cap,
uint64_t seed0, uint64_t seed1,
uint64_t (*hash)(const void *item,
uint64_t seed0, uint64_t seed1),
int (*compare)(const void *a, const void *b,
void *udata),
void (*elfree)(void *item),
void *udata,
timewheel_t *twptr);
struct ttlmap *ttlmap_new_with_allocator_threadunsafe(
void *(*malloc)(size_t),
void *(*realloc)(void *, size_t),
void (*free)(void*),
size_t elsize, size_t cap,
uint64_t seed0, uint64_t seed1,
uint64_t (*hash)(const void *item,
uint64_t seed0, uint64_t seed1),
int (*compare)(const void *a, const void *b,
void *udata),
void (*elfree)(void *item),
void *udata,
timewheel_t *twptr);
void ttlmap_free(ttlmap *map);
void ttlmap_clear(ttlmap *map, bool update_cap);
size_t ttlmap_count(ttlmap *map);
bool ttlmap_oom(ttlmap *map);
void *ttlmap_get(ttlmap *map, const void *item);
void *ttlmap_set(ttlmap *map, const void *item, int ttl_ms);
void *ttlmap_delete(ttlmap *map, void *item);
void *ttlmap_probe(ttlmap *map, uint64_t position);
bool ttlmap_scan(ttlmap *map,
bool (*iter)(const void *item, void *udata), void *udata);
bool ttlmap_iter(ttlmap *map, size_t *i, void **item);
uint64_t ttlmap_sip(const void *data, size_t len,
uint64_t seed0, uint64_t seed1);
uint64_t ttlmap_murmur(const void *data, size_t len,
uint64_t seed0, uint64_t seed1);
#endif