File: HashSet.hh

package info (click to toggle)
topcom 0.17.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,572 kB
  • sloc: cpp: 16,640; sh: 975; makefile: 345; ansic: 40
file content (101 lines) | stat: -rw-r--r-- 3,470 bytes parent folder | download
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
////////////////////////////////////////////////////////////////////////////////
// 
// HashSet.hh
//    produced: 01/09/97 jr
// last change: 10/10/97 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef HASHSET_HH
#define HASHSET_HH

#include <stdlib.h>
#include <iostream>
#include <ctype.h>
#include <string.h>

#include "RefCount.hh"
#include "PlainHashSet.hh"

template<class Key>	
class HashSet;

template<class Key>
inline std::istream& operator>>(std::istream& ist, HashSet<Key>& ht);

template<class Key>
inline std::ostream& operator<<(std::ostream& ost, const HashSet<Key>& ht);

template<class Key>	
class HashSet {
  typedef SmartPtr< PlainHashSet<Key> >    data_type;
private:
  static const PlainHashSet<Key> default_PlainHashSet;
private:
  data_type _data;
public:
  // constructors:
  inline HashSet() : _data(default_PlainHashSet) {}
  inline HashSet(const size_type new_size) : _data(PlainHashSet<Key>(new_size)) {}
  inline HashSet(const HashSet<Key>& ht) : _data(ht._data) {}
  // destructor:
  inline ~HashSet() {}
  // assignment:
  inline HashSet& operator=(const HashSet<Key>& ht) { _data = ht._data; return *this; }
  // comparison:
  inline bool operator==(const HashSet<Key>& ht) const {
    return (*_data == *ht._data);
  }
  inline bool operator!=(const HashSet<Key>& ht) const {
    return !((*this) == ht);
  }
  // keys for containers:
  inline const size_type keysize()              const { return _data->keysize(); }
  inline const size_type key(const size_type n) const { return _data->key(n); }
  // accessors:
  inline const bool           is_empty() const { return _data->is_empty(); }
  inline const size_type      card()     const { return _data->load(); }
  inline const size_type      size()     const { return _data->size(); }
  inline const size_type      load()     const { return _data->load(); }
#ifdef WATCH_MAXCHAINLEN
  inline static const size_type      maxchainlen() { return PlainHashSet<Key>::maxchainlen(); }
#endif
  // operations:
  inline bool member(const Key& key) const { return _data->member(key); }
  inline void insert(const Key& key)       { _data->insert(key); }
  inline void erase(const Key& key)        { _data->erase(key); }
  inline void erase_random()               { _data->erase_random(); }
  inline void clear()                      { _data->clear(); }
  // iterator types:
  typedef typename PlainHashSet<Key>::const_iterator const_iterator;
  typedef const_iterator                    iterator;
  // iterator functions:
  inline const_iterator begin()              const {return _data->begin();}
  inline const_iterator end()                const {return _data->end();}
  inline const_iterator find(const Key& key) const { return _data->find(key); }
  // iostream:
  inline std::istream& read(std::istream& ist) {
    return ist >> *_data;
  }
  inline std::ostream& write(std::ostream& ost) const {
    return ost << *_data;
  }
  friend std::istream& operator>><>(std::istream& ist, HashSet<Key>& ht);
  friend std::ostream& operator<<<>(std::ostream& ost, const HashSet<Key>& ht);
};

template<class Key>
const PlainHashSet<Key> HashSet<Key>::default_PlainHashSet;

// friends:
template<class Key>
inline std::istream& operator>>(std::istream& ist, HashSet<Key>& ht) {
  return ht.read(ist);
}

template<class Key>
inline std::ostream& operator<<(std::ostream& ost, const HashSet<Key>& ht) {
  return ht.write(ost);
}

#endif
// eof HashSet.hh