10#ifndef TEUCHOS_HASHSET_H
11#define TEUCHOS_HASHSET_H
37 inline HashSet(
int capacity=19);
43 inline void put(
const Key& key);
46 inline void remove(
const Key& key);
49 inline int size()
const {
return count_;}
58 inline std::string
toString()
const ;
64 inline int nextPrime(
int newCap)
const ;
69 mutable Key mostRecentKey_;
77 std::ostream& operator<<(std::ostream& os,
const HashSet<Key>& h);
79 template<
class Key>
inline
80 std::string toString(
const HashSet<Key>& h) {
return h.toString();}
83 template<
class Key>
inline
85 : data_(), count_(0), capacity_(
HashUtils::nextPrime(capacity))
87 data_.resize(capacity_);
90 template<
class Key>
inline
96 for (
int i=0; i<candidates.
length(); i++)
98 const Key& c = candidates[i];
107 template<
class Key>
inline
110 int index =
hashCode(key) % capacity_;
115 for (
int i=0; i<local.
length(); i++)
127 if (count_ > capacity_)
129 capacity_ = HashUtils::nextPrime(capacity_+1);
140 template<
class Key>
inline
141 void HashSet<Key>::rehash()
145 for (
int i=0; i<data_.length(); i++)
147 for (
int j=0; j<data_[i].length(); j++)
149 int newIndex =
hashCode(data_[i][j]) % capacity_;
150 tmp[newIndex].append(data_[i][j]);
157 template<
class Key>
inline
163 for (
int i=0; i<data_.length(); i++)
165 for (
int j=0; j<data_[i].length(); j++)
174 template<
class Key>
inline
179 for (
int i=0; i<data_.length(); i++)
181 for (
int j=0; j<data_[i].length(); j++)
188 template<
class Key>
inline
191 std::string rtn =
"HashSet[";
195 for (
int i=0; i<data_.length(); i++)
197 for (
int j=0; j<data_[i].length(); j++)
199 if (!first) rtn +=
", ";
201 rtn += Teuchos::toString(data_[i][j]);
209 template<
class Key>
inline
214 "HashSet<Key>::remove: key "
215 << Teuchos::toString(key)
216 <<
" not found in HashSet"
223 for (
int i=0; i<candidates.
length(); i++)
225 if (candidates[i] == key)
235 template<
class Key>
inline
Templated array class derived from the STL std::vector.
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Utilities for generating hashcodes.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
void reserve(size_type n)
int length() const
Return number of elements in the array.
int hashCode(const Array< T > &array)
Return the hash code.
void remove(int i)
Remove the i-th element from the array, with optional boundschecking.
void resize(size_type new_size, const value_type &x=value_type())
Array< T > & append(const T &x)
Add a new entry at the end of the array.
std::string toString() const
Write to a std::string.
int size() const
Get the number of elements in the table.
std::ostream & operator<<(std::ostream &os, const HashSet< Key > &h)
Write HashSet to a stream.
Array< Key > arrayify() const
Get list of keys in Array form.
void put(const Key &key)
Put a new object into the table.
HashSet(int capacity=19)
Create an empty HashSet.
bool containsKey(const Key &key) const
Check for the presence of a key.
void remove(const Key &key)
Remove from the table the element given by key.
Utilities for generating hashcodes. This is not a true hash ! For all ints and types less than ints i...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...