52 #ifndef IFPACK_HASHTABLE_H
53 #define IFPACK_HASHTABLE_H
55 #if defined(Ifpack_SHOW_DEPRECATED_WARNINGS)
57 #warning "The Ifpack package is deprecated"
94 template<
typename key_type>
103 seed_ = (2654435761U);
111 for (
int i = 0; i <
n_sets_; ++i)
122 inline double get(
const key_type key)
124 int hashed_key =
doHash(key);
126 for (
int set_ptr = 0; set_ptr <
counter_[hashed_key]; ++set_ptr)
128 if (
keys_[set_ptr][hashed_key] == key)
129 return(
vals_[set_ptr][hashed_key]);
136 inline void set(
const key_type key,
const double value,
137 const bool addToValue =
false)
139 int hashed_key =
doHash(key);
140 int& hashed_counter =
counter_[hashed_key];
142 for (
int set_ptr = 0; set_ptr < hashed_counter; ++set_ptr)
144 if (
keys_[set_ptr][hashed_key] == key)
147 vals_[set_ptr][hashed_key] += value;
149 vals_[set_ptr][hashed_key] = value;
156 keys_[hashed_counter][hashed_key] = key;
157 vals_[hashed_counter][hashed_key] = value;
162 std::vector<key_type> new_key;
163 std::vector<double> new_val;
165 keys_.push_back(new_key);
166 vals_.push_back(new_val);
189 for (
int key = 0; key <
n_keys_; ++key)
195 void arrayify(key_type* key_array,
double* val_array)
198 for (
int key = 0; key <
n_keys_; ++key)
199 for (
int set_ptr = 0; set_ptr <
counter_[key]; ++set_ptr)
201 key_array[count] =
keys_[set_ptr][key];
202 val_array[count] =
vals_[set_ptr][key];
213 cout <<
"n_keys = " <<
n_keys_ << endl;
214 cout <<
"n_sets = " <<
n_sets_ << endl;
224 3, 7, 13, 23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593,
225 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469,
226 12582917, 25165842, 50331653, 100663319, 201326611, 402653189,
227 805306457, 1610612741 } ;
235 for (i = 6 ; i < 30 ; i++)
258 std::vector<std::vector<double> >
vals_;
259 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.