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

Trie optimized for cache utilization. More...

Go to the source code of this file.

Data Structures

struct  tommy_trie_struct
 Trie container type. More...
 

Macros

#define TOMMY_TRIE_BIT   32
 Number of bits supported for trie keys. More...
 
#define TOMMY_TRIE_TREE_MAX   (64 / sizeof(void*))
 Number of branches on each inner node. More...
 
#define TOMMY_TRIE_BLOCK_SIZE   (TOMMY_TRIE_TREE_MAX * sizeof(void*))
 Trie block size. More...
 

Typedefs

typedef tommy_node tommy_trie_node
 Trie node. More...
 
typedef struct tommy_trie_struct tommy_trie
 Trie container type. More...
 

Functions

TOMMY_API void tommy_trie_init (tommy_trie *trie, tommy_allocator *alloc)
 Initializes the trie. More...
 
void tommy_trie_swap (tommy_trie *first, tommy_trie *second)
 Exchanges the complete state of two initialized tries, including their allocator references. More...
 
TOMMY_API void tommy_trie_clear (tommy_trie *trie)
 Removes all elements, preserving the allocator reference. More...
 
TOMMY_API void tommy_trie_insert (tommy_trie *trie, tommy_trie_node *node, void *data, tommy_key_t key)
 Inserts an element in the trie. More...
 
TOMMY_API void * tommy_trie_insert_unique (tommy_trie *trie, tommy_trie_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_remove (tommy_trie *trie, tommy_key_t key)
 Searches and removes the first element with the specified key. More...
 
TOMMY_API tommy_trie_node * tommy_trie_bucket (tommy_trie *trie, tommy_key_t key)
 Gets the bucket of the specified key. More...
 
tommy_trie_node * tommy_trie_find (tommy_trie *trie, tommy_key_t key)
 Finds the first node with the specified key. More...
 
void * tommy_trie_search (tommy_trie *trie, tommy_key_t key)
 Searches an element in the trie. More...
 
TOMMY_API tommy_trie_node * tommy_trie_find_less (tommy_trie *trie, tommy_key_t key)
 Finds the last node in key order with key strictly less than the specified one. More...
 
TOMMY_API tommy_trie_node * tommy_trie_find_less_equal (tommy_trie *trie, 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_node * tommy_trie_find_greater_equal (tommy_trie *trie, 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_node * tommy_trie_find_greater (tommy_trie *trie, 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_search_less (tommy_trie *trie, 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_search_less_equal (tommy_trie *trie, 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_search_greater_equal (tommy_trie *trie, 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_search_greater (tommy_trie *trie, 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_remove_existing (tommy_trie *trie, tommy_trie_node *node)
 Removes an element from the trie. More...
 
TOMMY_API tommy_trie_node * tommy_trie_head (tommy_trie *trie)
 Gets the head (smallest key) node in the trie. More...
 
TOMMY_API tommy_trie_node * tommy_trie_tail (tommy_trie *trie)
 Gets the tail (greatest key) node in the trie. More...
 
void * tommy_trie_remove_head (tommy_trie *trie)
 Removes and returns the head (smallest key) element. More...
 
void * tommy_trie_remove_tail (tommy_trie *trie)
 Removes and returns the tail (greatest key) element. More...
 
TOMMY_API tommy_trie_node * tommy_trie_next (tommy_trie *trie, tommy_trie_node *node)
 Gets the node following the specified one by increasing numeric key. More...
 
TOMMY_API tommy_trie_node * tommy_trie_prev (tommy_trie *trie, tommy_trie_node *node)
 Gets the node preceding the specified one by increasing numeric key. More...
 
TOMMY_API void tommy_trie_to_list (tommy_trie *trie, tommy_list *list)
 Transfers all elements from the trie to the tail of a list by increasing numeric key. More...
 
TOMMY_API void tommy_trie_foreach (tommy_trie *trie, tommy_foreach_func *func)
 Calls the specified function for each element in the trie. More...
 
TOMMY_API void tommy_trie_foreach_arg (tommy_trie *trie, 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_count (const tommy_trie *trie)
 Gets the number of elements. More...
 
tommy_bool_t tommy_trie_empty (const tommy_trie *trie)
 Checks whether the trie is empty. More...
 
TOMMY_API tommy_size_t tommy_trie_memory_usage (const tommy_trie *trie)
 Gets the size of allocated memory. More...
 

Detailed Description

Trie optimized for cache utilization.

This trie is a standard implementation that stores elements in the order defined by the key.

It needs an external allocator for the inner nodes in the trie.

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

Compared to tommy_trie_inplace you have to provide a tommy_allocator allocator. Note that the C malloc() is too slow to fulfill this role.

To initialize the trie you have to call tommy_allocator_init() to initialize the allocator, and tommy_trie_init() for the trie.

tommy_trie_init(&trie, &alloc);
Allocator of fixed-size blocks.
Definition: tommyalloc.h:27
Trie container type.
Definition: tommytrie.h:207
TOMMY_API void tommy_allocator_init(tommy_allocator *alloc, tommy_size_t block_size, tommy_size_t align_size)
Initializes the allocator.
#define TOMMY_TRIE_BLOCK_SIZE
Trie block size.
Definition: tommytrie.h:179
TOMMY_API void tommy_trie_init(tommy_trie *trie, tommy_allocator *alloc)
Initializes the trie.

To insert elements in the trie you have to call tommy_trie_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_node::data field of the node, and the key to initialize the tommy_node::index field.

struct element {
int value;
// other fields
tommy_node node;
};
struct element* elem = malloc(sizeof(struct element)); // creates the element
elem->value = ...; // initializes the element
tommy_trie_insert(&trie, &elem->node, elem, elem->value); // inserts the element
Data structure node.
Definition: tommytypes.h:242
TOMMY_API void tommy_trie_insert(tommy_trie *trie, tommy_trie_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_search() providing the key to search.

int value_to_find = 1;
struct element* elem = tommy_trie_search(&trie, value_to_find);
if (!elem) {
// not found
} else {
// found
}
void * tommy_trie_search(tommy_trie *trie, tommy_key_t key)
Searches an element in the trie.
Definition: tommytrie.h:319

To find a key bound, use tommy_trie_search_less(), tommy_trie_search_less_equal(), tommy_trie_search_greater_equal(), or tommy_trie_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_search().

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

int value_to_find = 1;
tommy_node* i = tommy_trie_bucket(&trie, 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
}
struct tommy_node_struct * next
Next node.
Definition: tommytypes.h:247
void * data
Pointer to the element containing the node.
Definition: tommytypes.h:260
TOMMY_API tommy_trie_node * tommy_trie_bucket(tommy_trie *trie, tommy_key_t key)
Gets the bucket of the specified key.

To iterate over all elements by increasing key, start with tommy_trie_head() and advance with tommy_trie_next(). Equal keys are visited in insertion order. Use tommy_trie_tail() and tommy_trie_prev() for the reverse order.

while (i) {
struct element* elem = i->data;
printf("%d\n", elem->value);
i = tommy_trie_next(&trie, i);
}
TOMMY_API tommy_trie_node * tommy_trie_head(tommy_trie *trie)
Gets the head (smallest key) node in the trie.
TOMMY_API tommy_trie_node * tommy_trie_next(tommy_trie *trie, tommy_trie_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_remove() providing the key to search and remove.

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

To remove the smallest or greatest element, use tommy_trie_remove_head() or tommy_trie_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_foreach() or tommy_trie_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_foreach(), and deinitialize the allocator using tommy_allocator_done(). The allocator must no longer be used by other tries.

tommy_trie_foreach(&trie, free);
TOMMY_API void tommy_allocator_done(tommy_allocator *alloc)
Deinitializes the allocator.
TOMMY_API void tommy_trie_foreach(tommy_trie *trie, tommy_foreach_func *func)
Calls the specified function for each element in the trie.

Macro Definition Documentation

◆ TOMMY_TRIE_BIT

#define TOMMY_TRIE_BIT   32

Number of bits supported for trie keys.

All keys must fit in TOMMY_TRIE_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_TREE_MAX

#define TOMMY_TRIE_TREE_MAX   (64 / sizeof(void*))

Number of branches on each inner node.

It must be a power of 2. Suggested values are 8, 16 and 32. Any inner node, excluding leafs, contains a pointer to each branch.

The default size is chosen to exactly fit a typical cache line of 64 bytes.

◆ TOMMY_TRIE_BLOCK_SIZE

#define TOMMY_TRIE_BLOCK_SIZE   (TOMMY_TRIE_TREE_MAX * sizeof(void*))

Trie block size.

You must use this value to initialize the allocator.

Typedef Documentation

◆ tommy_trie_node

Trie node.

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

◆ tommy_trie

typedef struct tommy_trie_struct tommy_trie

Trie container type.

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

Function Documentation

◆ tommy_trie_init()

TOMMY_API void tommy_trie_init ( tommy_trie *  trie,
tommy_allocator *  alloc 
)

Initializes the trie.

You have to provide an allocator initialized with both the size and align with TOMMY_TRIE_BLOCK_SIZE. You can share this allocator with other tries.

The trie is completely allocated through the allocator, and it doesn't need to be deinitialized.

Parameters
trieThe trie.
allocAllocator initialized with both the size and align with TOMMY_TRIE_BLOCK_SIZE.

◆ tommy_trie_swap()

void tommy_trie_swap ( tommy_trie *  first,
tommy_trie *  second 
)

Exchanges the complete state of two initialized tries, including their allocator references.

Each allocator reference moves with its internal nodes so subsequent operations use the associated allocator. 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. Referenced allocators must remain initialized. Passing the same trie twice has no effect. Both tries remain usable; their memory is released through their allocators.

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

◆ tommy_trie_clear()

TOMMY_API void tommy_trie_clear ( tommy_trie *  trie)

Removes all elements, preserving the allocator reference.

The trie remains initialized and can be reused immediately with the same allocator. 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_foreach() has freed the elements. Internal nodes are returned to the allocator, leaving the trie empty. Other tries sharing the allocator are unaffected. No memory is allocated; free blocks remain available for reuse in the allocator.

Parameters
trieThe trie.
Note
This operation is O(n), with stack space bounded by the number of key bits.

◆ tommy_trie_insert()

TOMMY_API void tommy_trie_insert ( tommy_trie *  trie,
tommy_trie_node *  node,
void *  data,
tommy_key_t  key 
)

Inserts an element in the trie.

Parameters
trieThe 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_insert_unique()

TOMMY_API void * tommy_trie_insert_unique ( tommy_trie *  trie,
tommy_trie_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, including its allocator, are left unchanged, and no memory is allocated. Otherwise, the candidate is inserted using the normal insertion policy and data is returned.

Parameters
trieThe 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_BIT bits.
Returns
The first equal element, or data if the candidate was inserted.

◆ tommy_trie_remove()

TOMMY_API void * tommy_trie_remove ( tommy_trie *  trie,
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_bucket() and tommy_trie_remove_existing() separately.

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

◆ tommy_trie_bucket()

TOMMY_API tommy_trie_node * tommy_trie_bucket ( tommy_trie *  trie,
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_node::next pointer until 0.

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

◆ tommy_trie_find()

tommy_trie_node * tommy_trie_find ( tommy_trie *  trie,
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
trieThe trie.
keyKey of the element to find.
Returns
The first node found, or 0 if none.

◆ tommy_trie_search()

void * tommy_trie_search ( tommy_trie *  trie,
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
trieThe trie.
keyKey of the element to find.
Returns
The first element found, or 0 if none.

◆ tommy_trie_find_less()

TOMMY_API tommy_trie_node * tommy_trie_find_less ( tommy_trie *  trie,
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
trieThe trie.
keySearch key, which must fit within TOMMY_TRIE_BIT bits.
Returns
The selected node, or 0 if none.

◆ tommy_trie_find_less_equal()

TOMMY_API tommy_trie_node * tommy_trie_find_less_equal ( tommy_trie *  trie,
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
trieThe trie.
keySearch key, which must fit within TOMMY_TRIE_BIT bits.
Returns
The selected node, or 0 if none.

◆ tommy_trie_find_greater_equal()

TOMMY_API tommy_trie_node * tommy_trie_find_greater_equal ( tommy_trie *  trie,
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
trieThe trie.
keySearch key, which must fit within TOMMY_TRIE_BIT bits.
Returns
The selected node, or 0 if none.

◆ tommy_trie_find_greater()

TOMMY_API tommy_trie_node * tommy_trie_find_greater ( tommy_trie *  trie,
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
trieThe trie.
keySearch key, which must fit within TOMMY_TRIE_BIT bits.
Returns
The selected node, or 0 if none.

◆ tommy_trie_search_less()

TOMMY_API void * tommy_trie_search_less ( tommy_trie *  trie,
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
trieThe trie.
keySearch key, which must fit within TOMMY_TRIE_BIT bits.
Returns
The selected element, or 0 if none.

◆ tommy_trie_search_less_equal()

TOMMY_API void * tommy_trie_search_less_equal ( tommy_trie *  trie,
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
trieThe trie.
keySearch key, which must fit within TOMMY_TRIE_BIT bits.
Returns
The selected element, or 0 if none.

◆ tommy_trie_search_greater_equal()

TOMMY_API void * tommy_trie_search_greater_equal ( tommy_trie *  trie,
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
trieThe trie.
keySearch key, which must fit within TOMMY_TRIE_BIT bits.
Returns
The selected element, or 0 if none.

◆ tommy_trie_search_greater()

TOMMY_API void * tommy_trie_search_greater ( tommy_trie *  trie,
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
trieThe trie.
keySearch key, which must fit within TOMMY_TRIE_BIT bits.
Returns
The selected element, or 0 if none.

◆ tommy_trie_remove_existing()

TOMMY_API void * tommy_trie_remove_existing ( tommy_trie *  trie,
tommy_trie_node *  node 
)

Removes an element from the trie.

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

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

◆ tommy_trie_head()

TOMMY_API tommy_trie_node * tommy_trie_head ( tommy_trie *  trie)

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

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

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

◆ tommy_trie_tail()

TOMMY_API tommy_trie_node * tommy_trie_tail ( tommy_trie *  trie)

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

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

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

◆ tommy_trie_remove_head()

void * tommy_trie_remove_head ( tommy_trie *  trie)

Removes and returns the head (smallest key) element.

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

Parameters
trieThe trie.
Returns
The removed element, or 0 if the trie is empty.
Note
Uses tommy_trie_head() and tommy_trie_remove_existing().

◆ tommy_trie_remove_tail()

void * tommy_trie_remove_tail ( tommy_trie *  trie)

Removes and returns the tail (greatest key) element.

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

Parameters
trieThe trie.
Returns
The removed element, or 0 if the trie is empty.
Note
Uses tommy_trie_tail() and tommy_trie_remove_existing().

◆ tommy_trie_next()

TOMMY_API tommy_trie_node * tommy_trie_next ( tommy_trie *  trie,
tommy_trie_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_iterator_validity for iterator validity across insertions and removals.

Parameters
trieThe 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_prev()

TOMMY_API tommy_trie_node * tommy_trie_prev ( tommy_trie *  trie,
tommy_trie_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_iterator_validity for iterator validity across insertions and removals.

Parameters
trieThe 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_to_list()

TOMMY_API void tommy_trie_to_list ( tommy_trie *  trie,
tommy_list *  list 
)

Transfers all elements from the trie to the tail of a list by increasing numeric key.

Elements with equal keys retain their insertion order. Existing list elements remain before the transferred elements; an initially empty list is therefore sorted. The list must be initialized and must not share nodes with the trie. Elements are not freed, and the node data and index fields are left unchanged. Internal nodes are returned to the allocator, leaving the trie empty and reusable with the same allocator. Other tries sharing the allocator are unaffected. No memory is allocated; free blocks remain available for reuse in the allocator.

Parameters
trieThe trie to drain.
listThe destination list.
Note
This operation is O(n), with stack space bounded by the number of key bits.

◆ tommy_trie_foreach()

TOMMY_API void tommy_trie_foreach ( tommy_trie *  trie,
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, the trie, or its allocator. 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_clear() before reusing it to release its internal nodes to the allocator, or tommy_allocator_done() to release its storage.

Parameters
trieThe trie.
funcFunction to call with each element.

◆ tommy_trie_foreach_arg()

TOMMY_API void tommy_trie_foreach_arg ( tommy_trie *  trie,
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_foreach(). The callback receives arg followed by the data field of each node.

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

◆ tommy_trie_count()

tommy_size_t tommy_trie_count ( const tommy_trie *  trie)

Gets the number of elements.

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

◆ tommy_trie_empty()

tommy_bool_t tommy_trie_empty ( const tommy_trie *  trie)

Checks whether the trie is empty.

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

◆ tommy_trie_memory_usage()

TOMMY_API tommy_size_t tommy_trie_memory_usage ( const tommy_trie *  trie)

Gets the size of allocated memory.

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

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