00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef SUNDANCE_INTHASHSET_H
00032 #define SUNDANCE_INTHASHSET_H
00033
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceSet.hpp"
00036 #include "Teuchos_Array.hpp"
00037 #include <list>
00038
00039
00040 namespace Sundance
00041 {
00042 using namespace Teuchos;
00043
00044
00045
00046
00047 class IntHashSet
00048 {
00049 public:
00050
00051 IntHashSet();
00052
00053
00054 void setCapacity(int capacity);
00055
00056
00057 inline void put(int x)
00058 {
00059
00060 std::list<int>& d = data_[hashFunc(x)];
00061 for (std::list<int>::const_iterator i=d.begin(); i != d.end(); i++)
00062 {
00063 if (x == *i) return;
00064 }
00065 d.push_back(x);
00066 size_++;
00067 }
00068
00069
00070 bool contains(int x) const ;
00071
00072
00073 int size() const {return size_;}
00074
00075
00076 void fillArray(int* a) const ;
00077
00078 private:
00079
00080 inline int hashFunc( const int key ) const { return (seed() ^ key)%capacity_; }
00081
00082 static unsigned int seed() {static int rtn = (2654435761U); return rtn;}
00083 unsigned int capacity_;
00084 Array<std::list<int> > data_;
00085 int size_;
00086 };
00087
00088 }
00089
00090
00091 #endif