hash_set.hxx.in 12.6 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
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
/*
 * Copyright (c) 1996
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 */
#ifndef @KWSYS_NAMESPACE@_hash_set_hxx
#define @KWSYS_NAMESPACE@_hash_set_hxx

#include <@KWSYS_NAMESPACE@/hashtable.hxx>
32

33
#include <@KWSYS_NAMESPACE@/hash_fun.hxx>
34

Brad King's avatar
Brad King committed
35
#include <functional> // equal_to
36 37

#if defined(_MSC_VER)
38 39 40
#pragma warning(push)
#pragma warning(disable : 4284)
#pragma warning(disable : 4786)
41 42 43
#endif

#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
44 45
#pragma set woff 1174
#pragma set woff 1375
46 47
#endif

48
namespace @KWSYS_NAMESPACE@ {
49 50 51

// identity is an extension: it is not part of the standard.
template <class _Tp>
52
struct _Identity : public std::unary_function<_Tp, _Tp>
53 54 55 56 57 58
{
  const _Tp& operator()(const _Tp& __x) const { return __x; }
};

// Forward declaration of equality operator; needed for friend declaration.

59
template <class _Value, class _HashFcn = hash<_Value>,
Brad King's avatar
Brad King committed
60
          class _EqualKey = std::equal_to<_Value>,
61
          class _Alloc = std::allocator<char> >
62 63 64
class hash_set;

template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
65 66
bool operator==(const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs1,
                const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs2);
67 68 69 70 71

template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
class hash_set
{
private:
72 73 74
  typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, _EqualKey,
                    _Alloc>
    _Ht;
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
  _Ht _M_ht;

public:
  typedef typename _Ht::key_type key_type;
  typedef typename _Ht::value_type value_type;
  typedef typename _Ht::hasher hasher;
  typedef typename _Ht::key_equal key_equal;

  typedef typename _Ht::size_type size_type;
  typedef typename _Ht::difference_type difference_type;
  typedef typename _Ht::const_pointer pointer;
  typedef typename _Ht::const_pointer const_pointer;
  typedef typename _Ht::const_reference reference;
  typedef typename _Ht::const_reference const_reference;

  typedef typename _Ht::const_iterator iterator;
  typedef typename _Ht::const_iterator const_iterator;

  typedef typename _Ht::allocator_type allocator_type;

  hasher hash_funct() const { return _M_ht.hash_funct(); }
  key_equal key_eq() const { return _M_ht.key_eq(); }
  allocator_type get_allocator() const { return _M_ht.get_allocator(); }

public:
  hash_set()
101 102 103
    : _M_ht(100, hasher(), key_equal(), allocator_type())
  {
  }
104
  explicit hash_set(size_type __n)
105 106 107
    : _M_ht(__n, hasher(), key_equal(), allocator_type())
  {
  }
108
  hash_set(size_type __n, const hasher& __hf)
109 110 111
    : _M_ht(__n, __hf, key_equal(), allocator_type())
  {
  }
112 113
  hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
           const allocator_type& __a = allocator_type())
114 115 116
    : _M_ht(__n, __hf, __eql, __a)
  {
  }
117 118 119 120

  template <class _InputIterator>
  hash_set(_InputIterator __f, _InputIterator __l)
    : _M_ht(100, hasher(), key_equal(), allocator_type())
121 122 123
  {
    _M_ht.insert_unique(__f, __l);
  }
124 125 126
  template <class _InputIterator>
  hash_set(_InputIterator __f, _InputIterator __l, size_type __n)
    : _M_ht(__n, hasher(), key_equal(), allocator_type())
127 128 129
  {
    _M_ht.insert_unique(__f, __l);
  }
130 131 132 133
  template <class _InputIterator>
  hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
           const hasher& __hf)
    : _M_ht(__n, __hf, key_equal(), allocator_type())
134 135 136
  {
    _M_ht.insert_unique(__f, __l);
  }
137 138 139 140 141
  template <class _InputIterator>
  hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
           const hasher& __hf, const key_equal& __eql,
           const allocator_type& __a = allocator_type())
    : _M_ht(__n, __hf, __eql, __a)
142 143 144
  {
    _M_ht.insert_unique(__f, __l);
  }
145 146 147 148 149 150 151

public:
  size_type size() const { return _M_ht.size(); }
  size_type max_size() const { return _M_ht.max_size(); }
  bool empty() const { return _M_ht.empty(); }
  void swap(hash_set& __hs) { _M_ht.swap(__hs._M_ht); }

152
  friend bool operator==<>(const hash_set&, const hash_set&);
153 154 155 156 157

  iterator begin() const { return _M_ht.begin(); }
  iterator end() const { return _M_ht.end(); }

public:
Brad King's avatar
Brad King committed
158
  std::pair<iterator, bool> insert(const value_type& __obj)
159 160 161 162 163
  {
    typedef typename _Ht::iterator _Ht_iterator;
    std::pair<_Ht_iterator, bool> __p = _M_ht.insert_unique(__obj);
    return std::pair<iterator, bool>(__p.first, __p.second);
  }
164 165
  template <class _InputIterator>
  void insert(_InputIterator __f, _InputIterator __l)
166 167 168
  {
    _M_ht.insert_unique(__f, __l);
  }
Brad King's avatar
Brad King committed
169
  std::pair<iterator, bool> insert_noresize(const value_type& __obj)
170 171
  {
    typedef typename _Ht::iterator _Ht_iterator;
172
    std::pair<_Ht_iterator, bool> __p = _M_ht.insert_unique_noresize(__obj);
Brad King's avatar
Brad King committed
173
    return std::pair<iterator, bool>(__p.first, __p.second);
174 175 176 177 178 179
  }

  iterator find(const key_type& __key) const { return _M_ht.find(__key); }

  size_type count(const key_type& __key) const { return _M_ht.count(__key); }

Brad King's avatar
Brad King committed
180
  std::pair<iterator, iterator> equal_range(const key_type& __key) const
181 182 183
  {
    return _M_ht.equal_range(__key);
  }
184

185
  size_type erase(const key_type& __key) { return _M_ht.erase(__key); }
186 187 188 189 190 191 192 193 194
  void erase(iterator __it) { _M_ht.erase(__it); }
  void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
  void clear() { _M_ht.clear(); }

public:
  void resize(size_type __hint) { _M_ht.resize(__hint); }
  size_type bucket_count() const { return _M_ht.bucket_count(); }
  size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
  size_type elems_in_bucket(size_type __n) const
195 196 197
  {
    return _M_ht.elems_in_bucket(__n);
  }
198 199 200
};

template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
201 202
bool operator==(const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs1,
                const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs2)
203 204 205 206 207
{
  return __hs1._M_ht == __hs2._M_ht;
}

template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
208 209 210 211
inline bool operator!=(
  const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs1,
  const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __hs2)
{
212 213 214 215
  return !(__hs1 == __hs2);
}

template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
216 217
inline void swap(hash_set<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1,
                 hash_set<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2)
218 219 220 221
{
  __hs1.swap(__hs2);
}

222
template <class _Value, class _HashFcn = hash<_Value>,
Brad King's avatar
Brad King committed
223
          class _EqualKey = std::equal_to<_Value>,
224
          class _Alloc = std::allocator<char> >
225 226 227
class hash_multiset;

template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
228 229
bool operator==(const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1,
                const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2);
230 231 232 233 234

template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
class hash_multiset
{
private:
235 236 237
  typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, _EqualKey,
                    _Alloc>
    _Ht;
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
  _Ht _M_ht;

public:
  typedef typename _Ht::key_type key_type;
  typedef typename _Ht::value_type value_type;
  typedef typename _Ht::hasher hasher;
  typedef typename _Ht::key_equal key_equal;

  typedef typename _Ht::size_type size_type;
  typedef typename _Ht::difference_type difference_type;
  typedef typename _Ht::const_pointer pointer;
  typedef typename _Ht::const_pointer const_pointer;
  typedef typename _Ht::const_reference reference;
  typedef typename _Ht::const_reference const_reference;

  typedef typename _Ht::const_iterator iterator;
  typedef typename _Ht::const_iterator const_iterator;

  typedef typename _Ht::allocator_type allocator_type;

  hasher hash_funct() const { return _M_ht.hash_funct(); }
  key_equal key_eq() const { return _M_ht.key_eq(); }
  allocator_type get_allocator() const { return _M_ht.get_allocator(); }

public:
  hash_multiset()
264 265 266
    : _M_ht(100, hasher(), key_equal(), allocator_type())
  {
  }
267
  explicit hash_multiset(size_type __n)
268 269 270
    : _M_ht(__n, hasher(), key_equal(), allocator_type())
  {
  }
271
  hash_multiset(size_type __n, const hasher& __hf)
272 273 274
    : _M_ht(__n, __hf, key_equal(), allocator_type())
  {
  }
275 276
  hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql,
                const allocator_type& __a = allocator_type())
277 278 279
    : _M_ht(__n, __hf, __eql, __a)
  {
  }
280 281 282 283

  template <class _InputIterator>
  hash_multiset(_InputIterator __f, _InputIterator __l)
    : _M_ht(100, hasher(), key_equal(), allocator_type())
284 285 286
  {
    _M_ht.insert_equal(__f, __l);
  }
287 288 289
  template <class _InputIterator>
  hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n)
    : _M_ht(__n, hasher(), key_equal(), allocator_type())
290 291 292
  {
    _M_ht.insert_equal(__f, __l);
  }
293 294 295 296
  template <class _InputIterator>
  hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
                const hasher& __hf)
    : _M_ht(__n, __hf, key_equal(), allocator_type())
297 298 299
  {
    _M_ht.insert_equal(__f, __l);
  }
300 301 302 303 304
  template <class _InputIterator>
  hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
                const hasher& __hf, const key_equal& __eql,
                const allocator_type& __a = allocator_type())
    : _M_ht(__n, __hf, __eql, __a)
305 306 307
  {
    _M_ht.insert_equal(__f, __l);
  }
308 309 310 311 312 313 314

public:
  size_type size() const { return _M_ht.size(); }
  size_type max_size() const { return _M_ht.max_size(); }
  bool empty() const { return _M_ht.empty(); }
  void swap(hash_multiset& hs) { _M_ht.swap(hs._M_ht); }

315
  friend bool operator==<>(const hash_multiset&, const hash_multiset&);
316 317 318 319 320 321

  iterator begin() const { return _M_ht.begin(); }
  iterator end() const { return _M_ht.end(); }

public:
  iterator insert(const value_type& __obj)
322 323 324
  {
    return _M_ht.insert_equal(__obj);
  }
325 326
  template <class _InputIterator>
  void insert(_InputIterator __f, _InputIterator __l)
327 328 329
  {
    _M_ht.insert_equal(__f, __l);
  }
330
  iterator insert_noresize(const value_type& __obj)
331 332 333
  {
    return _M_ht.insert_equal_noresize(__obj);
  }
334 335 336 337 338

  iterator find(const key_type& __key) const { return _M_ht.find(__key); }

  size_type count(const key_type& __key) const { return _M_ht.count(__key); }

Brad King's avatar
Brad King committed
339
  std::pair<iterator, iterator> equal_range(const key_type& __key) const
340 341 342
  {
    return _M_ht.equal_range(__key);
  }
343

344
  size_type erase(const key_type& __key) { return _M_ht.erase(__key); }
345 346 347 348 349 350 351 352 353
  void erase(iterator __it) { _M_ht.erase(__it); }
  void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
  void clear() { _M_ht.clear(); }

public:
  void resize(size_type __hint) { _M_ht.resize(__hint); }
  size_type bucket_count() const { return _M_ht.bucket_count(); }
  size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
  size_type elems_in_bucket(size_type __n) const
354 355 356
  {
    return _M_ht.elems_in_bucket(__n);
  }
357 358 359
};

template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
360 361
bool operator==(const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1,
                const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2)
362 363 364 365 366
{
  return __hs1._M_ht == __hs2._M_ht;
}

template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
367 368 369 370
inline bool operator!=(
  const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1,
  const hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2)
{
371 372 373 374
  return !(__hs1 == __hs2);
}

template <class _Val, class _HashFcn, class _EqualKey, class _Alloc>
375 376 377
inline void swap(hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1,
                 hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs2)
{
378 379 380 381 382 383
  __hs1.swap(__hs2);
}

} // namespace @KWSYS_NAMESPACE@

#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
384 385
#pragma reset woff 1174
#pragma reset woff 1375
386 387 388
#endif

#if defined(_MSC_VER)
389
#pragma warning(pop)
390 391 392
#endif

#endif