Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Protected Attributes | List of all members
JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t > Struct Template Reference

General purpose class for hash map of unique keys. More...

#include <JHashMap.hh>

Inheritance diagram for JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >:
JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t >, JHashMapEvaluator< JEvaluator_t > > JTOOLS::JMappableCollection< JKey_t, JValue_t > std::vector< std::pair< JKey_t, JValue_t > > JACOUSTICS::JGeometry::JDetector JACOUSTICS::JGeometry::JString JACOUSTICS::JModel::emitter_map JACOUSTICS::JModel::string_map JDETECTOR::JPMTDefaultSimulator JTRIGGER::JPMTRunByRunSimulator

Public Types

typedef JKey_t key_type
 
typedef JValue_t mapped_type
 
typedef std::pair< JKey_t,
JValue_t > 
value_type
 
typedef JHashMapEvaluator
< JEvaluator_t > 
evaluator_type
 
typedef JHashCollection
< value_type, evaluator_type
collection_type
 
typedef
collection_type::container_type 
container_type
 
typedef
container_type::const_iterator 
const_iterator
 
typedef
container_type::const_reverse_iterator 
const_reverse_iterator
 
typedef container_type::iterator iterator
 
typedef
container_type::reverse_iterator 
reverse_iterator
 

Public Member Functions

 JHashMap (const JEvaluator_t &evaluator=JEvaluator_t())
 Constructor. More...
 
virtual void clear ()
 Clear. More...
 
virtual mapped_typeget (typename JClass< key_type >::argument_type key)
 Get mapped value. More...
 
virtual const mapped_typeget (typename JClass< key_type >::argument_type key) const
 Get mapped value. More...
 
const_iterator find (const T &value) const
 Find element with given value. More...
 
iterator find (const T &value)
 Find element with given value. More...
 
value_typeget (const T &value)
 Get element with given value. More...
 
const value_typeget (const T &value) const
 Get element with given value. More...
 
virtual bool insert (const value_type &element)
 Insert element. More...
 
void erase (iterator pos)
 Erase element at given position. More...
 
void erase (iterator __begin, iterator __end)
 Erase elements in given range. More...
 
bool erase (const T &value)
 Erase element with given value. More...
 
bool has (const T &value) const
 Test whether given value is present. More...
 
int getIndex (const T &value) const
 Get index of given value. More...
 
const mapped_typeoperator[] (typename JClass< key_type >::argument_type key) const
 Get mapped value. More...
 
mapped_typeoperator[] (typename JClass< key_type >::argument_type key)
 Get mapped value. More...
 
void put (typename JClass< key_type >::argument_type key, typename JClass< mapped_type >::argument_type value)
 Put pair-wise element (key,value) into collection. More...
 

Public Attributes

JHashMapEvaluator< JEvaluator_t > getValue
 Function object for evaluation of element. More...
 

Protected Attributes

JRouter< int > router
 

Detailed Description

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
struct JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >

General purpose class for hash map of unique keys.

The keys in a hash collection are unique according to the specified evaluation. The evaluation of keys corresponds to a unary method returning an integer value for a given key; The default evaluator is JHashEvaluator.

This class implements the JMappableCollection interface.

Definition at line 71 of file JHashMap.hh.

Member Typedef Documentation

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef JKey_t JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::key_type

Definition at line 77 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef JValue_t JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::mapped_type

Definition at line 78 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef std::pair<JKey_t, JValue_t> JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::value_type

Definition at line 79 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef JHashMapEvaluator<JEvaluator_t> JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::evaluator_type

Definition at line 80 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef JHashCollection<value_type, evaluator_type> JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::collection_type

Definition at line 82 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef collection_type::container_type JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::container_type

Definition at line 83 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef container_type::const_iterator JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::const_iterator

Definition at line 85 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef container_type::const_reverse_iterator JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::const_reverse_iterator

Definition at line 86 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef container_type::iterator JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::iterator

Definition at line 87 of file JHashMap.hh.

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
typedef container_type::reverse_iterator JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::reverse_iterator

Definition at line 88 of file JHashMap.hh.

Constructor & Destructor Documentation

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::JHashMap ( const JEvaluator_t &  evaluator = JEvaluator_t())
inline

Constructor.

Parameters
evaluatorevaluator

Definition at line 98 of file JHashMap.hh.

98  :
99  collection_type(evaluator)
100  {}
JHashCollection< value_type, evaluator_type > collection_type
Definition: JHashMap.hh:82

Member Function Documentation

template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
virtual void JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::clear ( )
inlinevirtual

Clear.

Implements JTOOLS::JMappableCollection< JKey_t, JValue_t >.

Definition at line 106 of file JHashMap.hh.

107  {
109  }
template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
virtual mapped_type& JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::get ( typename JClass< key_type >::argument_type  key)
inlinevirtual

Get mapped value.

Parameters
keykey
Returns
mapped value

Implements JTOOLS::JMappableCollection< JKey_t, JValue_t >.

Definition at line 118 of file JHashMap.hh.

119  {
120  const int ival = this->getValue(key);
121 
122  if (!this->router.has(ival)) {
124  }
125 
126  return container_type::operator[](this->router.get(ival)).second;
127  }
JValue_t mapped_type
Definition: JHashMap.hh:78
virtual bool insert(const value_type &element)
Insert element.
std::pair< JKey_t, JValue_t > value_type
Definition: JHashMap.hh:79
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
template<class JKey_t, class JValue_t, class JEvaluator_t = JHashEvaluator>
virtual const mapped_type& JTOOLS::JHashMap< JKey_t, JValue_t, JEvaluator_t >::get ( typename JClass< key_type >::argument_type  key) const
inlinevirtual

Get mapped value.

This method will throw an exception if given key is not present following the prerequisite of constness.

Parameters
keykey
Returns
mapped value

Implements JTOOLS::JMappableCollection< JKey_t, JValue_t >.

Definition at line 138 of file JHashMap.hh.

139  {
140  const int ival = this->getValue(key);
141 
142  if (this->router.has(ival))
143  return container_type::operator[](this->router.get(ival)).second;
144  else
145  THROW(JIndexOutOfRange, "JHasMap::get(): invalid key.");
146  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
const_iterator JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::find ( const T value) const
inlineinherited

Find element with given value.

Parameters
valuevalue
Returns
position of element with given value or end()

Definition at line 102 of file JHashCollection.hh.

103  {
104  const int ival = this->getValue(value);
105 
106  if (router.has(ival))
107  return this->begin() + router.get(ival);
108  else
109  return this->end();
110  }
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
iterator JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::find ( const T value)
inlineinherited

Find element with given value.

Parameters
valuevalue
Returns
position of element with given value or end()

Definition at line 120 of file JHashCollection.hh.

121  {
122  const int ival = this->getValue(value);
123 
124  if (router.has(ival))
125  return this->begin() + router.get(ival);
126  else
127  return this->end();
128  }
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
value_type& JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::get ( const T value)
inlineinherited

Get element with given value.

This method will throw an exception if given value is not present following the prerequisite of constness.

Parameters
valuevalue
Returns
element

Definition at line 140 of file JHashCollection.hh.

141  {
142  const int ival = this->getValue(value);
143 
144  if (!router.has(ival)) {
145  this->insert(value);
146  }
147 
148  return container_type::operator[](router.get(ival)).second;
149  }
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
const value_type& JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::get ( const T value) const
inlineinherited

Get element with given value.

This method will throw an exception if given value is not present following the prerequisite of constness.

Parameters
valuevalue
Returns
element

Definition at line 161 of file JHashCollection.hh.

162  {
163  const int ival = this->getValue(value);
164 
165  if (router.has(ival)) {
166  return container_type::operator[](router.get(ival)).second;
167  }
168 
169  THROW(JIndexOutOfRange, "JHasCollection::get(): invalid value.");
170  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
virtual bool JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::insert ( const value_type element)
inlinevirtualinherited

Insert element.

Parameters
elementelement
Returns
true if inserted; else false

Definition at line 179 of file JHashCollection.hh.

180  {
181  const int ival = this->getValue(element);
182 
183  if (!router.has(ival)) {
184 
185  container_type::push_back(element);
186 
187  router.put(ival, this->size() - 1);
188 
189  return true;
190  }
191 
192  return false;
193  }
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
void JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::erase ( iterator  pos)
inlineinherited

Erase element at given position.

Parameters
posvalid position

Definition at line 201 of file JHashCollection.hh.

202  {
203  router.put(this->getValue(*pos), router.getDefaultAddress());
204 
205  for (iterator i = container_type::erase(pos); i != this->end(); ++i) {
206  router.put(this->getValue(*i), distance(this->begin(), i));
207  }
208  }
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
void JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::erase ( iterator  __begin,
iterator  __end 
)
inlineinherited

Erase elements in given range.

Parameters
__beginbegin position (included)
__endend position (excluded)

Definition at line 217 of file JHashCollection.hh.

218  {
219  for (iterator i = __begin; i != __end; ++i) {
220  router.put(this->getValue(*i), router.getDefaultAddress());
221  }
222 
223  for (iterator i = container_type::erase(__begin, __end); i != this->end(); ++i) {
224  router.put(this->getValue(*i), distance(this->begin(), i));
225  }
226  }
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
bool JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::erase ( const T value)
inlineinherited

Erase element with given value.

Parameters
valuevalue
Returns
true if element has been erased; else false

Definition at line 236 of file JHashCollection.hh.

237  {
238  const int ival = this->getValue(value);
239 
240  if (router.has(ival)) {
241 
242  this->erase(this->begin() + router.get(ival));
243 
244  return true;
245  }
246 
247  return false;
248  }
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
bool JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::has ( const T value) const
inlineinherited

Test whether given value is present.

Parameters
valuevalue
Returns
true if present; else false

Definition at line 258 of file JHashCollection.hh.

259  {
260  return router.has(this->getValue(value));
261  }
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
int JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::getIndex ( const T value) const
inlineinherited

Get index of given value.

Parameters
valuevalue
Returns
indecx

Definition at line 271 of file JHashCollection.hh.

272  {
273  return router.get(this->getValue(value));
274  }
JHashMapEvaluator< JEvaluator_t > getValue
Function object for evaluation of element.
template<class JKey_t, class JValue_t>
const mapped_type& JTOOLS::JMappableCollection< JKey_t, JValue_t >::operator[] ( typename JClass< key_type >::argument_type  key) const
inlineinherited

Get mapped value.

Parameters
keykey
Returns
value

Definition at line 73 of file JMappableCollection.hh.

74  {
75  return get(key);
76  }
template<class JKey_t, class JValue_t>
mapped_type& JTOOLS::JMappableCollection< JKey_t, JValue_t >::operator[] ( typename JClass< key_type >::argument_type  key)
inlineinherited

Get mapped value.

Parameters
keykey
Returns
value

Definition at line 85 of file JMappableCollection.hh.

86  {
87  return get(key);
88  }
template<class JKey_t, class JValue_t>
void JTOOLS::JMappableCollection< JKey_t, JValue_t >::put ( typename JClass< key_type >::argument_type  key,
typename JClass< mapped_type >::argument_type  value 
)
inlineinherited

Put pair-wise element (key,value) into collection.

Parameters
keykey
valuevalue

Definition at line 97 of file JMappableCollection.hh.

99  {
100  get(key) = value;
101  }

Member Data Documentation

JHashMapEvaluator< JEvaluator_t > JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::getValue
inherited

Function object for evaluation of element.

Definition at line 280 of file JHashCollection.hh.

JRouter<int> JTOOLS::JHashCollection< std::pair< JKey_t, JValue_t > , JHashMapEvaluator< JEvaluator_t > >::router
protectedinherited

Definition at line 284 of file JHashCollection.hh.


The documentation for this struct was generated from the following file: