Data structure to store chains of discrete choices with an finite range of choices at each position. More...
#include <BoundedNodeTrie.h>
Data Structures | |
struct | AbstractNode |
Abstract base class for nodes to allow differentiation. More... | |
struct | InsertResult |
class | Leaf |
Leaf node at bottom of the tree. More... | |
class | Node |
Most common type of nodes have other AbstractNodes as children. More... | |
Public Types | |
Public types | |
using | ChoiceList = std::vector< ChoiceIndex > |
Type used to represent choices made at each level of the tree. | |
using | ChoosingFunction = std::function< ChoiceIndex(const std::vector< ChoiceIndex > &, const boost::dynamic_bitset<> &)> |
Function signature needed to choose which child to descend to at a level in the tree. | |
Public Member Functions | |
Constructors | |
BoundedNodeTrie ()=default | |
Construct an empty trie, setting the upper exclusive bound on values at each level. More... | |
BoundedNodeTrie (ChoiceList bounds) | |
Construct an empty trie, setting the upper exclusive bound on values at each level. More... | |
Modification | |
bool | insert (const ChoiceList &values) |
Inserts a value list into the prefix trie if not already present. More... | |
ChoiceList | generateNewEntry (const ChoosingFunction &chooseFunction) |
Create a new entry by choosing branch at each level of the trie. More... | |
void | setBounds (ChoiceList bounds) |
Changes the bounds of the trie. Clears the trie. More... | |
void | clear () |
Removes all inserted lists from the trie. More... | |
Information | |
bool | contains (const ChoiceList &values) const |
Checks whether a value list is present in the trie. More... | |
const ChoiceList & | bounds () const |
Accessor for underlying bounds. | |
unsigned | size () const |
Returns the number of value lists this trie contains. More... | |
unsigned | capacity () const |
Returns the total number of value lists this trie might contain. More... | |
Private Types | |
Private types | |
using | NodePtr = std::unique_ptr< AbstractNode > |
Owning pointer to base class. | |
Private Member Functions | |
Private member functions | |
void | establishRoot_ () |
Generate a root node. | |
void | establishCapacity_ () |
Generate a root node. | |
Private Attributes | |
Private members | |
ChoiceList | bounds_ |
NodePtr | root_ |
unsigned | size_ = 0 |
unsigned | capacity_ = 0 |
Data structure to store chains of discrete choices with an finite range of choices at each position.
ChoiceIndex | Value type in which the count of possible choices is representable. This needs to be an integer type. |
|
default |
Construct an empty trie, setting the upper exclusive bound on values at each level.
bounds | The upper exclusive bound on values at each level. |
|
inline |
Construct an empty trie, setting the upper exclusive bound on values at each level.
bounds | The upper exclusive bound on values at each level. |
|
inline |
Returns the total number of value lists this trie might contain.
Complexity \(\Theta(1)\)
|
inline |
Removes all inserted lists from the trie.
Complexity \(\Theta(N)\)
|
inline |
Checks whether a value list is present in the trie.
Complexity \(O(N)\)
values
if contains
returns false, just use insert. That way you have only one trie traversal in all cases, and you get the information of whether it was already in the trie or not too.values | The value list to check for |
|
inline |
Create a new entry by choosing branch at each level of the trie.
Complexity \(\Theta(N)\)
chooseFunction | Function that chooses the branch to descend to at each level. The function is supplied a list of viable choices at the depth (indicating which parts of the tree are full) and a bitset indicating which children exist. |
std::logic_error | If the trie is full, i.e. size() == capacity() |
|
inline |
Inserts a value list into the prefix trie if not already present.
Complexity \(\Theta(N)\)
values | The value list to insert into the prefix trie |
std::logic_error | If no bounds are set. |
values
was not yet a member of the set.
|
inline |
Changes the bounds of the trie. Clears the trie.
Complexity \(\Theta(N)\)
|
inline |
Returns the number of value lists this trie contains.
Complexity \(\Theta(1)\)