1 // Copyright (C) 2001-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // This library is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
25 // Under Section 7 of GPL version 3, you are granted additional
26 // permissions described in the GCC Runtime Library Exception, version
27 // 3.1, as published by the Free Software Foundation.
29 // You should have received a copy of the GNU General Public License and
30 // a copy of the GCC Runtime Library Exception along with this program;
31 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
32 // <http://www.gnu.org/licenses/>.
36 * Silicon Graphics Computer Systems, Inc.
38 * Permission to use, copy, modify, distribute and sell this software
39 * and its documentation for any purpose is hereby granted without fee,
40 * provided that the above copyright notice appear in all copies and
41 * that both that copyright notice and this permission notice appear
42 * in supporting documentation. Silicon Graphics makes no
43 * representations about the suitability of this software for any
44 * purpose. It is provided "as is" without express or implied warranty.
48 * Hewlett-Packard Company
50 * Permission to use, copy, modify, distribute and sell this software
51 * and its documentation for any purpose is hereby granted without fee,
52 * provided that the above copyright notice appear in all copies and
53 * that both that copyright notice and this permission notice appear
54 * in supporting documentation. Hewlett-Packard Company makes no
55 * representations about the suitability of this software for any
56 * purpose. It is provided "as is" without express or implied warranty.
59 #ifndef __INTERPKERNELHASHMAP__
60 #define __INTERPKERNELHASHMAP__
62 #include "InterpKernelStlExt.hxx"
63 #include "InterpKernelHashTable.hxx"
65 namespace INTERP_KERNEL
67 template<class _Key, class _Tp, class _HashFn = hash<_Key>,
68 class _EqualKey = std::equal_to<_Key>, class _Alloc = std::allocator<_Tp> >
72 typedef hashtable<std::pair<const _Key, _Tp>,_Key, _HashFn,
73 STLEXT::Select1st<std::pair<const _Key, _Tp> >,
74 _EqualKey, _Alloc> _Ht;
79 typedef typename _Ht::key_type key_type;
80 typedef _Tp data_type;
81 typedef _Tp mapped_type;
82 typedef typename _Ht::value_type value_type;
83 typedef typename _Ht::hasher hasher;
84 typedef typename _Ht::key_equal key_equal;
86 typedef typename _Ht::size_type size_type;
87 typedef typename _Ht::difference_type difference_type;
88 typedef typename _Ht::pointer pointer;
89 typedef typename _Ht::const_pointer const_pointer;
90 typedef typename _Ht::reference reference;
91 typedef typename _Ht::const_reference const_reference;
93 typedef typename _Ht::iterator iterator;
94 typedef typename _Ht::const_iterator const_iterator;
96 typedef typename _Ht::allocator_type allocator_type;
98 hasher hash_funct() const { return _M_ht.hash_funct(); }
100 key_equal key_eq() const { return _M_ht.key_eq(); }
102 allocator_type get_allocator() const { return _M_ht.get_allocator(); }
104 HashMap() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
106 explicit HashMap(size_type __n) : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
108 HashMap(size_type __n, const hasher& __hf) : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
110 HashMap(size_type __n, const hasher& __hf, const key_equal& __eql,
111 const allocator_type& __a = allocator_type()) : _M_ht(__n, __hf, __eql, __a) {}
113 template<class _InputIterator>
114 HashMap(_InputIterator __f, _InputIterator __l) : _M_ht(100, hasher(), key_equal(), allocator_type())
115 { _M_ht.insert_unique(__f, __l); }
117 template<class _InputIterator>
118 HashMap(_InputIterator __f, _InputIterator __l, size_type __n) : _M_ht(__n, hasher(), key_equal(), allocator_type())
119 { _M_ht.insert_unique(__f, __l); }
121 template<class _InputIterator>
122 HashMap(_InputIterator __f, _InputIterator __l, size_type __n, const hasher& __hf)
123 : _M_ht(__n, __hf, key_equal(), allocator_type())
124 { _M_ht.insert_unique(__f, __l); }
126 template<class _InputIterator>
127 HashMap(_InputIterator __f, _InputIterator __l, size_type __n,
128 const hasher& __hf, const key_equal& __eql,
129 const allocator_type& __a = allocator_type()) : _M_ht(__n, __hf, __eql, __a)
130 { _M_ht.insert_unique(__f, __l); }
132 size_type size() const { return _M_ht.size(); }
134 size_type max_size() const { return _M_ht.max_size(); }
136 bool empty() const { return _M_ht.empty(); }
138 void swap(HashMap& __hs) { _M_ht.swap(__hs._M_ht); }
140 template<class _K1, class _T1, class _HF, class _EqK, class _Al>
141 friend bool operator== (const HashMap<_K1, _T1, _HF, _EqK, _Al>&,
142 const HashMap<_K1, _T1, _HF, _EqK, _Al>&);
144 iterator begin() { return _M_ht.begin(); }
146 iterator end() { return _M_ht.end(); }
148 const_iterator begin() const { return _M_ht.begin(); }
150 const_iterator end() const { return _M_ht.end(); }
152 std::pair<iterator, bool> insert(const value_type& __obj) { return _M_ht.insert_unique(__obj); }
154 template<class _InputIterator>
155 void insert(_InputIterator __f, _InputIterator __l) { _M_ht.insert_unique(__f, __l); }
157 std::pair<iterator, bool>
158 insert_noresize(const value_type& __obj) { return _M_ht.insert_unique_noresize(__obj); }
160 iterator find(const key_type& __key) { return _M_ht.find(__key); }
162 const_iterator find(const key_type& __key) const { return _M_ht.find(__key); }
164 _Tp& operator[](const key_type& __key) { return _M_ht.find_or_insert(value_type(__key, _Tp())).second; }
166 size_type count(const key_type& __key) const { return _M_ht.count(__key); }
168 std::pair<iterator, iterator> equal_range(const key_type& __key) { return _M_ht.equal_range(__key); }
170 std::pair<const_iterator, const_iterator> equal_range(const key_type& __key) const { return _M_ht.equal_range(__key); }
172 size_type erase(const key_type& __key) { return _M_ht.erase(__key); }
174 void erase(iterator __it) { _M_ht.erase(__it); }
176 void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
178 void clear() { _M_ht.clear(); }
180 void resize(size_type __hint) { _M_ht.resize(__hint); }
182 size_type bucket_count() const { return _M_ht.bucket_count(); }
184 size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
186 size_type elems_in_bucket(size_type __n) const { return _M_ht.elems_in_bucket(__n); }
189 template<class _Key, class _Tp, class _HashFn, class _EqlKey, class _Alloc>
190 inline bool operator==(const HashMap<_Key, _Tp, _HashFn, _EqlKey, _Alloc>& __hm1,
191 const HashMap<_Key, _Tp, _HashFn, _EqlKey, _Alloc>& __hm2)
192 { return __hm1._M_ht == __hm2._M_ht; }
194 template<class _Key, class _Tp, class _HashFn, class _EqlKey, class _Alloc>
195 inline bool operator!=(const HashMap<_Key, _Tp, _HashFn, _EqlKey, _Alloc>& __hm1,
196 const HashMap<_Key, _Tp, _HashFn, _EqlKey, _Alloc>& __hm2)
197 { return !(__hm1 == __hm2); }
199 template<class _Key, class _Tp, class _HashFn, class _EqlKey, class _Alloc>
200 inline void swap(HashMap<_Key, _Tp, _HashFn, _EqlKey, _Alloc>& __hm1,
201 HashMap<_Key, _Tp, _HashFn, _EqlKey, _Alloc>& __hm2)
202 { __hm1.swap(__hm2); }
204 template<class _Key, class _Tp,
205 class _HashFn = hash<_Key>,
206 class _EqualKey = std::equal_to<_Key>,
207 class _Alloc = std::allocator<_Tp> >
211 typedef hashtable<std::pair<const _Key, _Tp>, _Key, _HashFn,
212 STLEXT::Select1st<std::pair<const _Key, _Tp> >, _EqualKey, _Alloc>
216 typedef typename _Ht::key_type key_type;
217 typedef _Tp data_type;
218 typedef _Tp mapped_type;
219 typedef typename _Ht::value_type value_type;
220 typedef typename _Ht::hasher hasher;
221 typedef typename _Ht::key_equal key_equal;
223 typedef typename _Ht::size_type size_type;
224 typedef typename _Ht::difference_type difference_type;
225 typedef typename _Ht::pointer pointer;
226 typedef typename _Ht::const_pointer const_pointer;
227 typedef typename _Ht::reference reference;
228 typedef typename _Ht::const_reference const_reference;
230 typedef typename _Ht::iterator iterator;
231 typedef typename _Ht::const_iterator const_iterator;
233 typedef typename _Ht::allocator_type allocator_type;
235 hasher hash_funct() const { return _M_ht.hash_funct(); }
237 key_equal key_eq() const { return _M_ht.key_eq(); }
239 allocator_type get_allocator() const { return _M_ht.get_allocator(); }
241 HashMultiMap() : _M_ht(100, hasher(), key_equal(), allocator_type()) { }
243 explicit HashMultiMap(size_type __n) : _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
245 HashMultiMap(size_type __n, const hasher& __hf) : _M_ht(__n, __hf, key_equal(), allocator_type()) {}
247 HashMultiMap(size_type __n, const hasher& __hf, const key_equal& __eql,
248 const allocator_type& __a = allocator_type()) : _M_ht(__n, __hf, __eql, __a) {}
250 template<class _InputIterator>
251 HashMultiMap(_InputIterator __f, _InputIterator __l) : _M_ht(100, hasher(), key_equal(), allocator_type())
252 { _M_ht.insert_equal(__f, __l); }
254 template<class _InputIterator>
255 HashMultiMap(_InputIterator __f, _InputIterator __l, size_type __n) : _M_ht(__n, hasher(), key_equal(), allocator_type())
256 { _M_ht.insert_equal(__f, __l); }
258 template<class _InputIterator>
259 HashMultiMap(_InputIterator __f, _InputIterator __l, size_type __n, const hasher& __hf)
260 : _M_ht(__n, __hf, key_equal(), allocator_type())
261 { _M_ht.insert_equal(__f, __l); }
263 template<class _InputIterator>
264 HashMultiMap(_InputIterator __f, _InputIterator __l, size_type __n,
265 const hasher& __hf, const key_equal& __eql,
266 const allocator_type& __a = allocator_type())
267 : _M_ht(__n, __hf, __eql, __a)
268 { _M_ht.insert_equal(__f, __l); }
270 size_type size() const { return _M_ht.size(); }
272 size_type max_size() const { return _M_ht.max_size(); }
274 bool empty() const { return _M_ht.empty(); }
276 void swap(HashMultiMap& __hs) { _M_ht.swap(__hs._M_ht); }
278 template<class _K1, class _T1, class _HF, class _EqK, class _Al>
279 friend bool operator==(const HashMultiMap<_K1, _T1, _HF, _EqK, _Al>&,
280 const HashMultiMap<_K1, _T1, _HF, _EqK, _Al>&);
282 iterator begin() { return _M_ht.begin(); }
284 iterator end() { return _M_ht.end(); }
286 const_iterator begin() const { return _M_ht.begin(); }
288 const_iterator end() const { return _M_ht.end(); }
290 iterator insert(const value_type& __obj) { return _M_ht.insert_equal(__obj); }
292 template<class _InputIterator>
293 void insert(_InputIterator __f, _InputIterator __l) { _M_ht.insert_equal(__f,__l); }
295 iterator insert_noresize(const value_type& __obj) { return _M_ht.insert_equal_noresize(__obj); }
297 iterator find(const key_type& __key) { return _M_ht.find(__key); }
299 const_iterator find(const key_type& __key) const { return _M_ht.find(__key); }
301 size_type count(const key_type& __key) const { return _M_ht.count(__key); }
303 std::pair<iterator, iterator> equal_range(const key_type& __key) { return _M_ht.equal_range(__key); }
305 std::pair<const_iterator, const_iterator> equal_range(const key_type& __key) const { return _M_ht.equal_range(__key); }
307 size_type erase(const key_type& __key) { return _M_ht.erase(__key); }
309 void erase(iterator __it) { _M_ht.erase(__it); }
311 void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
313 void clear() { _M_ht.clear(); }
315 void resize(size_type __hint) { _M_ht.resize(__hint); }
317 size_type bucket_count() const { return _M_ht.bucket_count(); }
319 size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
321 size_type elems_in_bucket(size_type __n) const { return _M_ht.elems_in_bucket(__n); }
324 template<class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
325 inline bool operator==(const HashMultiMap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm1,
326 const HashMultiMap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm2)
327 { return __hm1._M_ht == __hm2._M_ht; }
329 template<class _Key, class _Tp, class _HF, class _EqKey, class _Alloc>
330 inline bool operator!=(const HashMultiMap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm1,
331 const HashMultiMap<_Key, _Tp, _HF, _EqKey, _Alloc>& __hm2)
332 { return !(__hm1 == __hm2); }
334 template<class _Key, class _Tp, class _HashFn, class _EqlKey, class _Alloc>
335 inline void swap(HashMultiMap<_Key, _Tp, _HashFn, _EqlKey, _Alloc>& __hm1,
336 HashMultiMap<_Key, _Tp, _HashFn, _EqlKey, _Alloc>& __hm2)
337 { __hm1.swap(__hm2); }
343 // Specialization of insert_iterator so that it will work for HashMap
345 template<class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
346 class insert_iterator<INTERP_KERNEL::HashMap<_Key, _Tp, _HashFn,
350 typedef INTERP_KERNEL::HashMap<_Key, _Tp, _HashFn, _EqKey, _Alloc>
352 _Container* container;
354 typedef _Container container_type;
355 typedef output_iterator_tag iterator_category;
356 typedef void value_type;
357 typedef void difference_type;
358 typedef void pointer;
359 typedef void reference;
361 insert_iterator(_Container& __x) : container(&__x) {}
363 insert_iterator(_Container& __x, typename _Container::iterator) : container(&__x) {}
365 insert_iterator<_Container>& operator=(const typename _Container::value_type& __value__)
367 container->insert(__value__);
371 insert_iterator<_Container>& operator*() { return *this; }
373 insert_iterator<_Container>& operator++() { return *this; }
375 insert_iterator<_Container>& operator++(int) { return *this; }
378 template<class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
379 class insert_iterator<INTERP_KERNEL::HashMultiMap<_Key, _Tp, _HashFn,
383 typedef INTERP_KERNEL::HashMultiMap<_Key, _Tp, _HashFn, _EqKey, _Alloc>
385 _Container* container;
386 typename _Container::iterator iter;
389 typedef _Container container_type;
390 typedef output_iterator_tag iterator_category;
391 typedef void value_type;
392 typedef void difference_type;
393 typedef void pointer;
394 typedef void reference;
396 insert_iterator(_Container& __x) : container(&__x) {}
398 insert_iterator(_Container& __x, typename _Container::iterator) : container(&__x) {}
400 insert_iterator<_Container>& operator=(const typename _Container::value_type& __value__)
402 container->insert(__value__);
406 insert_iterator<_Container>& operator*() { return *this; }
408 insert_iterator<_Container>& operator++() { return *this; }
410 insert_iterator<_Container>& operator++(int) { return *this; }