00001 #ifndef INT_HASH_IMPLEMENTATION
00002 #define INT_HASH_IMPLEMENTATION
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "byte_hasher.h"
00019 #include "hash_table.cpp"
00020 #include "int_hash.h"
00021
00022 #include <basis/set.cpp>
00023
00024 template <class contents>
00025 int_hash<contents>::int_hash(int max_bits)
00026 : hash_table<int, contents>(rotating_byte_hasher(), max_bits),
00027 _ids(new int_set)
00028 {}
00029
00030 template <class contents>
00031 int_hash<contents>::~int_hash()
00032 { WHACK(_ids); }
00033
00034 template <class contents>
00035 const int_set &int_hash<contents>::ids() const { return *_ids; }
00036
00037 template <class contents>
00038 void int_hash<contents>::ids(int_set &ids) const { ids = *_ids; }
00039
00040 template <class contents>
00041 outcome int_hash<contents>::add(int key, contents *to_store)
00042 {
00043 _ids->add(key);
00044 return hash_table<int, contents>::add(key, to_store);
00045 }
00046
00047 template <class contents>
00048 contents *int_hash<contents>::acquire(int key)
00049 {
00050 _ids->remove(key);
00051 return hash_table<int, contents>::acquire(key);
00052 }
00053
00054 template <class contents>
00055 bool int_hash<contents>::zap(int key)
00056 {
00057 _ids->remove(key);
00058 return hash_table<int, contents>::zap(key);
00059 }
00060
00061 template <class contents>
00062 void int_hash<contents>::reset()
00063 {
00064 _ids->clear();
00065 hash_table<int, contents>::reset();
00066 }
00067
00068 template <class contents>
00069 void int_hash<contents>::apply(apply_function *to_apply, void *data_link)
00070 {
00071 for (int i = 0; i < _ids->elements(); i++) {
00072 int current = (*_ids)[i];
00073 contents *found = hash_table<int, contents>::find(current);
00074 if (!found) {
00075 _ids->remove(current);
00076 continue;
00077 }
00078 to_apply(current, *found, data_link);
00079 }
00080 }
00081
00082 #endif // outer guard.
00083