Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JHashMap.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JHASHMAP__
2 #define __JTOOLS__JHASHMAP__
3 
4 #include <vector>
5 #include <utility>
6 #include <algorithm>
7 
8 #include "JLang/JNullType.hh"
9 #include "JLang/JTypeList.hh"
10 #include "JLang/JSinglePointer.hh"
11 #include "JLang/JEquals.hh"
13 #include "JLang/JException.hh"
15 #include "JTools/JHashEvaluator.hh"
16 #include "JTools/JRouter.hh"
17 #include "JTools/JTuple.hh"
18 #include "JTools/JPair.hh"
19 #include "JIO/JSerialisable.hh"
20 #include "JIO/JSTDIO.hh"
21 
22 
23 /**
24  * \file
25  *
26  * General purpose classes for (multidimensional) hash maps.
27  * \author mdejong
28  */
29 namespace JTOOLS {}
30 namespace JPP { using namespace JTOOLS; }
31 
32 namespace JTOOLS {
33 
34  using JLANG::JNullType;
35  using JLANG::JTypeList;
36  using JLANG::JTYPELIST;
37  using JLANG::JClass;
39  using JIO::JReader;
40  using JIO::JWriter;
41 
42 
43  /**
44  * General purpose class for hash map of (key, value) pairs.
45  *
46  * The elements in a hash map are sorted according to the specified evaluation.
47  * The evaluation of elements corresponds to a unary method returning an integer value for a given key;
48  * The default evaluator is JHashEvaluator.
49  *
50  * This class implements the JMappableCollection interface.
51  */
52  template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
53  struct JHashMap :
54  public std::vector< std::pair<JKey_t, JValue_t> >,
55  public JMappableCollection<JKey_t, JValue_t>
56  {
57  public:
58 
59  typedef JKey_t key_type;
60  typedef JValue_t mapped_type;
62  typedef JEvaluator_t evaluator_type;
63 
65 
66  typedef typename container_type::const_iterator const_iterator;
67  typedef typename container_type::const_reverse_iterator const_reverse_iterator;
68  typedef typename container_type::iterator iterator;
69  typedef typename container_type::reverse_iterator reverse_iterator;
70 
72 
74 
75 
76  /**
77  * Auxiliary class for ordering of objects in the collection by the hash value of their keys.
78  */
79  struct JComparator {
80 
81  /**
82  * Constructor.
83  *
84  * \param evaluator evaluator
85  */
86  JComparator(const JEvaluator_t& evaluator = JEvaluator_t()) :
87  getValue(evaluator)
88  {}
89 
90 
91  /**
92  * Comparison of elements.
93  *
94  * \param first first element
95  * \param second second element
96  * \return true if first element less than second element; else false
97  */
98  inline bool operator()(typename JClass<value_type>::argument_type first,
99  typename JClass<value_type>::argument_type second) const
100  {
101  return this->getValue(first.first) < this->getValue(second.first);
102  }
103 
104 
105  /**
106  * Comparison of element and key value.
107  *
108  * \param element element
109  * \param x key value
110  * \return true if element less than key value; else false
111  */
112  inline bool operator()(typename JClass<value_type>::argument_type element,
113  typename JClass<key_type>::argument_type x) const
114  {
115  return this->getValue(element.first) < this->getValue(x);
116  }
117 
118 
119  /**
120  * Function object for evaluation of key.
121  */
122  JEvaluator_t getValue;
123  };
124 
125 
126  /**
127  * Constructor.
128  *
129  * \param evaluator evaluator
130  */
131  JHashMap(const JEvaluator_t& evaluator = JEvaluator_t()) :
132  getValue(evaluator),
133  compare (evaluator),
134  router (-1) // default address
135  {}
136 
137 
138  /**
139  * Clear.
140  */
141  virtual void clear()
142  {
143  // reset internal router
144 
145  for (iterator i = this->begin(); i != this->end(); ++i) {
146  router.put(this->getValue(i->first), router.getDefaultAddress());
147  }
148 
149  container_type::clear();
150  }
151 
152 
153  /**
154  * Get mapped value.
155  *
156  * \param key key
157  * \return mapped value
158  */
159  virtual mapped_type& get(typename JClass<key_type>::argument_type key)
160  {
161  const int ival = this->getValue(key);
162 
163  if (!router.has(ival)) {
164  insert(value_type(key, mapped_type()));
165  }
166 
167  return container_type::operator[](router.get(ival)).second;
168  }
169 
170 
171  /**
172  * Get mapped value.
173  *
174  * This method will throw an exception if given key is not present following the prerequisite of constness.
175  *
176  * \param key key
177  * \return mapped value
178  */
179  const mapped_type& get(typename JClass<key_type>::argument_type key) const
180  {
181  const int ival = this->getValue(key);
182 
183  if (router.has(ival))
184  return container_type::operator[](router.get(ival)).second;
185  else
186  THROW(JIndexOutOfRange, "JHasMap::get(): invalid key.");
187  }
188 
189 
190  /**
191  * Insert element.
192  *
193  * \param element element
194  * \return (position, status), where status is true if inserted; else false
195  */
196  pair_type insert(const value_type& element)
197  {
198  using namespace std;
199 
200  const int ival = this->getValue(element.first);
201 
202  if (!router.has(ival)) {
203 
204  iterator i = container_type::insert(lower_bound(this->begin(), this->end(), element.first, compare), element);
205 
206  router.put(ival, distance(this->begin(), i));
207 
208  for (iterator __i = i; ++__i != this->end(); ) {
209  router.put(this->getValue(__i->first), distance(this->begin(), __i));
210  }
211 
212  return pair_type(i, true);
213 
214  } else {
215 
216  return pair_type(this->end(), false);
217  }
218  }
219 
220 
221  /**
222  * Erase element at given position.
223  *
224  * \param pos valid position
225  */
226  void erase(iterator pos)
227  {
228  this->router.put(this->getValue(*pos), this->router.getDefaultAddress());
229 
230  iterator i = pos;
231 
232  container_type::erase(i++);
233 
234  for ( ; i != this->end(); ++i) {
235  this->router.put(this->getValue(*i), distance(this->begin(), i));
236  }
237  }
238 
239 
240  /**
241  * Erase elements in given range.
242  *
243  * \param __begin begin position (included)
244  * \param __end end position (excluded)
245  */
246  void erase(iterator __begin, iterator __end)
247  {
248  iterator i = __begin;
249 
250  while (i != __end) {
251 
252  this->router.put(this->getValue(*i), this->router.getDefaultAddress());
253 
254  container_type::erase(i++);
255  }
256 
257  for ( ; i != this->end(); ++i) {
258  this->router.put(this->getValue(*i), distance(this->begin(), i));
259  }
260  }
261 
262 
263  /**
264  * Erase element.
265  *
266  * \param key key
267  * \return true if element with given key has been erased; else false
268  */
269  bool erase(typename JClass<key_type>::argument_type key) const
270  {
271  const int ival = this->getValue(key);
272 
273  if (router.has(ival)) {
274 
275  iterator pos = this->begin();
276 
277  std::advance(pos, this->router.get(ival));
278 
279  iterator i = container_type::erase(pos);
280 
281  for ( ; i != this->end(); ++i) {
282  this->router.put(this->getValue(*i), distance(this->begin(), i));
283  }
284 
285  return true;
286  }
287 
288  return false;
289  }
290 
291 
292  /**
293  * Test whether key is present.
294  *
295  * \param key key
296  * \return true if present; else false
297  */
298  bool has(typename JClass<key_type>::argument_type key) const
299  {
300  return router.has(this->getValue(key));
301  }
302 
303 
304  /**
305  * Get comparator.
306  *
307  * \return comparator
308  */
309  const JComparator& getComparator() const
310  {
311  return compare;
312  }
313 
314 
315  /**
316  * Read hash map from input.
317  *
318  * \param in reader
319  * \param object hash map
320  * \return reader
321  */
322  friend inline JReader& operator>>(JReader& in, JHashMap& object)
323  {
324  using namespace JIO;
325 
326  int n;
327 
328  in >> n;
329 
330  object.resize(n);
331 
332  for (value_type element; n != 0 && in >> element; --n) {
333  object.insert(element);
334  }
335 
336  return in;
337  }
338 
339 
340  /**
341  * Write hash map to output.
342  *
343  * \param out writer
344  * \param object hash map
345  * \return writer
346  */
347  friend inline JWriter& operator<<(JWriter& out, const JHashMap& object)
348  {
349  using namespace JIO;
350 
351  int n = object.size();
352 
353  out << n;
354 
355  for (typename JHashMap::const_iterator i = object.begin(); i != object.end(); ++i) {
356  out << *i;
357  }
358 
359  return out;
360  }
361 
362 
363  /**
364  * Function object for evaluation of key.
365  */
366  JEvaluator_t getValue;
367 
368 
369  protected:
370  /**
371  * Function object for comparison.
372  */
373  JComparator compare;
374 
376 
377  private:
378  void resize();
379  void push_back();
380  void pop_back();
381  };
382 
383 
384  /**
385  * Multi-dimensional hash map.
386  */
387  template<class JHead_t, class JTail_t, class JValue_t, class JEvaluator_t>
388  struct JHashMap<JTypeList<JHead_t, JTail_t>, JValue_t, JEvaluator_t> :
389  public JHashMap<JHead_t, JHashMap<JTail_t, JValue_t, JEvaluator_t>, JEvaluator_t>
390  {
391 
392  typedef JHead_t key_type;
395  typedef JEvaluator_t evaluator_type;
398 
401  typedef typename map_type::iterator iterator;
403 
404  using map_type::get;
405  using map_type::put;
406  using map_type::has;
407  using map_type::erase;
408 
409 
410  /**
411  * Constructor.
412  *
413  * \param evaluator evaluator
414  */
415  JHashMap(const JEvaluator_t& evaluator = JEvaluator_t()) :
416  JHashMap<JHead_t, JHashMap<JTail_t, JValue_t, JEvaluator_t>, JEvaluator_t>(evaluator)
417  {}
418 
419 
420  class super_const_iterator; // forward declaration
421 
422 
423  /**
424  * Multidimensional iterator.
425  */
426  class super_iterator :
427  public JLANG::JEquals <super_iterator>,
428  public JLANG::JForwardIterator<super_iterator>
429  {
430 
434 
435  friend class JHashMap;
436 
437  public:
438 
439  /**
440  * Default constructor.
441  */
443  {}
444 
445 
446  /**
447  * Smart pointer operator.
448  *
449  * \return pointer to pair of iterators
450  */
452  {
453  return pointer_type(new value_type(i->first, second));
454  }
455 
456 
457  /**
458  * Dereference operator.
459  *
460  * \return multidimensional pair
461  */
463  {
464  return reference_type(i->first, *second);
465  }
466 
467 
468  /**
469  * Equality of super iterator.
470  *
471  * \param cursor super iterator
472  * \return true if equal; else false
473  */
474  virtual bool equals(const super_iterator& cursor) const
475  {
476  return i == cursor.i && (i == range.second || second.equals(cursor.second));
477  }
478 
479 
480  /**
481  * Increment super_iterator.
482  *
483  * \return true if valid; else false
484  */
485  virtual bool increment()
486  {
487  if (!second.increment()) {
488 
489  while (++i != range.second) {
490 
491  second = i->second.super_begin();
492 
493  if (second != i->second.super_end()) {
494  break;
495  }
496  }
497  }
498 
499  return i != range.second;
500  }
501 
502 
503  /**
504  * Get multi-dimensional key.
505  *
506  * \return key
507  */
509  {
510  return multikey_type(i->first, second.getKey());
511  }
512 
513 
514  /**
515  * Get value.
516  *
517  * \return value
518  */
519  JValue_t& getValue()
520  {
521  return second.getValue();
522  }
523 
524 
525  private:
526  /**
527  * Constructor.
528  *
529  * \param __begin begin of data
530  * \param __end end of data
531  */
533  iterator __end) :
534  range(__begin, __end)
535  {
536  for (i = range.first; i != range.second; ++i) {
537 
538  second = i->second.super_begin();
539 
540  if (second != i->second.super_end()) {
541  break;
542  }
543  }
544  }
545 
546 
549  typename mapped_type::super_iterator second;
550  };
551 
552 
553  /**
554  * Multidimensional const_iterator.
555  */
556  class super_const_iterator :
557  public JLANG::JEquals <super_const_iterator>,
558  public JLANG::JForwardIterator<super_const_iterator>
559  {
560 
564 
565  friend class JHashMap;
566 
567  public:
568 
569  /**
570  * Default constructor.
571  */
573  {}
574 
575 
576  /**
577  * Copy constructor.
578  *
579  * \param cursor super_iterator
580  */
581  super_const_iterator(super_iterator cursor) :
582  range (cursor.range),
583  i (cursor.i),
584  second(cursor.second)
585  {}
586 
587 
588  /**
589  * Smart pointer operator.
590  *
591  * \return pointer to pair of iterators
592  */
594  {
595  return pointer_type(new value_type(i->first, second));
596  }
597 
598 
599  /**
600  * Dereference operator.
601  *
602  * \return multidimensional pair
603  */
605  {
606  return reference_type(i->first, *second);
607  }
608 
609 
610  /**
611  * Equality of super iterator.
612  *
613  * \param cursor super iterator
614  * \return true if equal; else false
615  */
616  virtual bool equals(const super_const_iterator& cursor) const
617  {
618  return i == cursor.i && (i == range.second || second.equals(cursor.second));
619  }
620 
621 
622  /**
623  * Increment super_iterator.
624  *
625  * \return true if valid; else false
626  */
627  virtual bool increment()
628  {
629  if (!second.increment()) {
630 
631  while (++i != range.second) {
632 
633  second = i->second.super_begin();
634 
635  if (second != i->second.super_end()) {
636  break;
637  }
638  }
639  }
640 
641  return i != range.second;
642  }
643 
644 
645  /**
646  * Get multi-dimensional key.
647  *
648  * \return key
649  */
651  {
652  return multikey_type(i->first, second.getKey());
653  }
654 
655 
656  /**
657  * Get value.
658  *
659  * \return value
660  */
661  const JValue_t& getValue()
662  {
663  return second.getValue();
664  }
665 
666 
667  private:
668  /**
669  * Constructor.
670  *
671  * \param __begin begin of data
672  * \param __end end of data
673  */
675  const_iterator __end) :
676  range(__begin, __end)
677  {
678  for (i = range.first; i != range.second; ++i) {
679 
680  second = i->second.super_begin();
681 
682  if (second != i->second.super_end()) {
683  break;
684  }
685  }
686  }
687 
688 
691  typename mapped_type::super_const_iterator second;
692  };
693 
694 
695  /**
696  * Get super_iterator to begin of data.
697  *
698  * \return super iterator
699  */
700  super_const_iterator super_begin() const
701  {
702  return super_const_iterator(this->begin(), this->end());
703  }
704 
705 
706  /**
707  * Get super_iterator to end of data.
708  *
709  * \return super iterator
710  */
711  super_const_iterator super_end() const
712  {
713  return super_const_iterator(this->end(), this->end());
714  }
715 
716 
717  /**
718  * Get super_iterator to begin of data.
719  *
720  * \return super iterator
721  */
722  super_iterator super_begin()
723  {
724  return super_iterator(this->begin(), this->end());
725  }
726 
727 
728  /**
729  * Get super_iterator to end of data.
730  *
731  * \return super iterator
732  */
733  super_iterator super_end()
734  {
735  return super_iterator(this->end(), this->end());
736  }
737 
738 
739  /**
740  * Get mapped value.
741  *
742  * \param key key
743  * \return value
744  */
745  JValue_t& get(const multikey_type& key)
746  {
747  this->get(key.first).get(key.second);
748  }
749 
750 
751  /**
752  * Get mapped value.
753  *
754  * This method will throw an exception if given key is not present following the prerequisite of constness.
755  *
756  * \param key key
757  * \return value
758  */
759  const JValue_t& get(const multikey_type& key) const
760  {
761  this->get(key.first).get(key.second);
762  }
763 
764 
765  /**
766  * Put tuple-wise element (key,value) into collection.
767  *
768  * \param key key
769  * \param value value
770  */
771  void put(const multikey_type& key, const JValue_t& value)
772  {
773  this->get(key.first).put(key.second, value);
774  }
775 
776 
777  /**
778  * Erase element.
779  *
780  * \param key key
781  * \return true if element with given key has been erased; else false
782  */
783  bool erase(const multikey_type& key)
784  {
785  if (this->has(key.first))
786  return this->get(key.first).erase(key.second);
787  else
788  return false;
789  }
790 
791 
792  /**
793  * Test whether key is present.
794  *
795  * \param key key
796  * \return true if present; else false
797  */
798  bool has(const multikey_type& key) const
799  {
800  return map_type::has(key.first) && this->get(key.first).has(key.second);
801  }
802  };
803 
804 
805  /**
806  * Terminator class of recursive class JHashMap.
807  */
808  template<class JHead_t, class JValue_t, class JEvaluator_t>
809  struct JHashMap<JTypeList<JHead_t, JNullType>, JValue_t, JEvaluator_t> :
810  public JHashMap<JHead_t, JValue_t, JEvaluator_t>
811  {
812 
813  typedef JHead_t key_type;
814  typedef JValue_t mapped_type;
816  typedef JEvaluator_t evaluator_type;
817  typedef JHead_t multikey_type;
819 
822  typedef typename map_type::iterator iterator;
824 
825 
826  /**
827  * Constructor.
828  *
829  * \param evaluator evaluator
830  */
831  JHashMap(const JEvaluator_t& evaluator = JEvaluator_t()) :
832  JHashMap<JHead_t, JValue_t, JEvaluator_t>(evaluator)
833  {}
834 
835 
836  class super_const_iterator; // forward declaration
837 
838 
839  /**
840  * Terminator class of multidimensional iterator.
841  */
842  class super_iterator :
843  public JLANG::JEquals <super_iterator>,
844  public JLANG::JForwardIterator<super_iterator>
845  {
846 
850 
851  friend class JHashMap;
852 
853  public:
854 
855  /**
856  * Default constructor.
857  */
859  {}
860 
861 
862  /**
863  * Smart pointer operator.
864  *
865  * \return pointer to pair of iterators
866  */
868  {
869  return pointer_type(new value_type(i->first, i->second));
870  }
871 
872 
873  /**
874  * Dereference operator.
875  *
876  * \return multidimensional pair
877  */
879  {
880  return reference_type(i->first, i->second);
881  }
882 
883 
884  /**
885  * Equality of super iterator.
886  *
887  * \param cursor super iterator
888  * \return true if equal; else false
889  */
890  virtual bool equals(const super_iterator& cursor) const
891  {
892  return i == cursor.i;
893  }
894 
895 
896  /**
897  * Increment super_iterator.
898  *
899  * \return true if valid; else false
900  */
901  virtual bool increment()
902  {
903  return ++i != range.second;
904  }
905 
906 
907  /**
908  * Get multi-dimensional key.
909  *
910  * \return key
911  */
913  {
914  return multikey_type(i->first);
915  }
916 
917 
918  /**
919  * Get value.
920  *
921  * \return value
922  */
923  JValue_t& getValue()
924  {
925  return i->second;
926  }
927 
928  private:
929  /**
930  * Constructor.
931  *
932  * \param __begin begin of data
933  * \param __end end of data
934  */
936  iterator __end) :
937  range(__begin, __end),
938  i (__begin)
939  {}
940 
941 
944  };
945 
946 
947  /**
948  * Terminator class of multidimensional const_iterator.
949  */
950  class super_const_iterator :
951  public JLANG::JEquals <super_const_iterator>,
952  public JLANG::JForwardIterator<super_const_iterator>
953  {
954 
958 
959  friend class JHashMap;
960 
961  public:
962 
963  /**
964  * Default constructor.
965  */
967  {}
968 
969 
970  /**
971  * Copy constructor.
972  *
973  * \param cursor super_iterator
974  */
975  super_const_iterator(super_iterator cursor) :
976  range(cursor.range),
977  i (cursor.i)
978  {}
979 
980 
981  /**
982  * Smart pointer operator.
983  *
984  * \return pointer to pair of iterators
985  */
987  {
988  return pointer_type(new value_type(i->first, i->second));
989  }
990 
991 
992  /**
993  * Dereference operator.
994  *
995  * \return multidimensional pair
996  */
998  {
999  return reference_type(i->first, i->second);
1000  }
1001 
1002 
1003  /**
1004  * Equality of super iterator.
1005  *
1006  * \param cursor super iterator
1007  * \return true if equal; else false
1008  */
1009  virtual bool equals(const super_const_iterator& cursor) const
1010  {
1011  return i == cursor.i;
1012  }
1013 
1014 
1015  /**
1016  * Increment super_iterator.
1017  *
1018  * \return true if valid; else false
1019  */
1020  virtual bool increment()
1021  {
1022  return ++i != range.second;
1023  }
1024 
1025 
1026  /**
1027  * Get multi-dimensional key.
1028  *
1029  * \return key
1030  */
1032  {
1033  return multikey_type(i->first);
1034  }
1035 
1036 
1037  /**
1038  * Get value.
1039  *
1040  * \return value
1041  */
1042  const JValue_t& getValue()
1043  {
1044  return i->second;
1045  }
1046 
1047  private:
1048  /**
1049  * Constructor.
1050  *
1051  * \param __begin begin of data
1052  * \param __end end of data
1053  */
1055  const_iterator __end) :
1056  range(__begin, __end),
1057  i (__begin)
1058  {}
1059 
1060 
1063  };
1064 
1065 
1066  /**
1067  * Get super_iterator to begin of data.
1068  *
1069  * \return super_iterator
1070  */
1071  super_const_iterator super_begin() const
1072  {
1073  return super_const_iterator(this->begin(), this->end());
1074  }
1075 
1076 
1077  /**
1078  * Get super_iterator to end of data.
1079  *
1080  * \return super_iterator
1081  */
1082  super_const_iterator super_end() const
1083  {
1084  return super_const_iterator(this->end(), this->end());
1085  }
1086 
1087 
1088  /**
1089  * Get super_iterator to begin of data.
1090  *
1091  * \return super_iterator
1092  */
1093  super_iterator super_begin()
1094  {
1095  return super_iterator(this->begin(), this->end());
1096  }
1097 
1098 
1099  /**
1100  * Get super_iterator to end of data.
1101  *
1102  * \return super_iterator
1103  */
1104  super_iterator super_end()
1105  {
1106  return super_iterator(this->end(), this->end());
1107  }
1108  };
1109 }
1110 
1111 #endif
1112 
void erase(iterator pos)
Erase element at given position.
Definition: JHashMap.hh:226
JKey_t key_type
Definition: JHashMap.hh:59
virtual bool equals(const super_iterator &cursor) const
Equality of super iterator.
Definition: JHashMap.hh:474
bool operator()(typename JClass< value_type >::argument_type first, typename JClass< value_type >::argument_type second) const
Comparison of elements.
Definition: JHashMap.hh:98
Template interface for method bool increment().
Template data structure.
Definition: JTuple.hh:45
Exceptions.
Interface for binary output.
bool has(typename JClass< key_type >::argument_type key) const
Test whether key is present.
Definition: JHashMap.hh:298
bool has(const multikey_type &key) const
Test whether key is present.
Definition: JHashMap.hh:798
container_type::const_reverse_iterator const_reverse_iterator
Definition: JHashMap.hh:67
General purpose class for hash map of (key, value) pairs.
Definition: JHashMap.hh:53
const JComparator & getComparator() const
Get comparator.
Definition: JHashMap.hh:309
JValue_t mapped_type
Definition: JHashMap.hh:60
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
Template interface definition for associative collection of elements.
std::vector< value_type > container_type
Definition: JHashMap.hh:64
virtual bool equals(const super_iterator &cursor) const
Equality of super iterator.
Definition: JHashMap.hh:890
JHashMap(const JEvaluator_t &evaluator=JEvaluator_t())
Constructor.
Definition: JHashMap.hh:831
JHashMap< key_type, mapped_type, evaluator_type > map_type
Definition: JHashMap.hh:397
JEvaluator_t getValue
Function object for evaluation of key.
Definition: JHashMap.hh:122
JHashMap< key_type, mapped_type, evaluator_type > map_type
Definition: JHashMap.hh:818
super_const_iterator(const_iterator __begin, const_iterator __end)
Constructor.
Definition: JHashMap.hh:1054
JRouter< int > router
Definition: JHashMap.hh:375
super_const_iterator(const_iterator __begin, const_iterator __end)
Constructor.
Definition: JHashMap.hh:674
Type list.
Definition: JTypeList.hh:22
The template JSinglePointer class can be used to hold a pointer to an object.
JEvaluator_t evaluator_type
Definition: JHashMap.hh:62
Template specialisation for a pair of values.
Definition: JPair.hh:28
JArgument< T >::argument_type argument_type
Definition: JClass.hh:64
T get(const JHead &head)
Get object from header.
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:377
friend JReader & operator>>(JReader &in, JHashMap &object)
Read hash map from input.
Definition: JHashMap.hh:322
Template specialisation of JTuple for multiple data types.
Definition: JTuple.hh:222
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
Auxiliary class for no type definition.
Definition: JNullType.hh:19
super_const_iterator super_end() const
Get super_iterator to end of data.
Definition: JHashMap.hh:711
void put(typename JClass< key_type >::argument_type key, typename JClass< mapped_type >::argument_type value)
Put pair-wise element (key,value) into collection.
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.
Definition: JCounter.hh:35
super_const_iterator super_begin() const
Get super_iterator to begin of data.
Definition: JHashMap.hh:700
JEvaluator_t getValue
Function object for evaluation of key.
Definition: JHashMap.hh:366
super_iterator super_end()
Get super_iterator to end of data.
Definition: JHashMap.hh:733
void erase(iterator __begin, iterator __end)
Erase elements in given range.
Definition: JHashMap.hh:246
Template for generic class types.
Definition: JClass.hh:62
JComparator(const JEvaluator_t &evaluator=JEvaluator_t())
Constructor.
Definition: JHashMap.hh:86
virtual void clear()
Clear.
Definition: JHashMap.hh:141
JPair< const key_type &, typename mapped_type::super_iterator & > value_type
Definition: JHashMap.hh:431
Auxiliary class for ordering of objects in the collection by the hash value of their keys...
Definition: JHashMap.hh:79
super_iterator super_end()
Get super_iterator to end of data.
Definition: JHashMap.hh:1104
Data structure based on type list.
JHashMap(const JEvaluator_t &evaluator=JEvaluator_t())
Constructor.
Definition: JHashMap.hh:131
super_iterator super_begin()
Get super_iterator to begin of data.
Definition: JHashMap.hh:1093
bool operator()(typename JClass< value_type >::argument_type element, typename JClass< key_type >::argument_type x) const
Comparison of element and key value.
Definition: JHashMap.hh:112
JPair< const key_type &, typename mapped_type::super_const_iterator & > value_type
Definition: JHashMap.hh:561
super_const_iterator super_end() const
Get super_iterator to end of data.
Definition: JHashMap.hh:1082
bool erase(typename JClass< key_type >::argument_type key) const
Erase element.
Definition: JHashMap.hh:269
friend JWriter & operator<<(JWriter &out, const JHashMap &object)
Write hash map to output.
Definition: JHashMap.hh:347
container_type::const_iterator const_iterator
Definition: JHashMap.hh:66
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
virtual bool equals(const super_const_iterator &cursor) const
Equality of super iterator.
Definition: JHashMap.hh:1009
virtual bool equals(const super_const_iterator &cursor) const
Equality of super iterator.
Definition: JHashMap.hh:616
super_const_iterator super_begin() const
Get super_iterator to begin of data.
Definition: JHashMap.hh:1071
container_type::reverse_iterator reverse_iterator
Definition: JHashMap.hh:69
super_iterator super_begin()
Get super_iterator to begin of data.
Definition: JHashMap.hh:722
std::pair< JKey_t, JValue_t > value_type
Definition: JHashMap.hh:61
JComparator compare
Function object for comparison.
Definition: JHashMap.hh:373
std::pair< const_iterator, bool > pair_type
Definition: JHashMap.hh:71
void put(const multikey_type &key, const JValue_t &value)
Put tuple-wise element (key,value) into collection.
Definition: JHashMap.hh:771
pair_type insert(const value_type &element)
Insert element.
Definition: JHashMap.hh:196
STD extensions for binary I/O.
JHashMap(const JEvaluator_t &evaluator=JEvaluator_t())
Constructor.
Definition: JHashMap.hh:415
container_type::iterator iterator
Definition: JHashMap.hh:68