-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib1.h
1132 lines (805 loc) · 25.2 KB
/
lib1.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2016 Wu, Xingbo <[email protected]>
*
* All rights reserved. No warranty, explicit or implicit, provided.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
// includes {{{
// C headers
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <math.h>
// POSIX headers
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
// Linux headers
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
// }}} includes
// types {{{
typedef int_least8_t s8;
typedef int_least16_t s16;
typedef int_least32_t s32;
typedef int_least64_t s64;
typedef uint_least8_t u8;
typedef uint_least16_t u16;
typedef uint_least32_t u32;
typedef uint_least64_t u64;
// }}} types
// locks {{{
typedef struct __spinlock {
union {
pthread_spinlock_t lock;
u64 padding[8];
};
} spinlock;
extern void
spinlock_init(spinlock * const lock);
extern void
spinlock_lock(spinlock * const lock);
extern bool
spinlock_trylock(spinlock * const lock);
extern void
spinlock_unlock(spinlock * const lock);
typedef struct __mutexlock {
union {
pthread_mutex_t lock;
u64 padding[8];
};
} mutexlock;
extern void
mutexlock_init(mutexlock * const lock);
extern void
mutexlock_lock(mutexlock * const lock);
extern bool
mutexlock_trylock(mutexlock * const lock);
extern void
mutexlock_unlock(mutexlock * const lock);
typedef struct __rwlock {
union {
u64 var;
u64 padding[8];
};
} rwlock;
extern void
rwlock_init(rwlock * const lock);
extern bool
rwlock_trylock_read(rwlock * const lock);
extern void
rwlock_lock_read(rwlock * const lock);
extern void
rwlock_unlock_read(rwlock * const lock);
extern bool
rwlock_trylock_write(rwlock * const lock);
extern void
rwlock_lock_write(rwlock * const lock);
extern void
rwlock_unlock_write(rwlock * const lock);
// }}} locks
// timing {{{
extern u64
time_nsec(void);
extern double
time_sec(void);
extern u64
time_diff_nsec(const u64 last);
extern double
time_diff_sec(const double last);
extern u64
timespec_diff(const struct timespec t0, const struct timespec t1);
// }}} timing
// debug {{{
extern void
debug_backtrace(void);
extern void
watch_u64_usr1(u64 * const ptr);
extern void
debug_wait_gdb(void);
#ifndef NDEBUG
extern void
debug_assert(const bool v);
#else
#define debug_assert(expr) ((void)0)
#endif
extern void
debug_dump_maps(FILE * const out);
extern void
debug_perf_start(void);
extern void
debug_perf_switch(void);
extern void
debug_perf_stop(void);
// }}} debug
// bits {{{
extern u32
bits_reverse_u32(const u32 v);
extern u64
bits_reverse_u64(const u64 v);
extern u64
bits_rotl_u64(const u64 v, const u64 n);
extern u64
bits_rotr_u64(const u64 v, const u64 n);
extern u32
bits_rotl_u32(const u32 v, const u64 n);
extern u32
bits_rotr_u32(const u32 v, const u64 n);
// }}} bits
// bitmap {{{
struct bitmap;
extern struct bitmap *
bitmap_create(const u64 bits);
extern bool
bitmap_test(const struct bitmap * const bm, const u64 idx);
extern bool
bitmap_test_all1(struct bitmap * const bm);
extern bool
bitmap_test_all0(struct bitmap * const bm);
extern void
bitmap_set1(struct bitmap * const bm, const u64 idx);
extern void
bitmap_set0(struct bitmap * const bm, const u64 idx);
extern u64
bitmap_count(struct bitmap * const bm);
extern void
bitmap_set_all1(struct bitmap * const bm);
extern void
bitmap_set_all0(struct bitmap * const bm);
extern void
bitmap_static_init(struct bitmap * const bm, const u64 bits);
// }}} bitmap
// bloom filter {{{
struct bloomfilter;
extern struct bloomfilter *
bf_create(const u64 bpk, const u64 capacity);
extern void
bf_mark(struct bloomfilter * const bf, u64 hash64);
extern bool
bf_test(const struct bloomfilter * const bf, u64 hash64);
extern void
bf_destroy(struct bloomfilter * const bf);
// }}} bloom filter
// process/thread {{{
extern u64
process_get_rss(void);
extern u64
process_affinity_core_count(void);
extern u64
process_affinity_core_list(const u64 max, u64 * const cores);
extern u64
process_cpu_time_usec(void);
extern void
thread_set_affinity(const u64 cpu);
extern double
thread_fork_join_private(const u64 nr, void *(*func) (void *), void * const * const argv);
extern double
thread_fork_join(const u64 nr, void *(*func) (void *), void * const arg);
extern int
thread_create_at(const u64 cpu, pthread_t * const thread, void *(*start_routine) (void *), void * const arg);
// }}} process/thread
// mm {{{
extern void *
xalloc(const u64 align, const u64 size);
/* hugepages */
// force posix allocators: -DVALGRIND_MEMCHECK
extern void *
pages_alloc_4kb(const size_t nr_4kb);
extern void *
pages_alloc_2mb(const size_t nr_2mb);
extern void *
pages_alloc_1gb(const size_t nr_1gb);
extern void *
pages_alloc_best(const size_t size, const bool try_1gb, u64 * const size_out);
extern void
pages_unmap(void * const ptr, const size_t size);
// }}} mm
// oalloc {{{
struct oalloc;
extern struct oalloc *
oalloc_create(void);
extern void *
oalloc_alloc(const u64 size, struct oalloc * const oa);
extern void
oalloc_destroy(struct oalloc * const oa);
// }}} oalloc
// gcache {{{
struct gcache;
extern struct gcache *
gcache_create(const u64 nr_classes, const u64 inc);
extern void *
gcache_pull(struct gcache * const g, const u64 size);
extern bool
gcache_push(struct gcache * const g, const u64 size, void * ptr);
extern void
gcache_clean(struct gcache * const g);
extern void
gcache_destroy(struct gcache * const g);
struct gcache_iter;
extern struct gcache_iter *
gcache_iter_create(struct gcache * const g);
extern void *
gcache_iter_next(struct gcache_iter * const gi);
extern void
gcache_iter_destroy(struct gcache_iter * const gi);
// }}} gcache
// cpucache {{{
extern void
cpu_clflush1(void * const ptr);
extern void
cpu_clflush(void * const ptr, const size_t size);
extern void
cpu_mfence(void);
// }}} cpucache
// qsort {{{
extern void
qsort_u16(u16 * const array, const size_t nr);
extern void
qsort_u32(u32 * const array, const size_t nr);
extern void
qsort_u64(u64 * const array, const size_t nr);
extern void
qsort_double(double * const array, const size_t nr);
extern void
qsort_u64_sample(const u64 * const array0, const u64 nr, const u64 res, FILE * const out);
extern void
qsort_double_sample(const double * const array0, const u64 nr, const u64 res, FILE * const out);
// }}} qsort
// hash {{{
extern u32
crc32(const void * const ptr, const size_t size);
extern u32
xxhash32(const void * const ptr, const size_t size);
extern u64
xxhash64(const void * const ptr, const size_t size);
// }}} hash
// xlog {{{
struct xlog {
u64 nr_rec;
u64 nr_cap;
u64 unit_size;
u8 * ptr;
};
extern struct xlog *
xlog_create(const u64 nr_init, const u64 unit_size);
extern void
xlog_append(struct xlog * const xlog, const void * const rec);
extern void
xlog_append_cycle(struct xlog * const xlog, const void * const rec);
extern void
xlog_reset(struct xlog * const xlog);
extern void
xlog_dump(struct xlog * const xlog, FILE * const out);
extern void
xlog_destroy(struct xlog * const xlog);
struct xlog_iter;
extern struct xlog_iter *
xlog_iter_create(const struct xlog * const xlog);
extern bool
xlog_iter_next(struct xlog_iter * const iter, void * const out);
// free iter after use
// }}} ulog/dlog
// string {{{
// size of out should be >= 10
extern void
str10_u32(void * const out, const u32 v);
// size of out should be >= 20
extern void
str10_u64(void * const out, const u64 v);
// size of out should be >= 8
extern void
str16_u32(void * const out, const u32 v);
// size of out should be >= 16
extern void
str16_u64(void * const out, const u64 v);
// user should free returned ptr after use
extern char **
string_tokens(const char * const str, const char * const delim);
// }}} string
// damp {{{
struct damp;
extern struct damp *
damp_create(const u64 cap, const double dshort, const double dlong);
extern double
damp_average(const struct damp * const d);
extern double
damp_min(const struct damp * const d);
extern double
damp_max(const struct damp * const d);
extern bool
damp_add_test(struct damp * const d, const double v);
extern void
damp_clean(struct damp * const d);
extern void
damp_destroy(struct damp * const d);
// }}} damp
// vctr {{{
struct vctr;
extern struct vctr *
vctr_create(const u64 nr);
extern u64
vctr_size(struct vctr * const v);
extern void
vctr_add(struct vctr * const v, const u64 i, const u64 n);
extern void
vctr_add1(struct vctr * const v, const u64 i);
extern void
vctr_add_atomic(struct vctr * const v, const u64 i, const u64 n);
extern void
vctr_add1_atomic(struct vctr * const v, const u64 i);
extern void
vctr_set(struct vctr * const v, const u64 i, const u64 n);
extern u64
vctr_get(struct vctr * const v, const u64 i);
extern void
vctr_merge(struct vctr * const to, const struct vctr * const from);
extern void
vctr_reset(struct vctr * const v);
extern void
vctr_destroy(struct vctr * const v);
// }}} vctr
// rgen {{{
extern u64
xorshift(const u64 x);
extern u64
random_u64(void);
extern u64
srandom_u64(const u64 seed);
extern double
random_double(void);
struct rgen;
typedef u64 (*rgen_next_func)(struct rgen * const);
extern struct rgen * rgen_new_exponential(const double percentile, const double range);
extern struct rgen * rgen_new_constant(const u64 constant);
extern struct rgen * rgen_new_counter(const u64 min, const u64 max);
extern struct rgen * rgen_new_counter_unsafe(const u64 min, const u64 max);
extern struct rgen * rgen_new_skipinc(const u64 min, const u64 max, const u64 inc);
extern struct rgen * rgen_new_skipinc_unsafe(const u64 min, const u64 max, const u64 inc);
extern struct rgen * rgen_new_reducer(const u64 min, const u64 max);
extern struct rgen * rgen_new_reducer_unsafe(const u64 min, const u64 max);
extern struct rgen * rgen_new_zipfian(const u64 min, const u64 max);
extern struct rgen * rgen_new_xzipfian(const u64 min, const u64 max);
extern struct rgen * rgen_new_unizipf(const u64 min, const u64 max, const u64 ufactor);
extern struct rgen * rgen_new_uniform(const u64 min, const u64 max);
extern struct rgen * rgen_new_trace32(const char * const filename);
extern u64
rgen_next_wait(struct rgen * const gen);
extern u64
rgen_next_nowait(struct rgen * const gen);
extern void
rgen_destroy(struct rgen * const gen);
extern void
rgen_helper_message(void);
extern int
rgen_helper(const int argc, char ** const argv, struct rgen ** const gen_out);
extern struct rgen *
rgen_dup(struct rgen * const gen0);
extern bool
rgen_async_convert(struct rgen * const gen0, const u64 cpu);
extern void
rgen_async_wait(struct rgen * const gen);
extern void
rgen_async_wait_all(struct rgen * const gen);
// }}} rgen
// rcu {{{
struct rcu_node;
extern struct rcu_node *
rcu_node_create(void);
extern void
rcu_node_init(struct rcu_node * const node);
extern struct rcu_node *
rcu_node_create(void);
extern void *
rcu_read_ref(struct rcu_node * const node);
extern void
rcu_read_unref(struct rcu_node * const node, void * ptr);
extern void
rcu_update(struct rcu_node * const node, void * ptr);
// }}} rcu
// server {{{
struct stream2 {
FILE * w;
FILE * r;
};
struct server;
struct server_wi;
extern struct server *
server_create(const char * const host, const int port, void*(*worker)(void * const), void * const priv);
extern void
server_wait(struct server * const server);
extern void
server_destroy(struct server * const server);
extern struct stream2 *
server_wi_stream2(struct server_wi * const wi);
extern void *
server_wi_private(struct server_wi * const wi);
extern void
server_wi_destroy(struct server_wi * const wi);
extern struct stream2 *
stream2_create(const char * const host, const int port);
extern void
stream2_destroy(struct stream2 * const stream2);
// }}} server
// kv {{{
struct kv {
u64 hash; // hashvalue of the key
u32 klen;
u32 vlen;
u8 kv[]; // len(kv) == klen + vlen
};
extern size_t
kv_size(const struct kv * const kv);
extern size_t
kv_size_align(const struct kv * const kv, const u64 align);
extern size_t
key_size(const struct kv * const key);
extern size_t
key_size_align(const struct kv * const key, const u64 align);
extern void
kv_update_hash(struct kv * const kv);
extern void
kv_refill(struct kv * const kv, const void * const key, const u32 klen, const void * const value, const u32 vlen);
extern void
kv_refill_str(struct kv * const kv, const char * const key, const char * const value);
extern struct kv *
kv_create(const void * const key, const u32 klen, const void * const value, const u32 vlen);
extern struct kv *
kv_create_str(const char * const key, const char * const value);
extern struct kv *
kv_dup(const struct kv * const kv);
extern struct kv *
kv_dup_key(const struct kv * const kv);
extern struct kv *
kv_dup2(const struct kv * const from, struct kv * const to);
extern struct kv *
kv_dup2_key(const struct kv * const from, struct kv * const to);
extern bool
kv_keymatch(const struct kv * const key1, const struct kv * const key2);
extern bool
kv_fullmatch(const struct kv * const kv1, const struct kv * const kv2);
typedef int (*kv_compare_func)(const struct kv * const kv1, const struct kv * const kv2);
extern int
kv_keycompare(const struct kv * const kv1, const struct kv * const kv2);
extern void
kv_qsort(const struct kv ** const kvs, const size_t nr);
extern void *
kv_value_ptr(struct kv * const kv);
extern void *
kv_key_ptr(struct kv * const kv);
extern const void *
kv_value_ptr_const(const struct kv * const kv);
extern const void *
kv_key_ptr_const(const struct kv * const kv);
extern struct kv *
kv_alloc_malloc(const u64 size, void * const priv);
extern void
kv_retire_free(struct kv * const kv, void * const priv);
// }}} kv
// kvmap {{{
struct kvmap_api {
// no create function in api
void * map;
// thread-safe basic functions:
struct kv * (* get) (void * map, const struct kv * const key, struct kv * const out);
bool (* probe) (void * map, const struct kv * const key);
bool (* set) (void * map, const struct kv * const kv);
bool (* del) (void * map, const struct kv * const key);
// unsafe functions:
void (* clean) (void * map);
void (* destroy) (void * map);
void (* fprint) (void * map, FILE * const out);
void * (* iter_create) (void * map);
struct kv * (* iter_next) (void * iter, struct kv * const out);
void (* iter_destroy) (void * iter);
};
extern void
kvmap_api_destroy(struct kvmap_api * const api);
typedef struct kv * (* kv_alloc_func)(const u64, void * const);
typedef void (* kv_retire_func)(struct kv * const, void * const);
typedef void (* kvmap_hit_func)(const struct kv * const, void * const);
typedef void (* kvmap_uncache_func)(struct kv * const, void * const);
typedef void (* cache_refresh_func)(struct kv * const, const struct kv * const, void * const);
struct kvmap_mm {
kv_alloc_func af;
void * ap;
kv_retire_func rf;
void * rp;
kvmap_hit_func hf;
void * hp;
kvmap_uncache_func uf;
void * up;
cache_refresh_func xf;
void * xp;
};
extern void
kvmap_api_helper_message(void);
extern int
kvmap_api_helper(int argc, char ** const argv, struct kvmap_api ** const out, struct kvmap_mm * const mm, const bool use_ucache);
// }}} kvmap
// kvmap2 {{{
struct kvmap2;
extern struct kvmap2 *
kvmap2_create(const struct kvmap_mm * const mm);
extern struct kv *
kvmap2_get(struct kvmap2 * const map2, const struct kv * const key, struct kv * const out);
extern bool
kvmap2_probe(struct kvmap2 * const map2, const struct kv * const key);
extern bool
kvmap2_set(struct kvmap2 * const map2, const struct kv * const kv);
extern bool
kvmap2_del(struct kvmap2 * const map2, const struct kv * const key);
extern void
kvmap2_clean(struct kvmap2 * const map2);
extern void
kvmap2_destroy(struct kvmap2 * const map2);
extern void
kvmap2_fprint(struct kvmap2 * const map2, FILE * const out);
struct kvmap2_iter;
extern struct kvmap2_iter *
kvmap2_iter_create(struct kvmap2 * const map2);
extern struct kv *
kvmap2_iter_next(struct kvmap2_iter * const iter2, struct kv * const out);
extern void
kvmap2_iter_destroy(struct kvmap2_iter * const iter2);
extern struct kvmap_api *
kvmap2_api_create(struct kvmap2 * const map);
// }}} kvmap2
// cuckoo {{{
struct cuckoo;
extern struct cuckoo *
cuckoo_create(const struct kvmap_mm * const mm);
extern struct kv *
cuckoo_get(struct cuckoo * const map, const struct kv * const key, struct kv * const out);
extern bool
cuckoo_probe(struct cuckoo * const map, const struct kv * const key);
extern bool
cuckoo_set(struct cuckoo * const map, const struct kv * const kv);
extern bool
cuckoo_del(struct cuckoo * const map, const struct kv * const key);
extern void
cuckoo_clean(struct cuckoo * const map);
extern void
cuckoo_destroy(struct cuckoo * const map);
extern void
cuckoo_fprint(struct cuckoo * const map, FILE * const out);
extern struct cuckoo_iter *
cuckoo_iter_create(struct cuckoo * const map);
extern struct kv *
cuckoo_iter_next(struct cuckoo_iter * const iter, struct kv * const out);
extern void
cuckoo_iter_destroy(struct cuckoo_iter * const iter);
extern struct kvmap_api *
cuckoo_api_create(struct cuckoo * const map);
// }}} cuckoo
// skiplist {{{
struct skiplist;
extern struct skiplist *
skiplist_create_f(const struct kvmap_mm * const mm, kv_compare_func comp);
extern struct skiplist *
skiplist_create(const struct kvmap_mm * const mm);
extern struct kv *
skiplist_get(struct skiplist * const list, const struct kv * const key, struct kv * const out);
extern bool
skiplist_probe(struct skiplist * const list, const struct kv * const key);
extern bool
skiplist_set(struct skiplist * const list, const struct kv * const kv);
extern bool
skiplist_del(struct skiplist * const list, const struct kv * const key);
extern void
skiplist_clean(struct skiplist * const list);
extern void
skiplist_destroy(struct skiplist * const list);
extern void
skiplist_fprint(struct skiplist * const list, FILE * const out);
extern struct kv *
skiplist_head(struct skiplist * const list, struct kv * const out);
extern struct kv *
skiplist_tail(struct skiplist * const list, struct kv * const out);
struct skiplist_iter;
extern struct skiplist_iter *
skiplist_iter_create(struct skiplist * const list);
extern struct kv *
skiplist_iter_next(struct skiplist_iter * const iter, struct kv * const out);
extern void
skiplist_iter_destroy(struct skiplist_iter * const iter);
extern struct kvmap_api *
skiplist_api_create(struct skiplist * const map);
// }}} skiplist
// chainmap {{{
struct chainmap;
extern struct chainmap *
chainmap_create(const struct kvmap_mm * const mm);
extern struct kv *
chainmap_get(struct chainmap * const map, const struct kv * const key, struct kv * const out);
extern bool
chainmap_probe(struct chainmap * const map, const struct kv * const key);
extern bool
chainmap_set(struct chainmap * const map, const struct kv * const kv);
extern bool
chainmap_del(struct chainmap * const map, const struct kv * const key);
extern void
chainmap_clean(struct chainmap * const map);
extern void
chainmap_destroy(struct chainmap * const map);
extern void
chainmap_fprint(struct chainmap * const map, FILE * const out);
extern struct chainmap_iter *
chainmap_iter_create(struct chainmap * const map);
extern struct kv *
chainmap_iter_next(struct chainmap_iter * const iter, struct kv * const out);
extern void
chainmap_iter_destroy(struct chainmap_iter * const iter);
extern struct kvmap_api *
chainmap_api_create(struct chainmap * const map);
// }}} chainmap
// bptree {{{
struct bptree;
extern struct bptree *
bptree_create(const struct kvmap_mm * const mm);
extern struct kv *
bptree_get(struct bptree * const tree, const struct kv * const key, struct kv * const out);
extern bool
bptree_probe(struct bptree * const tree, const struct kv * const key);
extern bool
bptree_set(struct bptree * const tree, const struct kv * const kv0);
extern bool
bptree_del(struct bptree * const tree, const struct kv * const key);
extern void
bptree_clean(struct bptree * const tree);
extern void
bptree_destroy(struct bptree * const tree);
extern void
bptree_fprint(struct bptree * const tree, FILE * const out);
struct bptree_iter;
extern struct bptree_iter *
bptree_iter_create(struct bptree * const tree);
extern struct kv *
bptree_iter_next(struct bptree_iter * const iter, struct kv * const out);
extern void
bptree_iter_destroy(struct bptree_iter * const iter);
extern struct kvmap_api *
bptree_api_create(struct bptree * const map);
// }}} bptree
// tcpmap {{{
struct tcpmap;
extern struct tcpmap *
tcpmap_create(const char * const host, const int port);
extern struct kv *
tcpmap_get(struct tcpmap * const map, const struct kv * const key, struct kv * const out);
extern bool
tcpmap_probe(struct tcpmap * const map, const struct kv * const key);
extern bool
tcpmap_set(struct tcpmap * const map, const struct kv * const kv0);
extern bool
tcpmap_del(struct tcpmap * const map, const struct kv * const key);
extern void
tcpmap_clean(struct tcpmap * const map);
extern void
tcpmap_destroy(struct tcpmap * const map);
extern struct kvmap_api *
tcpmap_api_create(struct tcpmap * const map);
// }}} tcpmap
// icache {{{
struct icache;
extern struct icache *
icache_create(const struct kvmap_mm * const mm, const u64 nr_mb);
extern struct kv *
icache_get(struct icache * const cache, const struct kv * const key, struct kv * const out);
extern bool
icache_probe(struct icache * const cache, const struct kv * const key);
extern bool
icache_set(struct icache * const cache, const struct kv * const kv);
extern bool
icache_del(struct icache * const cache, const struct kv * const key);
extern void
icache_clean(struct icache * const cache);
extern void