Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
JHashCollection.cc File Reference

Example program to test JTOOLS::JHashCollection class. More...

#include <iostream>
#include <iomanip>
#include <cmath>
#include <set>
#include "JTools/JHashCollection.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JTOOLS::JHashCollection class.

Author
mdejong

Definition in file JHashCollection.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 54 of file JHashCollection.cc.

55{
56 using namespace std;
57 using namespace JPP;
58
59 double precision;
60 int debug;
61
62 try {
63
64 JParser<> zap("Example program to test hash collection.");
65
66 zap['e'] = make_field(precision) = 1.0e-3;
67 zap['d'] = make_field(debug) = 3;
68
69 zap(argc, argv);
70 }
71 catch(const exception &error) {
72 FATAL(error.what() << endl);
73 }
74
75
76 typedef JHashCollection<double, get_value> hash_collection;
77
78 hash_collection buffer(precision);
79
80
81 set<double> input = { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0 };
82 set<double> rm = { 1.5, 1.1 };
83
84 for (set<double>::const_reverse_iterator x = input.rbegin(); x != input.rend(); ++x) {
85 buffer.insert(*x);
86 buffer.insert(*x);
87 }
88
89 for (hash_collection::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
90 DEBUG(FIXED(5,2) << *i << endl);
91 }
92
93 ASSERT(buffer.size() == input.size(), "Test of buffer size with multiple inserts of same element.");
94
95
96 for (set<double>::const_iterator x = input.begin(); x != input.end(); ++x) {
97
98 DEBUG(FIXED(5,2) << *x << ' ' << buffer.getIndex(*x) << endl);
99
100 ASSERT(buffer.has(*x), "Test of buffer content.");
101 }
102
103 {
104 hash_collection out(precision);
105
106 out = buffer;
107
108 for (set<double>::const_iterator x = input.begin(); x != input.end(); ++x) {
109
110 DEBUG(FIXED(5,2) << *x << ' ' << out.getIndex(*x) << endl);
111
112 ASSERT(out.has(*x), "Test of buffer content after assignment.");
113 }
114 }
115
116 for (set<double>::const_iterator x = rm.begin(); x != rm.end(); ++x) {
117
118 hash_collection::iterator p = buffer.find(*x);
119
120 DEBUG("find " << FIXED(5,2) << *x << " at position " << distance(buffer.begin(),p) << ' ' << buffer.getIndex(*x) << endl);
121
122 buffer.erase(p);
123 }
124
125 for (set<double>::const_iterator x = input.begin(); x != input.end(); ++x) {
126
127 ASSERT(buffer.has(*x) == (rm.count(*x) == 0), "Test of buffer content after erase.");
128 }
129
130 return 0;
131}
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Utility class to parse command line options.
Definition JParser.hh:1698
General purpose class for hash collection of unique elements.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448