Data Structures | Macros | Typedefs | Functions
tommytrieinp.h File Reference

In-place trie. More...

Go to the source code of this file.

Data Structures

struct  tommy_trie_inplace_node_struct
 Trie node. More...
 
struct  tommy_trie_inplace_struct
 Trie container type. More...
 

Macros

#define TOMMY_TRIE_INPLACE_BIT   32
 Number of bits supported for in-place trie keys. More...
 
#define TOMMY_TRIE_INPLACE_TREE_MAX   4
 Number of branches on each node. More...
 

Typedefs

typedef struct tommy_trie_inplace_node_struct tommy_trie_inplace_node
 Trie node. More...
 
typedef struct tommy_trie_inplace_struct tommy_trie_inplace
 Trie container type. More...
 

Functions

TOMMY_API void tommy_trie_inplace_init (tommy_trie_inplace *trie_inplace)
 Initializes the trie. More...
 
TOMMY_API void tommy_trie_inplace_clear (tommy_trie_inplace *trie_inplace)
 Removes all elements. More...
 
void tommy_trie_inplace_swap (tommy_trie_inplace *first, tommy_trie_inplace *second)
 Exchanges the complete state of two initialized tries. More...
 
TOMMY_API void tommy_trie_inplace_insert (tommy_trie_inplace *trie_inplace, tommy_trie_inplace_node *node, void *data, tommy_key_t key)
 Inserts an element in the trie. More...
 
TOMMY_API void * tommy_trie_inplace_insert_unique (tommy_trie_inplace *trie_inplace, tommy_trie_inplace_node *node, void *data, tommy_key_t key)
 Inserts an element only if no element with the same numeric key is already contained. More...
 
TOMMY_API void * tommy_trie_inplace_remove (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Searches and removes the first element with the specified key. More...
 
tommy_trie_inplace_node * tommy_trie_inplace_bucket (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Gets the bucket of the specified key. More...
 
tommy_trie_inplace_node * tommy_trie_inplace_find (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Finds the first node with the specified key. More...
 
void * tommy_trie_inplace_search (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Searches an element in the trie. More...
 
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_find_less (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Finds the last node in key order with key strictly less than the specified one. More...
 
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_find_less_equal (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Finds the last node in key order with key less or equal than the specified one. More...
 
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_find_greater_equal (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Finds the first node in key order with key greater or equal than the specified one. More...
 
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_find_greater (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Finds the first node in key order with key strictly greater than the specified one. More...
 
TOMMY_API void * tommy_trie_inplace_search_less (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Searches the last element in key order with key strictly less than the specified one. More...
 
TOMMY_API void * tommy_trie_inplace_search_less_equal (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Searches the last element in key order with key less or equal than the specified one. More...
 
TOMMY_API void * tommy_trie_inplace_search_greater_equal (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Searches the first element in key order with key greater or equal than the specified one. More...
 
TOMMY_API void * tommy_trie_inplace_search_greater (tommy_trie_inplace *trie_inplace, tommy_key_t key)
 Searches the first element in key order with key strictly greater than the specified one. More...
 
TOMMY_API void * tommy_trie_inplace_remove_existing (tommy_trie_inplace *trie_inplace, tommy_trie_inplace_node *node)
 Removes an element from the trie. More...
 
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_head (tommy_trie_inplace *trie_inplace)
 Gets the head (smallest key) node in the trie. More...
 
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_tail (tommy_trie_inplace *trie_inplace)
 Gets the tail (greatest key) node in the trie. More...
 
void * tommy_trie_inplace_remove_head (tommy_trie_inplace *trie_inplace)
 Removes and returns the head (smallest key) element. More...
 
void * tommy_trie_inplace_remove_tail (tommy_trie_inplace *trie_inplace)
 Removes and returns the tail (greatest key) element. More...
 
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_next (tommy_trie_inplace *trie_inplace, tommy_trie_inplace_node *node)
 Gets the node following the specified one by increasing numeric key. More...
 
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_prev (tommy_trie_inplace *trie_inplace, tommy_trie_inplace_node *node)
 Gets the node preceding the specified one by increasing numeric key. More...
 
TOMMY_API void tommy_trie_inplace_foreach (tommy_trie_inplace *trie_inplace, tommy_foreach_func *func)
 Calls the specified function for each element in the trie. More...
 
TOMMY_API void tommy_trie_inplace_foreach_arg (tommy_trie_inplace *trie_inplace, tommy_foreach_arg_func *func, void *arg)
 Calls the specified function with an argument for each element in the trie. More...
 
tommy_size_t tommy_trie_inplace_count (const tommy_trie_inplace *trie_inplace)
 Gets the number of elements. More...
 
tommy_bool_t tommy_trie_inplace_empty (const tommy_trie_inplace *trie_inplace)
 Checks whether the trie is empty. More...
 
TOMMY_API tommy_size_t tommy_trie_inplace_memory_usage (const tommy_trie_inplace *trie_inplace)
 Gets the size of allocated memory. More...
 

Detailed Description

In-place trie.

This trie is an in-place implementation not needing any external allocation.

Unlike tommy_trie, elements also represent the inner nodes and are not stored in key order. Ordered traversal merges each node's elements with its child subtrees.

You can control the number of branches of each node using the TOMMY_TRIE_INPLACE_TREE_MAX define. More branches imply more speed, but a bigger memory occupation.

Compared to tommy_trie you should use a lower number of branches to limit the unused memory occupation of the leaf nodes. This implies a lower speed, but without the need of an external allocator.

To initialize the trie you have to call tommy_trie_inplace_init().

tommy_trie_inplace trie_inplace;
tommy_trie_inplace_init(&trie_inplace);
Trie container type.
Definition: tommytrieinp.h:218
TOMMY_API void tommy_trie_inplace_init(tommy_trie_inplace *trie_inplace)
Initializes the trie.

To insert elements in the trie you have to call tommy_trie_inplace_insert() for each element. In the insertion call you have to specify the address of the node, the address of the element, and the key value to use. The address of the element is used to initialize the tommy_trie_inplace_node::data field of the node, and the key to initialize the tommy_trie_inplace_node::key field.

struct element {
int value;
// other fields
};
struct element* elem = malloc(sizeof(struct element)); // creates the element
elem->value = ...; // initializes the element
tommy_trie_inplace_insert(&trie_inplace, &elem->node, elem, elem->value); // inserts the element
Trie node.
Definition: tommytrieinp.h:206
TOMMY_API void tommy_trie_inplace_insert(tommy_trie_inplace *trie_inplace, tommy_trie_inplace_node *node, void *data, tommy_key_t key)
Inserts an element in the trie.

To find an element in the trie you have to call tommy_trie_inplace_search() providing the key to search.

int value_to_find = 1;
struct element* elem = tommy_trie_inplace_search(&trie_inplace, value_to_find);
if (!elem) {
// not found
} else {
// found
}
void * tommy_trie_inplace_search(tommy_trie_inplace *trie_inplace, tommy_key_t key)
Searches an element in the trie.
Definition: tommytrieinp.h:335

To find a key bound, use tommy_trie_inplace_search_less(), tommy_trie_inplace_search_less_equal(), tommy_trie_inplace_search_greater_equal(), or tommy_trie_inplace_search_greater(). Like the corresponding tommy_tree searches, the less searches return the last qualifying element in key and insertion order, and the greater searches return the first. They return the element pointer, or 0 if no key qualifies, and accept the same key range as tommy_trie_inplace_search().

To iterate over all the elements in the trie with the same key, you have to use tommy_trie_inplace_bucket() and follow the tommy_trie_inplace_node::next pointer until 0.

int value_to_find = 1;
tommy_trie_inplace_node* i = tommy_trie_inplace_bucket(&trie_inplace, value_to_find);
while (i) {
struct element* elem = i->data; // gets the element pointer
printf("%d\n", elem->value); // process the element
i = i->next; // goes to the next element
}
void * data
Pointer to the data.
Definition: tommytrieinp.h:209
struct tommy_trie_inplace_node_struct * next
Next element.
Definition: tommytrieinp.h:207
tommy_trie_inplace_node * tommy_trie_inplace_bucket(tommy_trie_inplace *trie_inplace, tommy_key_t key)
Gets the bucket of the specified key.
Definition: tommytrieinp.h:299

To iterate over all elements by increasing key, start with tommy_trie_inplace_head() and advance with tommy_trie_inplace_next(). Equal keys are visited in insertion order. Use tommy_trie_inplace_tail() and tommy_trie_inplace_prev() for the reverse order.

while (i) {
struct element* elem = i->data;
printf("%d\n", elem->value);
i = tommy_trie_inplace_next(&trie_inplace, i);
}
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_head(tommy_trie_inplace *trie_inplace)
Gets the head (smallest key) node in the trie.
TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_next(tommy_trie_inplace *trie_inplace, tommy_trie_inplace_node *node)
Gets the node following the specified one by increasing numeric key.

Iterators are pointers to nodes contained in the trie. Inserting elements or removing other nodes between iterator calls does not invalidate pointers to nodes that remain in the trie. Subsequent next/prev calls use the current contents and ordering; inserted elements may become visible and removed elements are skipped.

Removing the pointed node invalidates its use as an iterator, even if its storage has not been freed. To continue traversal after removing the current node, obtain the next or previous node before removal.

Keys and fields used for ordering must not be modified while contained. Concurrent traversal and modification require external synchronization.

The container passed to next/prev must currently contain the node. After swapping containers, use the container that now owns the node.

To remove an element from the trie you have to call tommy_trie_inplace_remove() providing the key to search and remove.

struct element* elem = tommy_trie_inplace_remove(&trie_inplace, value_to_remove);
if (elem) {
free(elem); // frees the element allocated memory
}
TOMMY_API void * tommy_trie_inplace_remove(tommy_trie_inplace *trie_inplace, tommy_key_t key)
Searches and removes the first element with the specified key.

To remove the smallest or greatest element, use tommy_trie_inplace_remove_head() or tommy_trie_inplace_remove_tail(). With equal keys, they remove the first or last element in insertion order, respectively, like the corresponding tommy_tree operations. They return the removed element, or 0 if empty.

To visit all the elements use tommy_trie_inplace_foreach() or tommy_trie_inplace_foreach_arg(). Elements are visited by increasing key, with equal keys in insertion order.

To destroy the trie you can deallocate all the elements with tommy_trie_inplace_foreach(), as the trie doesn't allocate memory.

tommy_trie_inplace_foreach(&trie_inplace, free);
TOMMY_API void tommy_trie_inplace_foreach(tommy_trie_inplace *trie_inplace, tommy_foreach_func *func)
Calls the specified function for each element in the trie.

Macro Definition Documentation

◆ TOMMY_TRIE_INPLACE_BIT

#define TOMMY_TRIE_INPLACE_BIT   32

Number of bits supported for in-place trie keys.

All keys must fit in TOMMY_TRIE_INPLACE_BIT bits, even if tommy_key_t is wider. This requirement is checked with assert(), and is not enforced when assertions are disabled.

Increase this value to support larger keys. Keeping it small improves trie performance.

◆ TOMMY_TRIE_INPLACE_TREE_MAX

#define TOMMY_TRIE_INPLACE_TREE_MAX   4

Number of branches on each node.

It must be a power of 2. Suggested values are 2, 4 and 8. Any node, including leafs, contains a pointer to each branch.

Typedef Documentation

◆ tommy_trie_inplace_node

Trie node.

This is the node that you have to include inside your elements.

◆ tommy_trie_inplace

Trie container type.

Note
Don't use internal fields directly, but access the container only using functions.

Function Documentation

◆ tommy_trie_inplace_init()

TOMMY_API void tommy_trie_inplace_init ( tommy_trie_inplace *  trie_inplace)

Initializes the trie.

The trie is completely in-place, and it doesn't need to be deinitialized.

Parameters
trie_inplaceThe trie.

◆ tommy_trie_inplace_clear()

TOMMY_API void tommy_trie_inplace_clear ( tommy_trie_inplace *  trie_inplace)

Removes all elements.

The trie remains initialized and can be reused immediately. Elements are not freed and nodes are not accessed or modified. Their links must not be used to traverse the previous contents. You can call this function after tommy_trie_inplace_foreach() has freed the elements.

Parameters
trie_inplaceThe trie.
Note
This operation is O(1) with respect to the number of elements.

◆ tommy_trie_inplace_swap()

void tommy_trie_inplace_swap ( tommy_trie_inplace *  first,
tommy_trie_inplace *  second 
)

Exchanges the complete state of two initialized tries.

The tries must not share nodes. Nodes and elements are not accessed or modified. Existing node pointers remain valid and belong to the other trie. Passing the same trie twice has no effect. Both tries remain usable and require no deinitialization.

Parameters
firstThe first trie.
secondThe second trie.
Note
This operation is O(1) with respect to the number of elements.

◆ tommy_trie_inplace_insert()

TOMMY_API void tommy_trie_inplace_insert ( tommy_trie_inplace *  trie_inplace,
tommy_trie_inplace_node *  node,
void *  data,
tommy_key_t  key 
)

Inserts an element in the trie.

Parameters
trie_inplaceThe trie.
nodePointer to the node embedded into the element to insert.
dataPointer to the element to insert.
keyKey to use to insert the element.

◆ tommy_trie_inplace_insert_unique()

TOMMY_API void * tommy_trie_inplace_insert_unique ( tommy_trie_inplace *  trie_inplace,
tommy_trie_inplace_node *  node,
void *  data,
tommy_key_t  key 
)

Inserts an element only if no element with the same numeric key is already contained.

If found, the first element with that key in insertion order is returned. The candidate node and trie are left unchanged, and no memory is allocated. Otherwise, the candidate is inserted using the normal insertion policy and data is returned.

Parameters
trie_inplaceThe trie.
nodeThe candidate node. It must not belong to any container.
dataPointer to the element to insert.
keyNumeric key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The first equal element, or data if the candidate was inserted.

◆ tommy_trie_inplace_remove()

TOMMY_API void * tommy_trie_inplace_remove ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Searches and removes the first element with the specified key.

If the element is not found, 0 is returned. If more equal elements are present, the first one is removed. This operation is faster than calling tommy_trie_inplace_bucket() and tommy_trie_inplace_remove_existing() separately.

Parameters
trie_inplaceThe trie.
keyKey of the element to find and remove.
Returns
The removed element, or 0 if not found.

◆ tommy_trie_inplace_bucket()

tommy_trie_inplace_node * tommy_trie_inplace_bucket ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Gets the bucket of the specified key.

The bucket is guaranteed to contain ALL and ONLY the elements with the specified key. You can access elements in the bucket following the tommy_trie_inplace_node::next pointer until 0.

Parameters
trie_inplaceThe trie.
keyKey of the element to find.
Returns
The head of the bucket, or 0 if empty.

◆ tommy_trie_inplace_find()

tommy_trie_inplace_node * tommy_trie_inplace_find ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Finds the first node with the specified key.

If multiple elements have the key, the first in insertion order is returned.

Parameters
trie_inplaceThe trie.
keyKey of the element to find.
Returns
The first node found, or 0 if none.

◆ tommy_trie_inplace_search()

void * tommy_trie_inplace_search ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Searches an element in the trie.

You have to provide the key of the element you want to find. If more elements with the same key are present, the first one is returned.

Parameters
trie_inplaceThe trie.
keyKey of the element to find.
Returns
The first element found, or 0 if none.

◆ tommy_trie_inplace_find_less()

TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_find_less ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Finds the last node in key order with key strictly less than the specified one.

If multiple elements have the selected key, the last in insertion order is returned.

Parameters
trie_inplaceThe trie.
keySearch key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The selected node, or 0 if none.

◆ tommy_trie_inplace_find_less_equal()

TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_find_less_equal ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Finds the last node in key order with key less or equal than the specified one.

If multiple elements have the selected key, the last in insertion order is returned.

Parameters
trie_inplaceThe trie.
keySearch key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The selected node, or 0 if none.

◆ tommy_trie_inplace_find_greater_equal()

TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_find_greater_equal ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Finds the first node in key order with key greater or equal than the specified one.

If multiple elements have the selected key, the first in insertion order is returned.

Parameters
trie_inplaceThe trie.
keySearch key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The selected node, or 0 if none.

◆ tommy_trie_inplace_find_greater()

TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_find_greater ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Finds the first node in key order with key strictly greater than the specified one.

If multiple elements have the selected key, the first in insertion order is returned.

Parameters
trie_inplaceThe trie.
keySearch key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The selected node, or 0 if none.

◆ tommy_trie_inplace_search_less()

TOMMY_API void * tommy_trie_inplace_search_less ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Searches the last element in key order with key strictly less than the specified one.

If multiple elements have the selected key, the last in insertion order is returned.

Parameters
trie_inplaceThe trie.
keySearch key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The selected element, or 0 if none.

◆ tommy_trie_inplace_search_less_equal()

TOMMY_API void * tommy_trie_inplace_search_less_equal ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Searches the last element in key order with key less or equal than the specified one.

If multiple elements have the selected key, the last in insertion order is returned.

Parameters
trie_inplaceThe trie.
keySearch key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The selected element, or 0 if none.

◆ tommy_trie_inplace_search_greater_equal()

TOMMY_API void * tommy_trie_inplace_search_greater_equal ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Searches the first element in key order with key greater or equal than the specified one.

If multiple elements have the selected key, the first in insertion order is returned.

Parameters
trie_inplaceThe trie.
keySearch key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The selected element, or 0 if none.

◆ tommy_trie_inplace_search_greater()

TOMMY_API void * tommy_trie_inplace_search_greater ( tommy_trie_inplace *  trie_inplace,
tommy_key_t  key 
)

Searches the first element in key order with key strictly greater than the specified one.

If multiple elements have the selected key, the first in insertion order is returned.

Parameters
trie_inplaceThe trie.
keySearch key, which must fit within TOMMY_TRIE_INPLACE_BIT bits.
Returns
The selected element, or 0 if none.

◆ tommy_trie_inplace_remove_existing()

TOMMY_API void * tommy_trie_inplace_remove_existing ( tommy_trie_inplace *  trie_inplace,
tommy_trie_inplace_node *  node 
)

Removes an element from the trie.

You must already have the address of the node to remove.

Parameters
trie_inplaceThe trie.
nodeThe node to remove.
Returns
The removed element.

◆ tommy_trie_inplace_head()

TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_head ( tommy_trie_inplace *  trie_inplace)

Gets the head (smallest key) node in the trie.

If multiple elements have the smallest key, the first in insertion order is returned.

Parameters
trie_inplaceThe trie.
Returns
The head node, or 0 if the trie is empty.

◆ tommy_trie_inplace_tail()

TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_tail ( tommy_trie_inplace *  trie_inplace)

Gets the tail (greatest key) node in the trie.

If multiple elements have the greatest key, the last in insertion order is returned.

Parameters
trie_inplaceThe trie.
Returns
The tail node, or 0 if the trie is empty.

◆ tommy_trie_inplace_remove_head()

void * tommy_trie_inplace_remove_head ( tommy_trie_inplace *  trie_inplace)

Removes and returns the head (smallest key) element.

If multiple elements have the smallest key, the first in insertion order is removed.

Parameters
trie_inplaceThe trie.
Returns
The removed element, or 0 if the trie is empty.
Note
Uses tommy_trie_inplace_head() and tommy_trie_inplace_remove_existing().

◆ tommy_trie_inplace_remove_tail()

void * tommy_trie_inplace_remove_tail ( tommy_trie_inplace *  trie_inplace)

Removes and returns the tail (greatest key) element.

If multiple elements have the greatest key, the last in insertion order is removed.

Parameters
trie_inplaceThe trie.
Returns
The removed element, or 0 if the trie is empty.
Note
Uses tommy_trie_inplace_tail() and tommy_trie_inplace_remove_existing().

◆ tommy_trie_inplace_next()

TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_next ( tommy_trie_inplace *  trie_inplace,
tommy_trie_inplace_node *  node 
)

Gets the node following the specified one by increasing numeric key.

Elements with equal keys are visited in insertion order. See tommy_trie_inplace_iterator_validity for iterator validity across insertions and removals.

Parameters
trie_inplaceThe trie.
nodeNode currently contained in the trie. It must not be 0.
Returns
The following node, or 0 for the tail node.
Note
Moving within duplicates is O(1). Moving to another key traverses the trie from the root, bounded by the number of key bits and branches per level.

◆ tommy_trie_inplace_prev()

TOMMY_API tommy_trie_inplace_node * tommy_trie_inplace_prev ( tommy_trie_inplace *  trie_inplace,
tommy_trie_inplace_node *  node 
)

Gets the node preceding the specified one by increasing numeric key.

Elements with equal keys are visited in reverse insertion order. See tommy_trie_inplace_iterator_validity for iterator validity across insertions and removals.

Parameters
trie_inplaceThe trie.
nodeNode currently contained in the trie. It must not be 0.
Returns
The preceding node, or 0 for the head node.
Note
Moving within duplicates is O(1). Moving to another key traverses the trie from the root, bounded by the number of key bits and branches per level.

◆ tommy_trie_inplace_foreach()

TOMMY_API void tommy_trie_inplace_foreach ( tommy_trie_inplace *  trie_inplace,
tommy_foreach_func *  func 
)

Calls the specified function for each element in the trie.

Elements are visited by increasing key, with equal keys in insertion order. The callback receives the data field of each node. An empty trie does not invoke the callback.

The callback may deallocate the current element, including its embedded node. It must not add or remove elements, modify keys or node links, or deallocate other elements or the trie. This operation does not remove elements or update the count.

No memory is allocated. Stack space is bounded by the number of key bits.

If the callback frees the elements, the trie retains dangling node pointers. Call tommy_trie_inplace_clear() or tommy_trie_inplace_init() before reusing it. The trie has no storage to release.

Parameters
trie_inplaceThe trie.
funcFunction to call with each element.

◆ tommy_trie_inplace_foreach_arg()

TOMMY_API void tommy_trie_inplace_foreach_arg ( tommy_trie_inplace *  trie_inplace,
tommy_foreach_arg_func *  func,
void *  arg 
)

Calls the specified function with an argument for each element in the trie.

The iteration order and callback rules are the same as tommy_trie_inplace_foreach(). The callback receives arg followed by the data field of each node.

Parameters
trie_inplaceThe trie.
funcFunction to call with each element.
argArgument to pass to the function.

◆ tommy_trie_inplace_count()

tommy_size_t tommy_trie_inplace_count ( const tommy_trie_inplace *  trie_inplace)

Gets the number of elements.

Parameters
trie_inplaceThe trie.
Returns
The number of elements in the trie.
Note
This operation is O(1).

◆ tommy_trie_inplace_empty()

tommy_bool_t tommy_trie_inplace_empty ( const tommy_trie_inplace *  trie_inplace)

Checks whether the trie is empty.

Parameters
trie_inplaceThe trie.
Returns
Nonzero if the trie is empty, 0 otherwise.
Note
This operation is O(1).

◆ tommy_trie_inplace_memory_usage()

TOMMY_API tommy_size_t tommy_trie_inplace_memory_usage ( const tommy_trie_inplace *  trie_inplace)

Gets the size of allocated memory.

It includes the size of the tommy_trie_inplace_node of the stored elements.

Parameters
trie_inplaceThe trie.
Returns
Total memory allocated by the trie, in bytes.