# unordered_set

Go to the documentation of this file.

    00001 // TR1 unordered_set -*- C++ -*-
    00002
    00003 // Copyright (C) 2005 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 2, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 /** @file
    00031  *  This is a TR1 C++ Library header.
    00032  */
    00033
    00034 #ifndef GNU_LIBSTDCXX_TR1_UNORDERED_SET_
    00035 #define GNU_LIBSTDCXX_TR1_UNORDERED_SET_
    00036
    00037 #include <tr1/hashtable>
    00038 #include <tr1/functional>
    00039 #include <memory>
    00040
    00041 namespace std { namespace tr1 {
    00042
    00043 // XXX When we get typedef templates these class definitions will be unnecessary.
    00044
    00045 template <class Value,
    00046       class Hash = hash<Value>,
    00047       class Pred = std::equal_to<Value>,
    00048       class Alloc = std::allocator<Value>,
    00049       bool cache_hash_code = false>
    00050 class unordered_set
    00051   : public hashtable <Value, Value, Alloc,
    00052               Internal::identity<Value>, Pred,
    00053               Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
    00054               Internal::prime_rehash_policy,
    00055               cache_hash_code, false, true>
    00056 {
    00057   typedef hashtable <Value, Value, Alloc,
    00058               Internal::identity<Value>, Pred,
    00059               Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
    00060               Internal::prime_rehash_policy,
    00061               cache_hash_code, false, true>
    00062           Base;
    00063
    00064 public:
    00065   typedef typename Base::size_type size_type;
    00066   typedef typename Base::hasher hasher;
    00067   typedef typename Base::key_equal key_equal;
    00068   typedef typename Base::allocator_type allocator_type;
    00069
    00070   explicit unordered_set(size_type n = 10,
    00071              const hasher& hf = hasher(),
    00072              const key_equal& eql = key_equal(),
    00073              const allocator_type& a = allocator_type())
    00074     : Base (n,
    00075         hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
    00076         eql, Internal::identity<Value>(),
    00077         a)
    00078   { }
    00079
    00080   template <typename InputIterator>
    00081   unordered_set(InputIterator f, InputIterator l,
    00082         size_type n = 10,
    00083         const hasher& hf = hasher(),
    00084         const key_equal& eql = key_equal(),
    00085         const allocator_type& a = allocator_type())
    00086     : Base (f, l,
    00087         n,
    00088         hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
    00089         eql, Internal::identity<Value>(),
    00090         a)
    00091         { }
    00092 };
    00093
    00094 template <class Value,
    00095       class Hash = hash<Value>,
    00096       class Pred = std::equal_to<Value>,
    00097       class Alloc = std::allocator<Value>,
    00098       bool cache_hash_code = false>
    00099 class unordered_multiset
    00100   : public hashtable <Value, Value, Alloc,
    00101               Internal::identity<Value>, Pred,
    00102               Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
    00103               Internal::prime_rehash_policy,
    00104               cache_hash_code, false, false>
    00105 {
    00106   typedef hashtable <Value, Value, Alloc,
    00107               Internal::identity<Value>, Pred,
    00108               Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
    00109               Internal::prime_rehash_policy,
    00110               cache_hash_code, false, false>
    00111           Base;
    00112
    00113 public:
    00114   typedef typename Base::size_type size_type;
    00115   typedef typename Base::hasher hasher;
    00116   typedef typename Base::key_equal key_equal;
    00117   typedef typename Base::allocator_type allocator_type;
    00118
    00119   explicit unordered_multiset(size_type n = 10,
    00120                   const hasher& hf = hasher(),
    00121                   const key_equal& eql = key_equal(),
    00122                   const allocator_type& a = allocator_type())
    00123     : Base (n,
    00124         hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
    00125         eql, Internal::identity<Value>(),
    00126         a)
    00127   { }
    00128
    00129
    00130   template <typename InputIterator>
    00131   unordered_multiset(InputIterator f, InputIterator l,
    00132              typename Base::size_type n = 0,
    00133              const hasher& hf = hasher(),
    00134              const key_equal& eql = key_equal(),
    00135              const allocator_type& a = allocator_type())
    00136     : Base (f, l,
    00137         n,
    00138         hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
    00139         eql, Internal::identity<Value>(),
    00140         a)
    00141   { }
    00142 };
    00143
    00144 template <class Value, class Hash, class Pred, class Alloc, bool cache_hash_code>
    00145 inline void swap (unordered_set<Value, Hash, Pred, Alloc, cache_hash_code>& x,
    00146           unordered_set<Value, Hash, Pred, Alloc, cache_hash_code>& y)
    00147 {
    00148   x.swap(y);
    00149 }
    00150
    00151 template <class Value, class Hash, class Pred, class Alloc, bool cache_hash_code>
    00152 inline void swap (unordered_multiset<Value, Hash, Pred, Alloc, cache_hash_code>& x,
    00153           unordered_multiset<Value, Hash, Pred, Alloc, cache_hash_code>& y)
    00154 {
    00155   x.swap(y);
    00156 }
    00157
    00158 } }
    00159
    00160 #endif /* GNU_LIBSTDCXX_TR1_UNORDERED_SET_ */