ALWAYS_INLINE void * lwan_trie_lookup_full(lwan_trie_t *trie, const char *key, bool prefix) { if (!trie) return NULL; lwan_trie_node_t *node = _lookup_node(trie->root, key, prefix); return node ? node->data : NULL; }
bool mhash_has_key(MHASH *table, void *key) { struct node **node; if (!table || !key) return false; node = _lookup_node(table, key); if (*node) return true; else return false; }
void* mhash_lookup(MHASH *table, void *key) { struct node **node; if (!table || !key) return NULL; node = _lookup_node(table, key); if (*node) return (*node)->value; else return NULL; }
void* mhash_next(MHASH *table, void **key) { struct node **node; uint32_t row; if (!table || !key) return NULL; /* * return 1st node */ if (*key == NULL) { row = 0; while (row < table->rownum) { if (table->nodes[row]) { *key = table->nodes[row]->key; return table->nodes[row]->value; } row++; } return NULL; } /* * return next follow the *key */ row = table->hash_func(*key) & (table->rownum - 1); node = _lookup_node(table, *key); if (node && *node) { if ((*node)->next) { *key = (*node)->next->key; return (*node)->next->value; } /* next row */ row += 1; while (row < table->rownum) { if (table->nodes[row]) { *key = table->nodes[row]->key; return table->nodes[row]->value; } row++; } } return NULL; }
bool mhash_remove(MHASH *table, void *key) { struct node **node; if (!table || !key) return false; node = _lookup_node(table, key); if (*node) { struct node *lnode = *node; *node = lnode->next; if (table->destroy_func) table->destroy_func(lnode->value); mos_free(lnode); table->num--; return true; } return false; }
MERR* mhash_insert(MHASH *table, void *key, void *value) { struct node **node; MERR_NOT_NULLB(table, key); node = _lookup_node(table, key); if (*node != NULL) { (*node)->value = value; } else { struct node *lnode = mos_calloc(1, sizeof(struct node)); lnode->hashv = table->hash_func(key); lnode->key = key; lnode->value = value; lnode->next = NULL; *node = lnode; table->num++; } _hash_resize(table); return MERR_OK; }