52template <
typename UInt>
55 std::vector<UInt> result;
56 result.reserve(
keys.size());
57 for (
const auto key :
keys)
58 result.push_back(key);
59 std::sort(result.begin(), result.end());
63void demo_set_membership()
65 std::cout <<
"[1] PatriciaSet: integer-key membership\n";
69 for (
const auto id : {7U, 42U, 128U, 255U})
72 std::cout <<
"contains 42: " << std::boolalpha << ids.
contains(42)
73 <<
" (expect true)\n";
74 std::cout <<
"contains 99: " << ids.
contains(99) <<
" (expect false)\n";
77 std::cout <<
"contains 128 after erase: " << ids.
contains(128)
78 <<
" (expect false)\n";
80 std::cout <<
"stored ids: ";
81 for (
const auto id : sorted_keys(ids.
keys()))
82 std::cout << id <<
" ";
88 std::cout <<
"[2] PatriciaMap: integer-key dictionary\n";
92 routes.
insert(10,
"default-lan");
93 routes.
insert(42,
"service-net");
98 std::cout <<
"route 42: " << *
value <<
"\n";
100 std::cout <<
"contains 255: " << routes.
contains(255) <<
"\n";
101 std::cout <<
"contains 11: " << routes.
contains(11) <<
"\n";
103 std::cout <<
"stored route ids: ";
104 for (
const auto id : sorted_keys(routes.
keys()))
105 std::cout << id <<
" ";
109void demo_fixed_width_property()
111 std::cout <<
"[3] Fixed-width bitwise keys\n";
120 std::cout <<
"PatriciaSet<uint8_t>::bit_width = "
122 std::cout <<
"byte keys: ";
123 for (
const auto key : sorted_keys(bytes.
keys()))
124 std::cout << static_cast<unsigned>(key) <<
" ";
131 std::cout <<
"\n=== Aleph::PatriciaSet / PatriciaMap ===\n\n";
133 demo_set_membership();
135 demo_fixed_width_property();
137 std::cout <<
"Done.\n";
size_t size_t int32_t value
Simple dynamic array with automatic resizing and functional operations.
Compressed bitwise map for unsigned integral keys.
bool insert(const Key key, const Value &value)
Insert key with a copy of value, only if key is absent.
void insert_or_assign(const Key key, Value value)
Insert key or overwrite the mapped value if key exists.
const Value * find(const Key key) const noexcept
Look up key.
bool contains(const Key key) const noexcept
Check whether key is stored.
Compressed bitwise set for unsigned integral keys.
bool insert(const Key key)
Insert key if absent.
bool erase(const Key key) noexcept
Remove key if present.
bool contains(const Key key) const noexcept
Check whether key is stored.
Main namespace for Aleph-w library functions.
void print_rule()
Prints a horizontal rule for example output separation.
PATRICIA/crit-bit set and map for fixed-width unsigned integer keys.