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