libsapling  0.8.0
typed_trie.h
Go to the documentation of this file.
1 #ifndef _LIBSAPLING_TYPED_TRIE_H_
2 #define _LIBSAPLING_TYPED_TRIE_H_
3 
9 #include <stdlib.h>
11 #include "libsapling/cc/lexer.h"
12 
13 #define IMPLEMENT_TYPED_TRIE(SYM, TYPE, FPF) \
14  \
15 IMPLEMENT_TYPED_ADAPTERS(SYM, TYPE, trie) \
16  \
17 static \
18 void SYM##__access(enum qt qt, node_t *ref, const char *key, void *info, \
19  SYM##__predicate_t predicate, SYM##__apply_t apply) \
20 { \
21  struct SYM##__adapt a = { 0, NULL, info, predicate, apply }; \
22  trie__access(qt, ref, key, &a, SYM##__predicate_adapter, \
23  SYM##__apply_adapter); \
24 } \
25  \
26 static \
27 void SYM##__insert(node_t *ref, const char *key, TYPE val) \
28 { \
29  TYPE *data = malloc(sizeof(TYPE)); \
30  *data = val; \
31  trie__insert(ref, key, data); \
32 } \
33  \
34 static \
35 void SYM##__delete(node_t *ref, const char *key) \
36 { \
37  trie__delete(ref, key); \
38 } \
39  \
40 static \
41 void SYM##__print(FILE *stream, node_t *ref) \
42 { \
43  trie__print(stream, ref, FPF); \
44 } \
45  \
46 static \
47 void SYM##__dump_dot(FILE *stream, node_t *ref) \
48 { \
49  lexer__dump_dot(stream, ref, FPF); \
50 } \
51  \
52 static \
53 int SYM##__length(const node_t *ref) \
54 { \
55  return trie__length(ref); \
56 } \
57  \
58  \
59 static \
60 void SYM##__found_key(node_t *ref, const struct info_stack *info) \
61 { \
62  int *found = info->user; \
63  \
64  *found = 1; \
65 } \
66  \
67 static \
68 int SYM##__in(node_t *ref, const char *key) \
69 { \
70  int in = 0; \
71  trie__access(E_QT, ref, key, &in, predicate_1, SYM##__found_key); \
72  return in; \
73 }
74 
75 #endif
Lexer implementation hello.
Implementation of typed adapters for predicate and apply functions.