Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JHashSet.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5
6#include "JTools/JHashSet.hh"
7#include "JLang/JObjectID.hh"
8
9#include "Jeep/JParser.hh"
10#include "Jeep/JMessage.hh"
11
12
13namespace {
14
15 using namespace JPP;
16
17
18 struct __A__ :
19 public JObjectID
20 {
21 /**
22 * Default constructor.
23 */
24 __A__() :
25 JObjectID()
26 {}
27
28
29 /**
30 * Constructor.
31 *
32 * \param id identifier
33 */
34 __A__(const int id) :
35 JObjectID(id)
36 {}
37
38
39 /**
40 * Get hash value.
41 *
42 * \param key key
43 * \return hash value
44 */
45 inline int getKey() const
46 {
47 return getID();
48 }
49 };
50}
51
52
53/**
54 * \file
55 *
56 * Example program to test JTOOLS::JHashSet class.
57 * \author mdejong
58 */
59int main(int argc, char **argv)
60{
61 using namespace std;
62
63 int debug;
64
65 try {
66
67 JParser<> zap("Example program to test hash set.");
68
69 zap['d'] = make_field(debug) = 3;
70
71 zap(argc, argv);
72 }
73 catch(const exception &error) {
74 FATAL(error.what() << endl);
75 }
76
77
78 using namespace JPP;
79
80 typedef JHashSet<__A__> hash_set;
81
82 hash_set buffer;
83
84 for (int i = 1<<10; i != 0; i >>= 1) {
85 buffer.insert(__A__(i));
86 }
87
88 buffer.erase(buffer.find(1<<2), buffer.find(1<<4));
89
90 if (!buffer.erase(1<<4)) {
91 FATAL("Erasing value failed." << endl);
92 }
93
94 for (hash_set::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
95
96 cout << setw(4) << *i;
97 cout << " == ";
98
99 hash_set::const_iterator p = buffer.find(*i);
100
101 if (p != buffer.end())
102 cout << setw(4) << *p << endl;
103 else
104 FATAL("Inconsistent has set at " << *i << endl);
105 }
106
107 return 0;
108}
int main(int argc, char **argv)
Definition JHashSet.cc:59
General purpose class for a hash set of sorted elements.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Auxiliary class for object identification.
Definition JObjectID.hh:25
Utility class to parse command line options.
Definition JParser.hh:1698
void erase(iterator pos)
Erase element at given position.
General purpose class for hash set of elements.
Definition JHashSet.hh:32
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).