1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
////////////////////////////////////////////////////////////////////////////////
//
// PlainHashSet.hh
// produced: 01/09/97 jr
// last change: 24/01/99 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef PLAINHASHSET_HH
#define PLAINHASHSET_HH
#include <stdlib.h>
#include <iostream>
#include <ctype.h>
#include <string.h>
#include "Global.hh"
#include "RefCount.hh"
#include "PlainHashTable.hh"
namespace topcom {
template<class Key>
class HashSetData;
template<class Key>
class __hsd_reader;
template<class Key>
inline std::istream& operator>>(std::istream& ist, __hsd_reader<Key>& r);
template<class Key>
class __hsd_reader {
public:
Key key;
public:
inline __hsd_reader() : key() {}
friend std::istream& operator>><>(std::istream& ist, __hsd_reader& r);
};
template<class Key>
inline std::ostream& operator<<(std::ostream& ost, const HashSetData<Key>& hsd);
template<class Key>
class HashSetData {
public:
typedef Key key_type;
typedef SmartPtr<Key> keyptr_type;
typedef SmartPtr<const Key> const_keyptr_type;
typedef __hsd_reader<Key> reader;
private:
const const_keyptr_type _keyptr;
public:
// constructors:
inline HashSetData() : _keyptr() {}
inline HashSetData(const HashSetData& hsd) : _keyptr(hsd._keyptr) {}
inline HashSetData(const Key& new_key) : _keyptr(new_key) {}
inline HashSetData(const reader& r) : _keyptr(r.key) {}
// destructor:
inline ~HashSetData() {}
private:
// assignment:
inline HashSetData& operator=(const HashSetData& hsd) {
if (this == &hsd) {
return *this;
}
_keyptr = hsd._keyptr;
return *this;
}
public:
// conversion:
inline operator const Key&() const { return *_keyptr; }
// keys for containers:
inline const keyptr_type& keyptr() const { return _keyptr; }
inline const Key& key() const { return *_keyptr; }
// comparison:
inline const bool operator==(const HashSetData<Key>& hsd) const { return (key() == hsd.key()); }
inline const bool operator!=(const HashSetData<Key>& hsd) const { return !(key() == hsd.key()); }
// iostream:
inline std::ostream& write(std::ostream& ost) const {
return ost << *_keyptr;
}
friend std::ostream& operator<<<>(std::ostream& ost, const HashSetData<Key>& hsd);
};
template<class Key>
class PlainHashSet : public PlainHashTable< HashSetData<Key> > {
public:
typedef PlainHashTable< HashSetData<Key> > plainhashset_data;
typedef typename HashSetData<Key>::keyptr_type keyptr_type;
typedef typename HashSetData<Key>::const_keyptr_type const_keyptr_type;
public:
// constructors:
inline PlainHashSet() : plainhashset_data() {}
inline PlainHashSet(const PlainHashSet& phs) : plainhashset_data(phs) {}
inline PlainHashSet(const plainhashset_data& phsd) : plainhashset_data(phsd) {}
inline PlainHashSet(const size_type init_bucket_count) : plainhashset_data(init_bucket_count) {}
// destructor:
inline ~PlainHashSet() {}
// assignment:
inline PlainHashSet& operator=(const PlainHashSet& phs) {
plainhashset_data::operator=(phs);
return *this;
}
// functions:
inline void insert(const Key& key) { plainhashset_data::insert(key); }
inline bool member(const Key& key) const { return plainhashset_data::member(key); }
};
template<class Key>
inline std::istream& operator>>(std::istream& ist, __hsd_reader<Key>& r) {
if (!(ist >> std::ws >> r.key)) {
#ifdef READ_DEBUG
std::cerr << "std::istream& operator>>(std::istream&, HashMapData<Key, Data>&): "
<< "key not found." << std::endl;
#endif
ist.clear(std::ios::failbit);
return ist;
}
return ist;
}
template<class Key>
inline std::ostream& operator<<(std::ostream& ost, const HashSetData<Key>& hsd) {
return hsd.write(ost);
}
}; // namespace topcom
#endif
// eof PlainHashSet.hh
|