52 #ifndef IFPACK_HASHTABLE_H
53 #define IFPACK_HASHTABLE_H
88 template<
typename key_type>
97 seed_ = (2654435761U);
105 for (
int i = 0; i <
n_sets_; ++i)
116 inline double get(
const key_type key)
118 int hashed_key =
doHash(key);
120 for (
int set_ptr = 0; set_ptr <
counter_[hashed_key]; ++set_ptr)
122 if (
keys_[set_ptr][hashed_key] == key)
123 return(
vals_[set_ptr][hashed_key]);
130 inline void set(
const key_type key,
const double value,
131 const bool addToValue =
false)
133 int hashed_key =
doHash(key);
134 int& hashed_counter =
counter_[hashed_key];
136 for (
int set_ptr = 0; set_ptr < hashed_counter; ++set_ptr)
138 if (
keys_[set_ptr][hashed_key] == key)
141 vals_[set_ptr][hashed_key] += value;
143 vals_[set_ptr][hashed_key] = value;
150 keys_[hashed_counter][hashed_key] = key;
151 vals_[hashed_counter][hashed_key] = value;
156 std::vector<key_type> new_key;
157 std::vector<double> new_val;
159 keys_.push_back(new_key);
160 vals_.push_back(new_val);
183 for (
int key = 0; key <
n_keys_; ++key)
189 void arrayify(key_type* key_array,
double* val_array)
192 for (
int key = 0; key <
n_keys_; ++key)
193 for (
int set_ptr = 0; set_ptr <
counter_[key]; ++set_ptr)
195 key_array[count] =
keys_[set_ptr][key];
196 val_array[count] =
vals_[set_ptr][key];
207 cout <<
"n_keys = " <<
n_keys_ << endl;
208 cout <<
"n_sets = " <<
n_sets_ << endl;
218 3, 7, 13, 23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593,
219 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469,
220 12582917, 25165842, 50331653, 100663319, 201326611, 402653189,
221 805306457, 1610612741 } ;
229 for (i = 6 ; i < 30 ; i++)
252 std::vector<std::vector<double> >
vals_;
253 std::vector<std::vector<key_type> >
keys_;
Ifpack_HashTable(const int n_keys=1031, const int n_sets=1)
std::vector< int > counter_
std::vector< std::vector< key_type > > keys_
void print()
Basic printing routine.
std::vector< std::vector< double > > vals_
void set(const key_type key, const double value, const bool addToValue=false)
Sets an element in the hash table.
TIfpack_HashTable(const int n_keys=1031, const int n_sets=1)
constructor.
void arrayify(key_type *key_array, double *val_array)
Converts the contents in array format for both keys and values.
Ifpack_HashTable64(const int n_keys=1031, const int n_sets=1)
int getNumEntries() const
Returns the number of stored entries.
int getRecommendedHashSize(int n)
void reset()
Resets the entries of the already allocated memory. This method can be used to clean an array...
int doHash(const key_type key)
Performs the hashing.