|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
21 #ifndef ELM_DATA_HASHMAP_H_
22 #define ELM_DATA_HASHMAP_H_
25 #include "HashTable.h"
27 #include <elm/delegate.h>
31 template <
class K,
class T,
class H = HashKey<K>,
class A = DefaultAlloc,
class E = Equiv<T> >
39 inline HashMap(
int _size = 211): _tab(_size) { }
41 inline const H&
hash()
const {
return _tab.
hash().keyHash(); }
42 inline H&
hash() {
return _tab.
hash().keyHash(); }
49 inline void add(
const K& key,
const T& val) { _tab.
add(
pair(key, val)); }
52 {
auto *n = _tab.
get(key(k));
if(n !=
nullptr)
return n->snd;
return _tab.
add(
pair(k, T()))->snd; }
56 {
auto *r = _tab.
get(key(k));
if(r)
return some(r->snd);
else return none; }
57 inline const T&
get(
const K& k,
const T&
def)
const
58 {
auto p = key(k);
auto r = _tab.
get(
p);
if(r)
return r->snd;
else return def; }
59 inline bool hasKey(
const K& k)
const {
return _tab.
hasKey(key(k)); }
62 {
auto *r = _tab.
get_const(key(k));
if(r)
return some(r->snd);
else return none; }
64 {
auto r = _tab.
get_const(key(k));
if(r)
return r->snd;
else return def; }
71 inline bool ended(
void)
const {
return i.ended(); }
72 inline const K&
item(
void)
const {
return i.
item().fst; }
73 inline void next(
void) { i.next(); }
84 inline bool ended(
void)
const {
return i.ended(); }
86 inline void next(
void) { i.next(); }
103 inline bool ended(
void)
const {
return i.ended(); }
104 inline const T&
item(
void)
const {
return i.
item().snd; }
105 inline void next(
void) { i.next(); }
106 inline const K&
key(
void)
const {
return i.
item().fst; }
107 inline bool equals(
const Iter& it)
const {
return i.equals(it.i); }
111 inline Iter
begin(
void)
const {
return Iter(*
this); }
112 inline Iter
end(
void)
const {
return Iter(*
this,
true); }
115 {
for(
const auto x: *
this)
if(x == item)
return true;
return false; }
117 {
for(
typename C::Iter i(c); c; i++)
if(!
contains(*i))
return false;
return true; }
133 inline void put(
const K& key,
const T& val) { _tab.
put(
pair(key, val)); }
137 inline const T&
operator[](
const K& k)
const {
auto *r = _tab.
get(key(k)); ASSERT(r);
return (*r).snd; }
139 inline const T&
operator[](
const Iter& i)
const {
auto *r = _tab.
get(key(i.key())); ASSERT(r);
return (*r).snd; }
142 template <
class C>
void putAll(
const C& c)
143 {
for(
auto p: c.pairs())
put(
p.fst,
p.snd); }
146 int minEntry(
void)
const {
return _tab.minEntry(); }
147 int maxEntry(
void)
const {
return _tab.maxEntry(); }
149 int size(
void)
const {
return _tab.size(); }
bool equals(const PairIter &it) const
Definition: HashMap.h:87
const T & get(const K &k, const T &def) const
Definition: HashMap.h:57
void remove(const K &k)
Definition: HashMap.h:134
T val_t
Definition: HashMap.h:36
const K & key(void) const
Definition: HashMap.h:106
void add(const K &key, const T &val)
Definition: HashMap.h:49
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
void putAll(const C &c)
Definition: HashMap.h:142
int count() const
Definition: HashMap.h:94
bool hasKey_const(const T &key) const
Definition: HashTable.h:109
Iterable< I > subiter(const I &b, const I &e)
Definition: util.h:231
void next(void)
Definition: HashMap.h:105
bool operator!=(const HashMap< K, T > &t) const
Definition: HashMap.h:122
const Pair< K, T > & item(void) const
Definition: HashMap.h:85
bool equals(const HashMap< K, T > &t) const
Definition: HashMap.h:119
void put(const K &key, const T &val)
Definition: HashMap.h:133
const T & item(void) const
Definition: HashMap.h:104
Pair< T1, T2 > pair(const T1 &v1, const T2 &v2)
Definition: Pair.h:63
const T & operator[](const Iter &i) const
Definition: HashMap.h:139
StrictMapDelegate< self_t > operator[](const K &key)
Definition: HashMap.h:138
KeyIter(const self_t &htab, bool end)
Definition: HashMap.h:70
void next(void)
Definition: HashMap.h:73
static Equiv< T > def
Definition: equiv.h:37
void next(void)
Definition: HashMap.h:86
const H & hash() const
Definition: HashTable.h:98
bool containsAll(const C &c) const
Definition: HashMap.h:116
Definition: HashTable.h:135
Option< T > get(const K &k) const
Definition: HashMap.h:55
E & equivalence()
Definition: HashMap.h:46
PairIter(const self_t &htab, bool end)
Definition: HashMap.h:83
const A & allocator() const
Definition: HashTable.h:100
Option< T > some(const T &val)
Definition: Option.h:81
const K & item(void) const
Definition: HashMap.h:72
int zeroEntry(void) const
Definition: HashMap.h:148
void put(const T &data)
Definition: HashTable.h:114
Iter end(void) const
Definition: HashMap.h:112
int maxEntry(void) const
Definition: HashMap.h:147
bool exists(const K &k) const
Definition: HashMap.h:153
const T & item(void) const
Definition: HashTable.h:139
const T * get(const T &key) const
Definition: HashTable.h:103
bool equals(const KeyIter &it) const
Definition: HashMap.h:74
Iter operator*(void) const
Definition: HashMap.h:154
KeyIter(const self_t &htab)
Definition: HashMap.h:69
const OptionalNone none
Definition: util_Option.cpp:154
Iterable< PairIter > pairs() const
Definition: HashMap.h:91
bool operator<(const HashMap< K, T > &t) const
Definition: HashMap.h:129
bool hasKey(const T &key) const
Definition: HashTable.h:107
const E & equivalence() const
Definition: HashMap.h:45
bool includes(const HashMap< K, T > &t) const
Definition: HashMap.h:124
HashMap(int _size=211)
Definition: HashMap.h:39
bool isEmpty() const
Definition: HashMap.h:95
bool ended(void) const
Definition: HashMap.h:103
bool hasKey(const K &k) const
Definition: HashMap.h:59
int minEntry(void) const
Definition: HashMap.h:146
const A & allocator() const
Definition: HashMap.h:43
A & allocator()
Definition: HashMap.h:44
Option< T > get_const(const K &k) const
Definition: HashMap.h:61
bool equals(const Iter &it) const
Definition: HashMap.h:107
Iter(const self_t &htab)
Definition: HashMap.h:101
bool operator==(const HashMap< K, T > &t) const
Definition: HashMap.h:121
T & fetch(const K &k)
Definition: HashMap.h:51
bool operator>=(const HashMap< K, T > &t) const
Definition: HashMap.h:127
bool operator>(const HashMap< K, T > &t) const
Definition: HashMap.h:130
bool contains(const T &item) const
Definition: HashMap.h:114
const T * get_const(const T &key) const
Definition: HashTable.h:105
int count(void) const
Definition: HashTable.h:124
const T & get_const(const K &k, const T &def) const
Definition: HashMap.h:63
int size(void) const
Definition: HashMap.h:149
bool operator<=(const HashMap< K, T > &t) const
Definition: HashMap.h:126
void remove(const Iter &i)
Definition: HashMap.h:135
void clear(void)
Definition: HashTable.h:152
void remove(const T &key)
Definition: HashTable.h:166
Definition: HashTable.h:32
const H & hash() const
Definition: HashMap.h:41
T * add(const T &data)
Definition: HashTable.h:159
bool hasKey_const(const K &k) const
Definition: HashMap.h:65
Definition: delegate.h:95
K key_t
Definition: HashMap.h:35
bool ended(void) const
Definition: HashMap.h:71
Iter begin(void) const
Definition: HashMap.h:111
HashMap(const self_t &h)
Definition: HashMap.h:40
const T & operator[](const K &k) const
Definition: HashMap.h:137
Iter(const self_t &htab, bool end)
Definition: HashMap.h:102
bool ended(void) const
Definition: HashMap.h:84
Iterable< KeyIter > keys() const
Definition: HashMap.h:78
StrictMapDelegate< self_t > operator[](const Iter &i)
Definition: HashMap.h:140
HashMap< K, T, H, A, E > self_t
Definition: HashMap.h:37
H & hash()
Definition: HashMap.h:42
PairIter(const self_t &htab)
Definition: HashMap.h:82
void clear(void)
Definition: HashMap.h:48
bool isEmpty(void) const
Definition: HashTable.h:121