Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testHash.C
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 <ctime>
29
30# include <gsl/gsl_rng.h>
31
32# include <tclap/CmdLine.h>
33
34# include <iostream>
35# include <aleph.H>
36# include <tpl_dynSetHash.H>
37
38# include <cassert>
39using namespace std;
40# include <cassert>
41using namespace TCLAP;
42
43CmdLine cmd = { "testHash", ' ', "0" };
44
46 { "n", "num", "num of keys", false, 10, "num of keys", cmd };
47
48ValueArg<size_t> seed = { "s", "seed", "seed", false, (size_t) time(nullptr),
49 "seed for random", cmd };
50
51void test(size_t n, unsigned long seed)
52{
55
58
59 for (size_t i = 0; i < n; ++i)
60 {
61 unsigned long val = gsl_rng_get(r);
62 const string sval = to_string(val);
63 a.append(make_pair(i, sval));
64 tbl.insert(i, sval);
65 }
66
67 tbl.for_each([] (auto p) { cout << p.first << ", " << p.second << endl; });
68
69 for (auto it = tbl.get_it(); it.has_curr(); it.next())
70 {
71 auto p = it.get_curr();
72 auto key = p.first;
73 auto ptr = tbl.search(key);
74 cout << key << " == " << ptr->first << " " << p.second << " == "
75 << ptr->second << endl;
76 assert(key == ptr->first);
77 assert(p.second == ptr->second);
78 }
79
80 for (size_t i = 0; i < n; ++i)
81 {
82 auto p1 = a(i);
83 auto ptr = tbl.search(p1.first);
84 assert(p1.first == ptr->first);
85 assert(p1.second == ptr->second);
86 }
87
89}
90
91int main(int argc, char *argv[])
92{
93 cmd.parse(argc, argv);
94 test(num_keys.getValue(), seed.getValue());
95}
96
Core header for the Aleph-w library.
T & append()
Allocate a new entry to the end of array.
MapOLhash< int, Foo > tbl
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::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.
void test()
Definition test-comb.C:35
ValueArg< size_t > num_keys
Definition testHash.C:45
CmdLine cmd
Definition testHash.C:43
ValueArg< size_t > seed
Definition testHash.C:48
gsl_rng * r
Dynamic set implementations based on hash tables.