Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
persistent_containers_example.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 https://github.com/lrleon/Aleph-w
6
7 This file is part of Aleph-w library
8
9 Copyright (c) 2002-2026 Leandro Rabindranath Leon
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 SOFTWARE.
28*/
29
41#include <iostream>
42#include <string>
43
46
47int main()
48{
50 auto ids_v1 = ids.insert(10).insert(20);
51 auto ids_v2 = ids_v1.insert(15).erase(10);
52
53 std::cout << "ids_v1 contains 10: " << ids_v1.contains(10) << '\n';
54 std::cout << "ids_v2 contains 10: " << ids_v2.contains(10) << '\n';
55
57 auto names_v1 = names.insert(1, std::string("Ada"));
58 auto names_v2 = names_v1.insert_or_assign(1, std::string("Ada Lovelace"));
59
60 std::cout << "old name: " << *names_v1.find(1) << '\n';
61 std::cout << "new name: " << *names_v2.find(1) << '\n';
62
64 auto log_v1 = log.push_back(std::string("created"));
65 auto log_v2 = log_v1.push_back(std::string("reviewed"));
66 auto log_v3 = log_v2.set(1, std::string("approved"));
67
68 std::cout << "log_v2[1]: " << log_v2.get(1) << '\n';
69 std::cout << "log_v3[1]: " << log_v3.get(1) << '\n';
70
71 return ids_v1.contains(10) and not ids_v2.contains(10) and
72 *names_v1.find(1) == "Ada" and *names_v2.find(1) == "Ada Lovelace" and
73 log_v2.get(1) == "reviewed" and log_v3.get(1) == "approved" ? 0 : 1;
74}
Immutable ordered map backed by a path-copying treap.
const T * find(const Key &key) const
Find a mapped value.
and std::constructible_from< T, VArg && > PersistentTreapMap insert_or_assign(KArg &&key, VArg &&value) const
Return a new version with key assigned to value.
and std::constructible_from< T, VArg && > PersistentTreapMap insert(KArg &&key, VArg &&value) const
Return a new version with a binding inserted if absent.
Immutable ordered set backed by a path-copying treap.
PersistentTreapSet erase(const Key &key) const
Return a new version without key.
PersistentTreapSet insert(const Key &key) const
Return a new version with key inserted by copy.
bool contains(const Key &key) const
Test whether key is present.
Immutable vector backed by a 32-way bitmapped trie.
PersistentVector push_back(const T &value) const
Return a new version with value appended by copy.
const T & get(const size_t index) const
Read a value by index.
PersistentVector set(const size_t index, const T &value) const
Return a new version with one index replaced by copy.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_log_function > > log(const __gmp_expr< T, U > &expr)
Definition gmpfrxx.h:4074
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
and
Check uniqueness with explicit hash + equality functors.
Immutable path-copying treap set and map.
Immutable bitmapped-vector trie with structural sharing.