33 #ifndef MOOT_ASSOC_VECTOR_H 34 #define MOOT_ASSOC_VECTOR_H 44 template<
typename KeyT,
typename ValT>
46 :
public std::pair<KeyT,ValT>
52 typedef std::pair<KeyT,ValT>
PairT;
83 : PairT(x.first,x.second)
93 inline key_type &
key (
void) {
return this->first; };
94 inline const key_type &
key (
void)
const {
return this->first; };
96 inline value_type &
value (
void) {
return this->second; };
97 inline const value_type &
value (
void)
const {
return this->second; };
105 return (this->first < x.first
107 : (this->first > x.first
109 : this->second < x.second));
129 template<
typename KeyT,
typename ValT>
130 class AssocVector :
public std::vector<AssocVectorNode<KeyT,ValT> >
140 typedef typename assoc_vector_type::iterator
iterator;
152 inline bool operator()(
const assoc_node_type &x,
const assoc_node_type &y)
const 154 return (x.second < y.second
156 : (x.second > y.second
158 : x.first < y.first));
176 : assoc_vector_type()
182 this->reserve(mysize);
197 for (i = this->begin(); i != this->end() && i->first !=
key; i++) ;
203 inline const_iterator
find(
const KeyT &
key)
const 206 for (i = this->begin(); i != this->end() && i->first !=
key; i++) ;
212 inline iterator
get(
const KeyT &
key)
214 iterator i = find(
key);
215 return (i == this->end() ? assoc_vector_type::insert(i,
key) : i);
223 inline iterator
insert(
const KeyT &
key,
const ValT &val)
225 iterator i =
get(
key);
239 {
return *(
get(
key)); };
243 {
return get_node(key).second; };
246 inline assoc_node_type &
nth(
const size_t n)
247 {
return assoc_vector_type::operator[](n); };
255 {
return get_node(key).second; };
259 {
return find(key)->second; };
267 { std::sort(this->begin(),this->end()); };
271 { std::sort(this->rbegin(),this->rend()); };
286 #endif // MOOT_ASSOC_VECTOR_H iterator find(const KeyT &key)
Definition: mootAssocVector.h:194
Definition: mootAssocVector.h:39
void rsort_byvalue(void)
Definition: mootAssocVector.h:278
assoc_vector_type::const_iterator const_iterator
Definition: mootAssocVector.h:141
Definition: mootAssocVector.h:151
assoc_vector_type::reverse_iterator reverse_iterator
Definition: mootAssocVector.h:143
AssocVector(const size_t mysize)
Definition: mootAssocVector.h:180
bool operator<(const ThisT &x) const
Definition: mootAssocVector.h:103
AssocVector(void)
Definition: mootAssocVector.h:175
AssocVectorNode< KeyT, ValT > assoc_node_type
Definition: mootAssocVector.h:137
assoc_value_type & operator[](const KeyT &key)
Definition: mootAssocVector.h:254
assoc_node_type & get_node(const KeyT &key)
Definition: mootAssocVector.h:238
ValT assoc_value_type
Definition: mootAssocVector.h:136
iterator insert(const KeyT &key, const ValT &val)
Definition: mootAssocVector.h:223
AssocVectorNode(const KeyT &key, const ValT &val)
Definition: mootAssocVector.h:77
assoc_vector_type::const_reverse_iterator const_reverse_iterator
Definition: mootAssocVector.h:144
LISP-style assoc list using vector<>: map-like class with small memory footprint. Useful for small as...
Definition: mootAssocVector.h:130
void sort_bykey(void)
Definition: mootAssocVector.h:266
assoc_node_type & nth(const size_t n)
Definition: mootAssocVector.h:246
KeyT assoc_key_type
Definition: mootAssocVector.h:135
void rsort_bykey(void)
Definition: mootAssocVector.h:270
void sort_byvalue(void)
Definition: mootAssocVector.h:274
ValT value_type
Definition: mootAssocVector.h:51
AssocVectorNode(const KeyT &key)
Definition: mootAssocVector.h:72
const value_type & value(void) const
Definition: mootAssocVector.h:97
key_type & key(void)
Definition: mootAssocVector.h:93
const assoc_value_type & operator[](const KeyT &key) const
Definition: mootAssocVector.h:258
AssocVectorNode< KeyT, ValT > ThisT
Definition: mootAssocVector.h:53
AssocVectorNode(const ThisT &x)
Definition: mootAssocVector.h:82
std::vector< assoc_node_type > assoc_vector_type
Definition: mootAssocVector.h:138
std::pair< KeyT, ValT > PairT
Definition: mootAssocVector.h:52
~AssocVectorNode(void)
Definition: mootAssocVector.h:87
KeyT key_type
Definition: mootAssocVector.h:50
assoc_value_type & get_value(const KeyT &key)
Definition: mootAssocVector.h:242
assoc_vector_type::iterator iterator
Definition: mootAssocVector.h:140
AssocVectorNode(void)
Definition: mootAssocVector.h:67
template class for individual AssocVector nodes
Definition: mootAssocVector.h:45
const_iterator find(const KeyT &key) const
Definition: mootAssocVector.h:203
~AssocVector(void)
Definition: mootAssocVector.h:186
value_type & value(void)
Definition: mootAssocVector.h:96
const key_type & key(void) const
Definition: mootAssocVector.h:94
bool operator()(const assoc_node_type &x, const assoc_node_type &y) const
Definition: mootAssocVector.h:152