79 #include <mix/IntAr.H>
81 #if !defined(AnyType) || !defined(AnyHash) || !defined(AnyKeyType) || !defined(AnyItem2Key) || !defined(AnyKey2Hash) || !defined(AnyKeyCmp)
82 #error "All AnyType,AnyHash,AnyKeyType,AnyItem2Key,AnyKey2Hash,AnyKeyCmp macros must be defined."
100 unsigned& hash_i,
unsigned& item_i)
const {
101 hash_i = AnyKey2Hash(key) %
hashBase;
105 for(item_i = 0; item_i < hash_ar.count(); ++item_i)
107 AnyType& item = *(AnyType*)(hash_ar.item_ptr(item_i));
108 if(EQUAL == AnyKeyCmp(key, AnyItem2Key(item)))
122 Throw(ERROR__ZERO_COUNT);
140 unsigned hash_i, item_i;
141 return find_key(key_value, hash_i, item_i);
146 unsigned i, total = 0;
163 AnyType& hash_fetch (AnyKeyType key) {
164 unsigned hash_i, item_i;
166 Throw(ERROR__DA_UNKNOWN_KEY);
167 AnyType& item = *(AnyType*)
hashItems[hash_i]->item_ptr(item_i);
171 AnyType hash_get (AnyKeyType key)
const {
172 unsigned hash_i, item_i;
174 Throw(ERROR__DA_UNKNOWN_KEY);
175 AnyType& item = *(AnyType*)
hashItems[hash_i]->item_ptr(item_i);
179 AnyType& operator[] (AnyKeyType key) {
180 return hash_fetch(key);
183 AnyType operator() (AnyKeyType key)
const {
184 return hash_get(key);
192 void add (
const AnyType& val) {
193 unsigned hash_i, item_i;
194 if(
find_key(AnyItem2Key(val), hash_i, item_i)){
195 Throw(ERROR__DA_KNOWN_KEY);
199 DEFAULT_QUANT, START_VOLUME);
202 *(AnyType*)hash_ar.item_ptr(_last_) = val;
207 void put (
const AnyType& val) {
208 unsigned hash_i, item_i;
209 if(
find_key(AnyItem2Key(val), hash_i, item_i)){
211 *(AnyType*)hash_ar.item_ptr(item_i) = val;
215 DEFAULT_QUANT, START_VOLUME);
218 *(AnyType*)hash_ar.item_ptr(_last_) = val;
Macro implementation of universal hash storage method with quick access.
Definition: AnyHash.H:86
DynAr ** hashItems
Definition: AnyHash.H:92
unsigned hashBase
Definition: AnyHash.H:95
void add(const AnyType &val)
Definition: AnyHash.H:192
virtual ~AnyHash()
Definition: AnyHash.H:129
Logic known_key(AnyKeyType key_value) const
Definition: AnyHash.H:139
void value_list(DynAr &vals) const
Definition: AnyHash.H:154
Logic find_key(AnyKeyType key, unsigned &hash_i, unsigned &item_i) const
Definition: AnyHash.H:99
void put(const AnyType &val)
Definition: AnyHash.H:207
AnyHash(unsigned base)
Definition: AnyHash.H:118
unsigned count() const
Definition: AnyHash.H:145