Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test-odhash.cc
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
26*/
27
28# include <memory>
29# include <iostream>
30# include "tpl_odhash.H"
31
32using namespace std;
33
34struct Foo
35{
36 string a = "hello world";
37 Foo() {}
38 Foo(const string & str) : a(str) {}
39};
40
42{
44 const pair<pair<const Foo*, const Foo*>, string> & p2) const
45 {
46 return p1.first == p2.first;
47 }
48};
49
52
53static size_t fst_unit_pair_hash
54(const pair<pair<const Foo*, const Foo*>, string> & p)
55{
56 return pair_dft_hash_fct(p.first);
57}
58
59static size_t snd_unit_pair_hash
60(const pair<pair<const Foo*, const Foo*>, string> & p)
61{
62 return pair_snd_hash_fct(p.first);
63}
64
66
67int main()
68{
70 for (size_t i = 0; i < 1000; ++i)
72
73 shared_ptr<Foo> f1(new Foo("Hola"));
74 shared_ptr<Foo> f2(new Foo("Mundo"));
75
76 static_cast<void>(m.insert(make_pair(make_pair(f1.get(), f2.get()),
77 f1->a + " " + f2->a)));
78
79 for (auto it = foos.get_it(); it.has_curr(); it.next())
80 {
81 auto f1 = it.get_curr().get();
82 for (auto it = foos.get_it(); it.has_curr(); it.next())
83 static_cast<void>(m.insert(make_pair(make_pair(f1, it.get_curr().get()),
84 f1->a + " " + it.get_curr()->a)));
85 }
86
87 for (auto it = foos.get_it(); it.has_curr(); it.next())
88 {
89 auto f1 = it.get_curr().get();
90 for (auto it = foos.get_it(); it.has_curr(); it.next())
91 m.remove(make_pair(make_pair(f1, it.get_curr().get()), ""));
92 }
93
94 for (auto it = m.get_it(); it.has_curr(); it.next())
95 {
96 auto p = it.get_curr();
97 cout << p.second << endl;
98 }
99}
T & append()
Allocate a new entry to the end of array.
Open addressing hash table with double hashing collision resolution.
Definition tpl_odhash.H:182
void remove(const Key &key)
Remove a key from the hash table.
Definition tpl_odhash.H:903
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:222
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Definition hashDry.H:203
size_t pair_snd_hash_fct(const std::pair< K1, K2 > &p) noexcept
Definition hash-fct.H:1134
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
Definition ahPair.H:89
size_t pair_dft_hash_fct(const std::pair< K1, K2 > &p) noexcept
Definition hash-fct.H:1121
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
Definition ah-date.H:140
STL namespace.
bool operator()(const pair< pair< const Foo *, const Foo * >, string > &p1, const pair< pair< const Foo *, const Foo * >, string > &p2) const
Foo(const string &str)
string a
static size_t fst_unit_pair_hash(const pair< pair< const Foo *, const Foo * >, string > &p)
static size_t snd_unit_pair_hash(const pair< pair< const Foo *, const Foo * >, string > &p)
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
int main()
Open addressing hash table with double hashing.