unordered_set.h

Go to the documentation of this file.
00001 // unordered_set implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2010 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file bits/unordered_set.h
00026  *  This is an internal header file, included by other library headers.
00027  *  You should not attempt to use it directly.
00028  */
00029 
00030 #ifndef _UNORDERED_SET_H
00031 #define _UNORDERED_SET_H
00032 
00033 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
00034 
00035   // XXX When we get typedef templates these class definitions
00036   // will be unnecessary.
00037   template<class _Value,
00038        class _Hash = hash<_Value>,
00039        class _Pred = std::equal_to<_Value>,
00040        class _Alloc = std::allocator<_Value>,
00041        bool __cache_hash_code = false>
00042     class __unordered_set
00043     : public _Hashtable<_Value, _Value, _Alloc,
00044             std::_Identity<_Value>, _Pred,
00045             _Hash, __detail::_Mod_range_hashing,
00046             __detail::_Default_ranged_hash,
00047             __detail::_Prime_rehash_policy,
00048             __cache_hash_code, true, true>
00049     {
00050       typedef _Hashtable<_Value, _Value, _Alloc,
00051              std::_Identity<_Value>, _Pred,
00052              _Hash, __detail::_Mod_range_hashing,
00053              __detail::_Default_ranged_hash,
00054              __detail::_Prime_rehash_policy,
00055              __cache_hash_code, true, true>
00056         _Base;
00057 
00058     public:
00059       typedef typename _Base::size_type       size_type;
00060       typedef typename _Base::hasher          hasher;
00061       typedef typename _Base::key_equal       key_equal;
00062       typedef typename _Base::allocator_type  allocator_type;
00063       
00064       explicit
00065       __unordered_set(size_type __n = 10,
00066               const hasher& __hf = hasher(),
00067               const key_equal& __eql = key_equal(),
00068               const allocator_type& __a = allocator_type())
00069       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
00070           __detail::_Default_ranged_hash(), __eql,
00071           std::_Identity<_Value>(), __a)
00072       { }
00073 
00074       template<typename _InputIterator>
00075         __unordered_set(_InputIterator __f, _InputIterator __l, 
00076             size_type __n = 10,
00077             const hasher& __hf = hasher(), 
00078             const key_equal& __eql = key_equal(), 
00079             const allocator_type& __a = allocator_type())
00080     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
00081         __detail::_Default_ranged_hash(), __eql,
00082         std::_Identity<_Value>(), __a)
00083         { }
00084 
00085       __unordered_set(__unordered_set&& __x)
00086       : _Base(std::forward<_Base>(__x)) { }
00087     };
00088 
00089   template<class _Value,
00090        class _Hash = hash<_Value>,
00091        class _Pred = std::equal_to<_Value>,
00092        class _Alloc = std::allocator<_Value>,
00093        bool __cache_hash_code = false>
00094     class __unordered_multiset
00095     : public _Hashtable<_Value, _Value, _Alloc,
00096             std::_Identity<_Value>, _Pred,
00097             _Hash, __detail::_Mod_range_hashing,
00098             __detail::_Default_ranged_hash,
00099             __detail::_Prime_rehash_policy,
00100             __cache_hash_code, true, false>
00101     {
00102       typedef _Hashtable<_Value, _Value, _Alloc,
00103              std::_Identity<_Value>, _Pred,
00104              _Hash, __detail::_Mod_range_hashing,
00105              __detail::_Default_ranged_hash,
00106              __detail::_Prime_rehash_policy,
00107              __cache_hash_code, true, false>
00108         _Base;
00109 
00110     public:
00111       typedef typename _Base::size_type       size_type;
00112       typedef typename _Base::hasher          hasher;
00113       typedef typename _Base::key_equal       key_equal;
00114       typedef typename _Base::allocator_type  allocator_type;
00115       
00116       explicit
00117       __unordered_multiset(size_type __n = 10,
00118                const hasher& __hf = hasher(),
00119                const key_equal& __eql = key_equal(),
00120                const allocator_type& __a = allocator_type())
00121       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
00122           __detail::_Default_ranged_hash(), __eql,
00123           std::_Identity<_Value>(), __a)
00124       { }
00125 
00126 
00127       template<typename _InputIterator>
00128         __unordered_multiset(_InputIterator __f, _InputIterator __l, 
00129                  typename _Base::size_type __n = 0,
00130                  const hasher& __hf = hasher(), 
00131                  const key_equal& __eql = key_equal(), 
00132                  const allocator_type& __a = allocator_type())
00133     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
00134         __detail::_Default_ranged_hash(), __eql,
00135         std::_Identity<_Value>(), __a)
00136         { }
00137 
00138       __unordered_multiset(__unordered_multiset&& __x)
00139       : _Base(std::forward<_Base>(__x)) { }
00140     };
00141 
00142   template<class _Value, class _Hash, class _Pred, class _Alloc,
00143        bool __cache_hash_code>
00144     inline void
00145     swap(__unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __x,
00146      __unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __y)
00147     { __x.swap(__y); }
00148 
00149   template<class _Value, class _Hash, class _Pred, class _Alloc,
00150        bool __cache_hash_code>
00151     inline void
00152     swap(__unordered_multiset<_Value, _Hash, _Pred,
00153      _Alloc, __cache_hash_code>& __x,
00154      __unordered_multiset<_Value, _Hash, _Pred,
00155      _Alloc, __cache_hash_code>& __y)
00156     { __x.swap(__y); }
00157 
00158 
00159   /**
00160    *  @brief A standard container composed of unique keys (containing
00161    *  at most one of each key value) in which the elements' keys are
00162    *  the elements themselves.
00163    *
00164    *  @ingroup unordered_associative_containers
00165    *
00166    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00167    *  <a href="tables.html#xx">unordered associative container</a>
00168    *
00169    *  @param  Value  Type of key objects.
00170    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
00171    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
00172    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00173    */
00174   template<class _Value,
00175        class _Hash = hash<_Value>,
00176        class _Pred = std::equal_to<_Value>,
00177        class _Alloc = std::allocator<_Value> >
00178     class unordered_set
00179     : public __unordered_set<_Value, _Hash, _Pred, _Alloc>
00180     {
00181       typedef __unordered_set<_Value, _Hash, _Pred, _Alloc>  _Base;
00182 
00183     public:
00184       typedef typename _Base::value_type      value_type;
00185       typedef typename _Base::size_type       size_type;
00186       typedef typename _Base::hasher          hasher;
00187       typedef typename _Base::key_equal       key_equal;
00188       typedef typename _Base::allocator_type  allocator_type;
00189       
00190       explicit
00191       unordered_set(size_type __n = 10,
00192             const hasher& __hf = hasher(),
00193             const key_equal& __eql = key_equal(),
00194             const allocator_type& __a = allocator_type())
00195       : _Base(__n, __hf, __eql, __a)
00196       { }
00197 
00198       template<typename _InputIterator>
00199         unordered_set(_InputIterator __f, _InputIterator __l, 
00200               size_type __n = 10,
00201               const hasher& __hf = hasher(), 
00202               const key_equal& __eql = key_equal(), 
00203               const allocator_type& __a = allocator_type())
00204     : _Base(__f, __l, __n, __hf, __eql, __a)
00205         { }
00206 
00207       unordered_set(unordered_set&& __x)
00208       : _Base(std::forward<_Base>(__x)) { }
00209 
00210       unordered_set(initializer_list<value_type> __l,
00211             size_type __n = 10,
00212             const hasher& __hf = hasher(),
00213             const key_equal& __eql = key_equal(),
00214             const allocator_type& __a = allocator_type())
00215     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
00216       { }
00217 
00218       unordered_set&
00219       operator=(unordered_set&& __x)
00220       {
00221     // NB: DR 1204.
00222     // NB: DR 675.
00223     this->clear();
00224     this->swap(__x);
00225     return *this;   
00226       }
00227 
00228       unordered_set&
00229       operator=(initializer_list<value_type> __l)
00230       {
00231     this->clear();
00232     this->insert(__l.begin(), __l.end());
00233     return *this;
00234       }
00235     };
00236 
00237   /**
00238    *  @brief A standard container composed of equivalent keys
00239    *  (possibly containing multiple of each key value) in which the
00240    *  elements' keys are the elements themselves.
00241    *
00242    *  @ingroup unordered_associative_containers
00243    *
00244    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00245    *  <a href="tables.html#xx">unordered associative container</a>
00246    *
00247    *  @param  Value  Type of key objects.
00248    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
00249    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
00250    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00251    */
00252   template<class _Value,
00253        class _Hash = hash<_Value>,
00254        class _Pred = std::equal_to<_Value>,
00255        class _Alloc = std::allocator<_Value> >
00256     class unordered_multiset
00257     : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc>
00258     {
00259       typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc>  _Base;
00260 
00261     public:
00262       typedef typename _Base::value_type      value_type;
00263       typedef typename _Base::size_type       size_type;
00264       typedef typename _Base::hasher          hasher;
00265       typedef typename _Base::key_equal       key_equal;
00266       typedef typename _Base::allocator_type  allocator_type;
00267       
00268       explicit
00269       unordered_multiset(size_type __n = 10,
00270              const hasher& __hf = hasher(),
00271              const key_equal& __eql = key_equal(),
00272              const allocator_type& __a = allocator_type())
00273       : _Base(__n, __hf, __eql, __a)
00274       { }
00275 
00276 
00277       template<typename _InputIterator>
00278         unordered_multiset(_InputIterator __f, _InputIterator __l, 
00279                typename _Base::size_type __n = 0,
00280                const hasher& __hf = hasher(), 
00281                const key_equal& __eql = key_equal(), 
00282                const allocator_type& __a = allocator_type())
00283     : _Base(__f, __l, __n, __hf, __eql, __a)
00284         { }
00285 
00286       unordered_multiset(unordered_multiset&& __x)
00287       : _Base(std::forward<_Base>(__x)) { }
00288 
00289       unordered_multiset(initializer_list<value_type> __l,
00290              size_type __n = 10,
00291              const hasher& __hf = hasher(),
00292              const key_equal& __eql = key_equal(),
00293              const allocator_type& __a = allocator_type())
00294     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
00295       { }
00296 
00297       unordered_multiset&
00298       operator=(unordered_multiset&& __x)
00299       {
00300     // NB: DR 1204.
00301     // NB: DR 675.
00302     this->clear();
00303     this->swap(__x);
00304     return *this;   
00305       }
00306 
00307       unordered_multiset&
00308       operator=(initializer_list<value_type> __l)
00309       {
00310     this->clear();
00311     this->insert(__l.begin(), __l.end());
00312     return *this;
00313       }
00314     };
00315 
00316   template<class _Value, class _Hash, class _Pred, class _Alloc>
00317     inline void
00318     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
00319      unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
00320     { __x.swap(__y); }
00321 
00322   template<class _Value, class _Hash, class _Pred, class _Alloc>
00323     inline void
00324     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
00325      unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
00326     { __x.swap(__y); }
00327 
00328 _GLIBCXX_END_NESTED_NAMESPACE
00329 
00330 #endif /* _UNORDERED_SET_H */
00331 

Generated on 12 Mar 2010 for libstdc++ by  doxygen 1.6.1