int hattrie_del(hattrie_t* T, const char* key, size_t len) { node_ptr parent = T->root; HT_UNUSED(parent); assert(*parent.flag & NODE_TYPE_TRIE); /* find node for deletion */ node_ptr node = hattrie_find(T, &key, &len); if (node.flag == NULL) { return -1; } /* if consumed on a trie node, clear the value */ if (*node.flag & NODE_TYPE_TRIE) { return hattrie_clrval(T, node); } /* remove from bucket */ size_t m_old = ahtable_size(node.b); int ret = ahtable_del(node.b, key, len); T->m -= (m_old - ahtable_size(node.b)); /* merge empty buckets */ /*! \todo */ return ret; }
/* Create a new trie node with all pointers pointing to the given child (which * can be NULL). */ static trie_node_t* alloc_trie_node(hattrie_t* T, node_ptr child) { trie_node_t* node = malloc_or_die(sizeof(trie_node_t)); node->flag = NODE_TYPE_TRIE; node->val = 0; /* pass T to allow custom allocator for trie. */ HT_UNUSED(T); /* unused now */ size_t i; for (i = 0; i < NODE_CHILDS; ++i) node->xs[i] = child; return node; }