42 #ifndef TEUCHOS_HASHTABLE_H 43 #define TEUCHOS_HASHTABLE_H 60 template<
class Key,
class Value>
class HashPair 66 inline HashPair(
const Key& key,
const Value& value)
85 inline Hashtable(
int capacity=101,
double rehashDensity = 0.8);
88 inline bool containsKey(
const Key& key)
const ;
91 inline const Value&
get(
const Key& key)
const ;
94 inline void put(
const Key& key,
const Value& value);
97 inline void remove(
const Key& key);
100 inline int size()
const {
return count_;}
109 inline double density()
const {
return ((
double)count_)/((double) capacity_);}
112 inline void setRehashDensity(
double rehashDensity);
115 inline std::string
toString()
const ;
119 inline void rehash();
120 inline int nextPrime(
int newCap)
const ;
121 inline void accumulateAvgFill(
int n)
const ;
135 template<
class Key,
class Value>
141 template<
class Key,
class Value>
142 std::ostream& operator<<(std::ostream& os, const Hashtable<Key, Value>& h);
144 template<
class Key,
class Value>
inline 146 : data_(), count_(0), capacity_(
HashUtils::nextPrime(capacity)),
147 nHits_(0), avgDegeneracy_(0), rehashDensity_(rehashDensity)
152 template<
class Key,
class Value>
inline 158 for (
int i=0; i<candidates.
length(); i++)
171 template<
class Key,
class Value>
inline 179 for (
int i=0; i<local.
length(); i++)
181 if (local[i].key_ == key)
183 local[i].value_ = value;
205 template<
class Key,
class Value>
inline 210 for (
int i=0; i<
data_.length(); i++)
212 for (
int j=0; j<
data_[i].length(); j++)
223 template<
class Key,
class Value>
inline 229 for (
int i=0; i<
data_.length(); i++)
231 for (
int j=0; j<
data_[i].length(); j++)
239 template<
class Key,
class Value>
inline 246 std::string rtn =
"[";
247 for (
int i=0; i<keys.
length(); i++)
251 if (i < keys.
length()-1) rtn +=
", ";
258 template<
class Key,
class Value>
inline 265 std::string rtn =
"[";
266 for (
int i=0; i<keys.
length(); i++)
270 if (i < keys.
length()-1) rtn +=
", ";
277 template<
class Key,
class Value>
inline 282 "Hashtable<Key, Value>::get: key " 284 <<
" not found in Hashtable" 292 for (
int i=0; i<candidates.
length(); i++)
304 template<
class Key,
class Value>
inline 309 "Hashtable<Key, Value>::remove: key " 311 <<
" not found in Hashtable" 318 for (
int i=0; i<candidates.
length(); i++)
329 template<
class Key,
class Value>
inline 336 template<
class Key,
class Value>
inline 337 std::ostream& operator<<(std::ostream& os, const Hashtable<Key, Value>& h)
345 #endif // TEUCHOS_HASHTABLE_H Templated hashtable class.
void reserve(size_type n)
Utilities for generating hashcodes.
Array< T > & append(const T &x)
Add a new entry at the end of the array.
void arrayify(Array< Key > &keys, Array< Value > &values) const
Get lists of keys and values in Array form.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
HashPair()
Empty constructor.
static int nextPrime(int newCapacity)
Value value_
Templated value variable.
std::string toString() const
Write to a std::string.
double avgDegeneracy() const
Return the average degeneracy (average number of entries per hash code).
Array< Array< HashPair< Key, Value > > > data_
double density() const
Return the density of the hashtable (num entries / capacity)
std::string toString(const HashSet< Key > &h)
bool containsKey(const Key &key) const
Check for the presence of a key.
Hashtable(int capacity=101, double rehashDensity=0.8)
Create an empty Hashtable.
Templated array class derived from the STL std::vector.
void put(const Key &key, const Value &value)
Put a new (key, value) pair in the table.
int length() const
Return number of elements in the array.
Helper class for Teuchos::Hashtable, representing a single <key, value> pair.
Utilities for generating hashcodes.
void accumulateAvgFill(int n) const
HashPair(const Key &key, const Value &value)
Basic <key, value> constructor.
const Value & get(const Key &key) const
Get the value indexed by key.
int size() const
Get the number of elements in the table.
void remove(const Key &key)
Remove from the table the element given by key.
Memory-safe templated array class that encapsulates std::vector.
Key key_
Templated key variable.