/[LeafOK_CVS]/lbbs/src/trie_dict.c
ViewVC logotype

Diff of /lbbs/src/trie_dict.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 by sysadm, Wed May 14 04:21:41 2025 UTC Revision 1.2 by sysadm, Fri May 16 04:54:35 2025 UTC
# Line 39  int char_to_offset(char c) Line 39  int char_to_offset(char c)
39          return -1;          return -1;
40  }  }
41    
42    char offset_to_char(int i)
43    {
44            if (i < 0)
45            {
46                    return '\0';
47            }
48            else if (i < 26)
49            {
50                    return (char)('A' + i);
51            }
52            else if (i < 52)
53            {
54                    return (char)('a' + (i - 26));
55            }
56            else if (i < 62)
57            {
58                    return (char)('0' + (i - 52));
59            }
60            else if (i == 62)
61            {
62                    return '_';
63            }
64    
65            return '\0';
66    }
67    
68  TRIE_NODE *trie_dict_create(void)  TRIE_NODE *trie_dict_create(void)
69  {  {
70          TRIE_NODE *p_dict;          TRIE_NODE *p_dict;
# Line 170  int trie_dict_del(TRIE_NODE *p_dict, con Line 196  int trie_dict_del(TRIE_NODE *p_dict, con
196    
197          return -1; // NULL key          return -1; // NULL key
198  }  }
199    
200    static void _trie_dict_traverse(TRIE_NODE *p_dict, trie_dict_traverse_cb cb, char *key, int depth)
201    {
202            if (p_dict == NULL || depth >= TRIE_MAX_KEY_LEN)
203            {
204                    return;
205            }
206    
207            for (int i = 0; i < TRIE_CHILDREN; i++)
208            {
209                    key[depth] = offset_to_char(i);
210                    key[depth + 1] = '\0';
211    
212                    if (p_dict->flags[i] != 0)
213                    {
214                            (*cb)(key, p_dict->values[i]);
215                    }
216    
217                    if (p_dict->p_nodes[i] != NULL && depth + 1 < TRIE_MAX_KEY_LEN)
218                    {
219                            _trie_dict_traverse(p_dict->p_nodes[i], cb, key, depth + 1);
220                    }
221            }      
222    }
223    
224    void trie_dict_traverse(TRIE_NODE *p_dict, trie_dict_traverse_cb cb)
225    {
226            char key[TRIE_MAX_KEY_LEN + 1];
227    
228            _trie_dict_traverse(p_dict, cb, key, 0);
229    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1