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 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32
33# include <memory>
34# include <iostream>
35# include "tpl_odhash.H"
36
37using namespace std;
38
39struct Foo
40{
41 string a = "hello world";
42 Foo() {}
43 Foo(const string & str) : a(str) {}
44};
45
47{
49 const pair<pair<const Foo*, const Foo*>, string> & p2) const
50 {
51 return p1.first == p2.first;
52 }
53};
54
57
58static size_t fst_unit_pair_hash
59(const pair<pair<const Foo*, const Foo*>, string> & p)
60{
61 return pair_dft_hash_fct(p.first);
62}
63
64static size_t snd_unit_pair_hash
65(const pair<pair<const Foo*, const Foo*>, string> & p)
66{
67 return pair_snd_hash_fct(p.first);
68}
69
71
72int main()
73{
75 for (size_t i = 0; i < 1000; ++i)
77
78 shared_ptr<Foo> f1(new Foo("Hola"));
79 shared_ptr<Foo> f2(new Foo("Mundo"));
80
81 static_cast<void>(m.insert(make_pair(make_pair(f1.get(), f2.get()),
82 f1->a + " " + f2->a)));
83
84 for (auto it = foos.get_it(); it.has_curr(); it.next())
85 {
86 auto f1 = it.get_curr().get();
87 for (auto it = foos.get_it(); it.has_curr(); it.next())
88 static_cast<void>(m.insert(make_pair(make_pair(f1, it.get_curr().get()),
89 f1->a + " " + it.get_curr()->a)));
90 }
91
92 for (auto it = foos.get_it(); it.has_curr(); it.next())
93 {
94 auto f1 = it.get_curr().get();
95 for (auto it = foos.get_it(); it.has_curr(); it.next())
96 m.remove(make_pair(make_pair(f1, it.get_curr().get()), ""));
97 }
98
99 for (auto it = m.get_it(); it.has_curr(); it.next())
100 {
101 auto p = it.get_curr();
102 cout << p.second << endl;
103 }
104}
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:228
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Definition hashDry.H:203
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
size_t pair_snd_hash_fct(const std::pair< K1, K2 > &p) noexcept
Definition hash-fct.H:1161
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:1148
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.