1 #ifndef __JTOOLS__JHASHMAP__
2 #define __JTOOLS__JHASHMAP__
30 namespace JPP {
using namespace JTOOLS; }
52 template<
class JKey_t,
class JValue_t,
class JEvaluator_t = JHashEvaluator>
68 typedef typename container_type::iterator
iterator;
131 JHashMap(
const JEvaluator_t& evaluator = JEvaluator_t()) :
145 for (
iterator i = this->begin(); i != this->end(); ++i) {
149 container_type::clear();
161 const int ival = this->
getValue(key);
167 return container_type::operator[](
router.get(ival)).second;
181 const int ival = this->
getValue(key);
184 return container_type::operator[](
router.get(ival)).second;
200 const int ival = this->
getValue(element.first);
204 iterator i = container_type::insert(lower_bound(this->begin(), this->end(), element.first,
compare), element);
206 router.put(ival, distance(this->begin(), i));
208 for (
iterator __i = i; ++__i != this->end(); ) {
209 router.put(this->
getValue(__i->first), distance(this->begin(), __i));
232 container_type::erase(i++);
234 for ( ; i != this->end(); ++i) {
254 container_type::erase(i++);
257 for ( ; i != this->end(); ++i) {
271 const int ival = this->
getValue(key);
279 iterator i = container_type::erase(pos);
281 for ( ; i != this->end(); ++i) {
332 for (
value_type element; n != 0 && in >> element; --n) {
333 object.insert(element);
351 int n =
object.size();
387 template<
class JHead_t,
class JTail_t,
class JValue_t,
class JEvaluator_t>
389 public JHashMap<JHead_t, JHashMap<JTail_t, JValue_t, JEvaluator_t>, JEvaluator_t>
407 using map_type::erase;
415 JHashMap(
const JEvaluator_t& evaluator = JEvaluator_t()) :
416 JHashMap<JHead_t,
JHashMap<JTail_t, JValue_t, JEvaluator_t>, JEvaluator_t>(evaluator)
420 class super_const_iterator;
426 class super_iterator :
474 virtual bool equals(
const super_iterator& cursor)
const
476 return i == cursor.i && (i == range.second || second.equals(cursor.second));
487 if (!second.increment()) {
489 while (++i != range.second) {
491 second = i->second.super_begin();
493 if (second != i->second.super_end()) {
499 return i != range.second;
521 return second.getValue();
534 range(__begin, __end)
536 for (i = range.first; i != range.second; ++i) {
538 second = i->second.super_begin();
540 if (second != i->second.super_end()) {
549 typename mapped_type::super_iterator
second;
556 class super_const_iterator :
582 range (cursor.range),
584 second(cursor.second)
616 virtual bool equals(
const super_const_iterator& cursor)
const
618 return i == cursor.i && (i == range.second || second.equals(cursor.second));
629 if (!second.increment()) {
631 while (++i != range.second) {
633 second = i->second.super_begin();
635 if (second != i->second.super_end()) {
641 return i != range.second;
663 return second.getValue();
676 range(__begin, __end)
678 for (i = range.first; i != range.second; ++i) {
680 second = i->second.super_begin();
682 if (second != i->second.super_end()) {
691 typename mapped_type::super_const_iterator
second;
702 return super_const_iterator(this->begin(), this->end());
713 return super_const_iterator(this->end(), this->end());
724 return super_iterator(this->begin(), this->end());
735 return super_iterator(this->end(), this->end());
747 this->
get(key.first).
get(key.second);
761 this->
get(key.first).
get(key.second);
808 template<
class JHead_t,
class JValue_t,
class JEvaluator_t>
810 public JHashMap<JHead_t, JValue_t, JEvaluator_t>
831 JHashMap(
const JEvaluator_t& evaluator = JEvaluator_t()) :
832 JHashMap<JHead_t, JValue_t, JEvaluator_t>(evaluator)
836 class super_const_iterator;
842 class super_iterator :
890 virtual bool equals(
const super_iterator& cursor)
const
892 return i == cursor.i;
903 return ++i != range.second;
937 range(__begin, __end),
950 class super_const_iterator :
1009 virtual bool equals(
const super_const_iterator& cursor)
const
1011 return i == cursor.i;
1022 return ++i != range.second;
1056 range(__begin, __end),
1073 return super_const_iterator(this->begin(), this->end());
1084 return super_const_iterator(this->end(), this->end());
1095 return super_iterator(this->begin(), this->end());
1106 return super_iterator(this->end(), this->end());
Template interface for method bool increment().
Interface for binary output.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
The template JSinglePointer class can be used to hold a pointer to an object.
JArgument< T >::argument_type argument_type
T get(const JHead &head)
Get object from header.
Auxiliary class for recursive type list generation.
Template definition of auxiliary base class for comparison of data structures.
Auxiliary class for no type definition.
Interface for binary input.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Template for generic class types.
Data structure based on type list.
Exception for accessing an index in a collection that is outside of its range.
STD extensions for binary I/O.