#include #include #include #include "JTools/JHashSet.hh" #include "JLang/JObjectID.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; struct __A__ : public JObjectID { /** * Default constructor. */ __A__() : JObjectID() {} /** * Constructor. * * \param id identifier */ __A__(const int id) : JObjectID(id) {} /** * Get hash value. * * \param key key * \return hash value */ inline int getKey() const { return getID(); } }; } /** * \file * * Example program to test JTOOLS::JHashSet class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; int debug; try { JParser<> zap("Example program to test hash set."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; typedef JHashSet<__A__> hash_set; hash_set buffer; for (int i = 1<<10; i != 0; i >>= 1) { buffer.insert(__A__(i)); } buffer.erase(buffer.find(1<<2), buffer.find(1<<4)); if (!buffer.erase(1<<4)) { FATAL("Erasing value failed." << endl); } for (hash_set::const_iterator i = buffer.begin(); i != buffer.end(); ++i) { cout << setw(4) << *i; cout << " == "; hash_set::const_iterator p = buffer.find(*i); if (p != buffer.end()) cout << setw(4) << *p << endl; else FATAL("Inconsistent has set at " << *i << endl); } return 0; }