xref: /php-src/ext/dom/lexbor/lexbor/core/sbst.h (revision bffab33a)
1 /*
2  * Copyright (C) 2018 Alexander Borisov
3  *
4  * Author: Alexander Borisov <borisov@lexbor.com>
5  */
6 
7 #ifndef LEXBOR_SBST_H
8 #define LEXBOR_SBST_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <string.h>
15 
16 #include "lexbor/core/base.h"
17 
18 
19 typedef struct {
20     lxb_char_t key;
21 
22     lxb_char_t         value[6];
23     unsigned char      value_len;
24 
25     unsigned short     left;
26     unsigned short     right;
27     unsigned short     next;
28 }
29 lexbor_sbst_entry_static_t;
30 
31 
32 /*
33  * Inline functions
34  */
35 lxb_inline const lexbor_sbst_entry_static_t *
lexbor_sbst_entry_static_find(const lexbor_sbst_entry_static_t * strt,const lexbor_sbst_entry_static_t * root,const lxb_char_t key)36 lexbor_sbst_entry_static_find(const lexbor_sbst_entry_static_t *strt,
37                               const lexbor_sbst_entry_static_t *root,
38                               const lxb_char_t key)
39 {
40     while (root != strt) {
41         if (root->key == key) {
42             return root;
43         }
44         else if (key > root->key) {
45             root = &strt[root->right];
46         }
47         else {
48             root = &strt[root->left];
49         }
50     }
51 
52     return NULL;
53 }
54 
55 #ifdef __cplusplus
56 } /* extern "C" */
57 #endif
58 
59 #endif /* LEXBOR_SBST_H */
60