|
FE 0.14.0
A C++23 toolkit for writing compiler/interpreter frontends.
|
Hash-consed, immutable sets of D*, ordered by an unsigned id the elements carry themselves. More...
#include <fe/patricia.h>
Classes | |
| class | Set |
| An immutable set - really just a tagged pointer, so copy it around freely. More... | |
Public Member Functions | |
Construction | |
| Patricia & | operator= (const Patricia &)=delete |
| Patricia (size_t page_size=Arena::Default_Page_Size) | |
| Patricia (const Patricia &)=delete | |
| Patricia (Patricia &&other) | |
Set Operations | |
| |
| template<std::ranges::input_range R> requires std::convertible_to<std::ranges::range_reference_t<R>, D*> | |
| Set | create (R &&r) |
Creates a Set with all elements in r. | |
| Set | create (std::initializer_list< D * > list) |
| Set | insert (Set s, D *d) |
| Yields \(s \cup \{d\}\). | |
| Set | erase (Set s, D *d) |
| Yields \(s \setminus \{d\}\). | |
| Set | merge (Set s1, Set s2) |
| Yields \(s_1 \cup s_2\). | |
| Set | intersect (Set s1, Set s2) |
| Yields \(s_1 \cap s_2\). | |
| Set | diff (Set s1, Set s2) |
| Yields \(s_1 \setminus s_2\). | |
Friends | |
| void | swap (Patricia &p1, Patricia &p2) noexcept |
Hash-consed, immutable sets of D*, ordered by an unsigned id the elements carry themselves.
A Patricia tree - a prefix trie over the big-endian bits of the id, as in Okasaki and Gill's Fast Mergeable Integer Maps
| Flavour | Holds |
|---|---|
| empty | nothing; a Set that converts to false |
| Uniq | exactly one D* - inline in the Set itself, so a singleton costs no node at all |
| Arr | 2 to N elements, sorted by id |
| Br | more than N elements: a prefix, its branching bit, and two non-empty children |
The flavour is picked for every subtree, so a branch's children are again single elements, arrays, or branches - which collapses the bottom \(\log_2 N\) levels of the trie into one array each. Patricia shape is canonical (the branching bit of an id set is just the highest bit its minimum and maximum disagree on), so this keeps one element set mapped to exactly one representation.
Ids are ordered as unsigned, i.e. iteration yields 0 first and K(-1) last. KT is a key trait:
Definition at line 64 of file patricia.h.
|
inlineexplicit |
Definition at line 465 of file patricia.h.
References fe::Arena::Default_Page_Size.
Referenced by operator=(), Patricia(), Patricia(), and swap.
|
delete |
References Patricia().
|
inline |
Definition at line 469 of file patricia.h.
References Patricia(), and swap.
|
inlinenodiscard |
Creates a Set with all elements in r.
Definition at line 481 of file patricia.h.
References fe::Vector< T, N, A >::Vector().
|
inlinenodiscard |
|
inlinenodiscard |
Yields \(s_1 \setminus s_2\).
Definition at line 608 of file patricia.h.
References diff(), fe::Patricia< D, KT, K, N >::Set::empty(), and fe::unreachable().
Referenced by diff().
|
inlinenodiscard |
Yields \(s \setminus \{d\}\).
Definition at line 533 of file patricia.h.
References erase(), and fe::Patricia< D, KT, K, N >::Set::Set().
Referenced by erase().
|
inlinenodiscard |
Yields \(s \cup \{d\}\).
s comes back unchanged if it already holds an element with d's id. Definition at line 492 of file patricia.h.
References fe::Patricia< D, KT, K, N >::Set::empty(), insert(), and fe::Patricia< D, KT, K, N >::Set::Set().
Referenced by insert().
|
inlinenodiscard |
Yields \(s_1 \cap s_2\).
Definition at line 585 of file patricia.h.
References fe::Patricia< D, KT, K, N >::Set::empty(), intersect(), and fe::unreachable().
Referenced by intersect().
|
inlinenodiscard |
Yields \(s_1 \cup s_2\).
Definition at line 562 of file patricia.h.
References fe::Patricia< D, KT, K, N >::Set::empty(), merge(), and fe::unreachable().
Referenced by merge().
|
delete |
References Patricia().
|
friend |
Definition at line 630 of file patricia.h.
References Patricia(), and swap.
Referenced by Patricia(), and swap.