2005-12-18 Benjamin Kosnik <bkoz@redhat.com>
[official-gcc.git] / libstdc++-v3 / include / tr1 / unordered_set
blobc3c16ddc6d798de329a558e3dca648d436a50a07
1 // TR1 unordered_set -*- C++ -*-
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 /** @file 
31  *  This is a TR1 C++ Library header. 
32  */
34 #ifndef GNU_LIBSTDCXX_TR1_UNORDERED_SET_
35 #define GNU_LIBSTDCXX_TR1_UNORDERED_SET_
37 #include <tr1/hashtable>
38 #include <tr1/functional>
39 #include <memory>
41 namespace std
42
43 _GLIBCXX_BEGIN_NAMESPACE(tr1)
45   // XXX When we get typedef templates these class definitions
46   // will be unnecessary.
48   template<class Value,
49            class Hash = hash<Value>,
50            class Pred = std::equal_to<Value>,
51            class Alloc = std::allocator<Value>,
52            bool cache_hash_code = false>
53     class unordered_set
54     : public hashtable<Value, Value, Alloc,
55                        Internal::identity<Value>, Pred,
56                        Hash, Internal::mod_range_hashing,
57                        Internal::default_ranged_hash,
58                        Internal::prime_rehash_policy,
59                        cache_hash_code, true, true>
60     {
61       typedef hashtable<Value, Value, Alloc,
62                         Internal::identity<Value>, Pred,
63                         Hash, Internal::mod_range_hashing,
64                         Internal::default_ranged_hash,
65                         Internal::prime_rehash_policy,
66                         cache_hash_code, true, true>
67         Base;
69     public:
70       typedef typename Base::size_type size_type;
71       typedef typename Base::hasher hasher;
72       typedef typename Base::key_equal key_equal;
73       typedef typename Base::allocator_type allocator_type;
74       
75       explicit
76       unordered_set(size_type n = 10,
77                     const hasher& hf = hasher(),
78                     const key_equal& eql = key_equal(),
79                     const allocator_type& a = allocator_type())
80       : Base (n, hf, Internal::mod_range_hashing(),
81               Internal::default_ranged_hash(),
82               eql, Internal::identity<Value>(), a)
83       { }
85       template<typename InputIterator>
86         unordered_set(InputIterator f, InputIterator l, 
87                       size_type n = 10,
88                       const hasher& hf = hasher(), 
89                       const key_equal& eql = key_equal(), 
90                       const allocator_type& a = allocator_type())
91         : Base (f, l, n, hf, Internal::mod_range_hashing(),
92                 Internal::default_ranged_hash(),
93                 eql, Internal::identity<Value>(), a)
94         { }
95     };
97   template<class Value,
98            class Hash = hash<Value>,
99            class Pred = std::equal_to<Value>,
100            class Alloc = std::allocator<Value>,
101            bool cache_hash_code = false>
102     class unordered_multiset
103     : public hashtable <Value, Value, Alloc,
104                         Internal::identity<Value>, Pred,
105                         Hash, Internal::mod_range_hashing,
106                         Internal::default_ranged_hash,
107                         Internal::prime_rehash_policy,
108                         cache_hash_code, true, false>
109     {
110       typedef hashtable<Value, Value, Alloc,
111                         Internal::identity<Value>, Pred,
112                         Hash, Internal::mod_range_hashing,
113                         Internal::default_ranged_hash,
114                         Internal::prime_rehash_policy,
115                         cache_hash_code, true, false>
116         Base;
118     public:
119       typedef typename Base::size_type size_type;
120       typedef typename Base::hasher hasher;
121       typedef typename Base::key_equal key_equal;
122       typedef typename Base::allocator_type allocator_type;
123       
124       explicit
125       unordered_multiset(size_type n = 10,
126                          const hasher& hf = hasher(),
127                          const key_equal& eql = key_equal(),
128                          const allocator_type& a = allocator_type())
129       : Base (n, hf, Internal::mod_range_hashing(),
130               Internal::default_ranged_hash(),
131               eql, Internal::identity<Value>(), a)
132       { }
135       template<typename InputIterator>
136         unordered_multiset(InputIterator f, InputIterator l, 
137                            typename Base::size_type n = 0,
138                            const hasher& hf = hasher(), 
139                            const key_equal& eql = key_equal(), 
140                            const allocator_type& a = allocator_type())
141         : Base (f, l, n, hf, Internal::mod_range_hashing(),
142                 Internal::default_ranged_hash(), eql,
143                 Internal::identity<Value>(), a)
144         { }
145     };
147   template<class Value, class Hash, class Pred, class Alloc,
148            bool cache_hash_code>
149     inline void
150     swap (unordered_set<Value, Hash, Pred, Alloc, cache_hash_code>& x,
151           unordered_set<Value, Hash, Pred, Alloc, cache_hash_code>& y)
152     { x.swap(y); }
154   template<class Value, class Hash, class Pred, class Alloc,
155            bool cache_hash_code>
156     inline void
157     swap(unordered_multiset<Value, Hash, Pred, Alloc, cache_hash_code>& x,
158          unordered_multiset<Value, Hash, Pred, Alloc, cache_hash_code>& y)
159    { x.swap(y); }
161 _GLIBCXX_END_NAMESPACE
164 #endif /* GNU_LIBSTDCXX_TR1_UNORDERED_SET_ */