aboutsummaryrefslogtreecommitdiff
path: root/util/dict.h
blob: 2da8e6f12dec13e747c8502c760fd5b39f0a3160 (plain)
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
#ifndef DICT_H
#define DICT_H

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

struct level {
    uint64_t bit_mask;
    uint64_t *token_masks;
};

#ifndef MAPPED_CHARS
#define MAPPED_CHARS 32
#endif

struct dict {
    // parameters for compilation
    struct string_token {
        char *s;
        int t;
    } *strings;
    size_t nstrings;
    uint8_t *char_to_bit;

    // result of compilation
    struct level start_level;
    struct level *bit_to_ptr[MAPPED_CHARS];
    size_t num_levels;
};

#define DICT_INIT(strings_, nstrings_, char_to_bit_) (struct dict){.strings = strings_, .nstrings = nstrings_, .char_to_bit = char_to_bit_}

int dict_compile(struct dict *d);
void dict_free(struct dict *d);
void dict_print(struct dict *d);
int dict_check(struct dict *d, char *string);

#endif