-
Notifications
You must be signed in to change notification settings - Fork 1
/
sparr.h
47 lines (35 loc) · 1022 Bytes
/
sparr.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
// sparr.h -- Slow but memory-efficient sparse array header.
#ifndef sparr_h
#define sparr_h
#include "config.h"
#if HAVE_STDINT_H
# include <stdint.h>
#endif /* else we get int types from config.h */
#include <sys/types.h>
typedef struct sparr *sparr;
#include "dirent.h"
#include "util.h"
#define GROUP_SIZE 48
typedef struct spgroup {
uint8_t mask[CEILDIV(GROUP_SIZE, 8)];
uint16_t fill;
dirent *slots;
} *spgroup;
struct sparr {
size_t cap; // Capacity of this array.
size_t fill; // How many buckets are occupied.
spgroup groups[];
};
spgroup make_spgroup();
int spgroup_test(spgroup g, uint16_t i);
dirent spgroup_get(spgroup g, uint16_t i);
int spgroup_set(spgroup g, uint16_t i, dirent v);
int spgroup_rm(spgroup g, uint16_t i);
void spgroup_free(spgroup g);
sparr make_sparr(int cap);
int sparr_test(sparr a, size_t i);
dirent sparr_get(sparr a, size_t i);
int sparr_set(sparr a, size_t i, dirent v);
int sparr_rm(sparr a, size_t i);
void sparr_free(sparr a);
#endif //sparr_h