10#ifndef TEUCHOS_HASHSET_H
11#define TEUCHOS_HASHSET_H
37 inline HashSet(
int capacity=19);
43 inline void put(
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
94 = data_[hashCode(key) % capacity_];
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);
132 index = hashCode(key) % capacity_;
135 data_[index].append(key);
140 template<
class Key>
inline
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_;
157 template<
class Key>
inline
163 for (
int i=0;
i<data_.length();
i++)
165 for (
int j=0;
j<data_[
i].length();
j++)
167 rtn.append(data_[
i][
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++)
183 rtn.append(data_[
i][
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"
220 int h = hashCode(key) % capacity_;
235 template<
class Key>
inline
238 return os <<
h.toString();
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.
Templated hashtable-based set.
std::string toString() const
Write to a std::string.
int size() const
Get the number of elements in the table.
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...
Smart reference counting pointer class for automatic garbage collection.
#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,...