|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Compressed bitwise map for unsigned integral keys. More...
#include <tpl_patricia_trie.H>
Classes | |
| struct | Node |
Public Types | |
| using | Key = UInt |
| Key type stored by the map. | |
| using | Value = T |
| Mapped value type stored at each leaf. | |
Public Member Functions | |
| PatriciaMap ()=default | |
| Construct an empty map. | |
| ~PatriciaMap ()=default | |
| Destructor. | |
| PatriciaMap (const PatriciaMap &other) | |
| Deep-copy constructor. | |
| PatriciaMap & | operator= (const PatriciaMap &other) |
| Deep-copy assignment. | |
| PatriciaMap (PatriciaMap &&other) noexcept | |
| Move constructor. | |
| PatriciaMap & | operator= (PatriciaMap &&other) noexcept |
| Move assignment. | |
| size_t | size () const noexcept |
| Return the number of stored key-value pairs. | |
| bool | is_empty () const noexcept |
| Check whether the map has no key-value pairs. | |
| void | clear () noexcept |
| Remove every key-value pair from the map. | |
| bool | insert (const Key key, const Value &value) |
Insert key with a copy of value, only if key is absent. | |
| bool | insert (const Key key, Value &&value) |
Insert key with value moved in, only if key is absent. | |
| void | insert_or_assign (const Key key, Value value) |
Insert key or overwrite the mapped value if key exists. | |
| bool | erase (const Key key) noexcept |
Remove key if present. | |
| bool | contains (const Key key) const noexcept |
Check whether key is stored. | |
| const Value * | find (const Key key) const noexcept |
Look up key. | |
| Value * | find (const Key key) noexcept |
| Mutable lookup overload. | |
| Array< Key > | keys () const |
| Return all stored keys. | |
| bool | check_invariants () const noexcept |
| Verify structural invariants recursively. | |
Static Public Attributes | |
| static constexpr size_t | bit_width = std::numeric_limits<Key>::digits |
Number of significant bits in Key. | |
Private Types | |
| using | Detail = patricia_trie_detail::Bitwise_Trie_Utils< Key > |
Private Member Functions | |
| template<typename U > | |
| bool | insert_impl (const Key key, U &&value) |
Static Private Member Functions | |
| static std::unique_ptr< Node > | clone_node (const Node *src) |
Private Attributes | |
| std::unique_ptr< Node > | root_ |
| size_t | size_ = 0 |
Compressed bitwise map for unsigned integral keys.
PatriciaMap is the mapped-value counterpart of PatriciaSet. It stores unique fixed-width unsigned integer keys and one value per key. Internal nodes only record the first discriminating bit; leaves store the complete key and its associated value.
| UInt | Unsigned integral key type. bool is rejected because it has only two values and does not benefit from a trie representation. |
| T | Mapped value type. Must be move-constructible for insertion and copy-constructible only if the map itself is copied. |
Definition at line 547 of file tpl_patricia_trie.H.
|
private |
Definition at line 576 of file tpl_patricia_trie.H.
Key type stored by the map.
Definition at line 551 of file tpl_patricia_trie.H.
Mapped value type stored at each leaf.
Definition at line 554 of file tpl_patricia_trie.H.
|
default |
Construct an empty map.
| Nothing. |
|
default |
Destructor.
Recursively releases every node.
| Nothing. |
|
inline |
Deep-copy constructor.
| [in] | other | Map to copy. |
| Whatever | T's copy constructor throws, or std::bad_alloc. |
Definition at line 636 of file tpl_patricia_trie.H.
|
inlinenoexcept |
Move constructor.
| [in,out] | other | Source map, left empty. |
| Nothing. |
Definition at line 661 of file tpl_patricia_trie.H.
References Aleph::blossom_maximum_cardinality_matching().
|
inlinenoexcept |
Verify structural invariants recursively.
Checks that internal nodes have two children and no value, internal bit indexes strictly increase down every path, each child subtree matches the routing bit used to reach it, every leaf has a value, and the number of leaves equals size().
true iff all invariants hold. | Nothing. |
Definition at line 820 of file tpl_patricia_trie.H.
References Aleph::and, and Aleph::blossom_maximum_cardinality_matching().
Remove every key-value pair from the map.
| Nothing. |
Definition at line 704 of file tpl_patricia_trie.H.
|
inlinestaticprivate |
Definition at line 578 of file tpl_patricia_trie.H.
References Aleph::blossom_maximum_cardinality_matching().
Check whether key is stored.
| [in] | key | Key to query. |
true if key is present. | Nothing. |
Definition at line 768 of file tpl_patricia_trie.H.
References Aleph::find().
Remove key if present.
| [in] | key | Key to erase. |
true if erased, false if absent. | Nothing. |
Definition at line 758 of file tpl_patricia_trie.H.
Look up key.
| [in] | key | Key to look up. |
key is present, nullptr otherwise. Valid until the next non-const operation on this map. | Nothing. |
Definition at line 779 of file tpl_patricia_trie.H.
References Aleph::and, Aleph::PatriciaMap< UInt, T >::Node::key, and Aleph::PatriciaMap< UInt, T >::Node::value.
Mutable lookup overload.
| [in] | key | Key to look up. |
key is present, nullptr otherwise. Valid until the next non-const operation on this map. | Nothing. |
Definition at line 792 of file tpl_patricia_trie.H.
References Aleph::and, Aleph::PatriciaMap< UInt, T >::Node::key, and Aleph::PatriciaMap< UInt, T >::Node::value.
Insert key with a copy of value, only if key is absent.
| [in] | key | Key to insert. |
| [in] | value | Value to copy into the new leaf. |
true if inserted, false if key was already present. | Whatever | T's copy constructor throws, or std::bad_alloc. |
Definition at line 717 of file tpl_patricia_trie.H.
References value.
Insert key with value moved in, only if key is absent.
| [in] | key | Key to insert. |
| [in,out] | value | Value to move into the new leaf. |
true if inserted, false if key was already present. | Whatever | T's move constructor throws, or std::bad_alloc. |
key is already present, value is left untouched. The duplicate check happens before the value is forwarded. Definition at line 732 of file tpl_patricia_trie.H.
References value.
Definition at line 594 of file tpl_patricia_trie.H.
References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), and value.
Insert key or overwrite the mapped value if key exists.
| [in] | key | Key to insert or update. |
| [in] | value | New value. It is moved into place. |
| Whatever | T's move/copy constructor or move assignment throws, or std::bad_alloc. |
Definition at line 744 of file tpl_patricia_trie.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::find(), and value.
|
inlinenoexcept |
Check whether the map has no key-value pairs.
true iff size() == 0. | Nothing. |
Definition at line 696 of file tpl_patricia_trie.H.
|
inline |
Return all stored keys.
Array containing every key in unspecified order. | std::bad_alloc | if the returned array cannot grow. |
Definition at line 802 of file tpl_patricia_trie.H.
References Aleph::Array< T >::reserve().
|
inline |
Deep-copy assignment.
| [in] | other | Map to copy. |
*this. | Whatever | T's copy constructor throws, or std::bad_alloc. |
Definition at line 646 of file tpl_patricia_trie.H.
References Aleph::blossom_maximum_cardinality_matching().
|
inlinenoexcept |
Move assignment.
| [in,out] | other | Source map, left empty. |
*this. | Nothing. |
Definition at line 672 of file tpl_patricia_trie.H.
References Aleph::blossom_maximum_cardinality_matching().
|
inlinenoexcept |
Return the number of stored key-value pairs.
| Nothing. |
Definition at line 687 of file tpl_patricia_trie.H.
|
staticconstexpr |
Number of significant bits in Key.
Definition at line 557 of file tpl_patricia_trie.H.
|
private |
Definition at line 574 of file tpl_patricia_trie.H.
Definition at line 575 of file tpl_patricia_trie.H.