17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===------------------------- hash_set ------------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_HASH_SET
127a984708SDavid Chisnall#define _LIBCPP_HASH_SET
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall
167a984708SDavid Chisnall    hash_set synopsis
177a984708SDavid Chisnall
187a984708SDavid Chisnallnamespace __gnu_cxx
197a984708SDavid Chisnall{
207a984708SDavid Chisnall
217a984708SDavid Chisnalltemplate <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
227a984708SDavid Chisnall          class Alloc = allocator<Value>>
237a984708SDavid Chisnallclass hash_set
247a984708SDavid Chisnall{
257a984708SDavid Chisnallpublic:
267a984708SDavid Chisnall    // types
277a984708SDavid Chisnall    typedef Value                                                      key_type;
287a984708SDavid Chisnall    typedef key_type                                                   value_type;
297a984708SDavid Chisnall    typedef Hash                                                       hasher;
307a984708SDavid Chisnall    typedef Pred                                                       key_equal;
317a984708SDavid Chisnall    typedef Alloc                                                      allocator_type;
327a984708SDavid Chisnall    typedef value_type&                                                reference;
337a984708SDavid Chisnall    typedef const value_type&                                          const_reference;
347a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::pointer         pointer;
357a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
367a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::size_type       size_type;
377a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
387a984708SDavid Chisnall
397a984708SDavid Chisnall    typedef /unspecified/ iterator;
407a984708SDavid Chisnall    typedef /unspecified/ const_iterator;
417a984708SDavid Chisnall
427a984708SDavid Chisnall    explicit hash_set(size_type n = 193, const hasher& hf = hasher(),
437a984708SDavid Chisnall                           const key_equal& eql = key_equal(),
447a984708SDavid Chisnall                           const allocator_type& a = allocator_type());
457a984708SDavid Chisnall    template <class InputIterator>
467a984708SDavid Chisnall        hash_set(InputIterator f, InputIterator l,
477a984708SDavid Chisnall                      size_type n = 193, const hasher& hf = hasher(),
487a984708SDavid Chisnall                      const key_equal& eql = key_equal(),
497a984708SDavid Chisnall                      const allocator_type& a = allocator_type());
507a984708SDavid Chisnall    hash_set(const hash_set&);
517a984708SDavid Chisnall    ~hash_set();
527a984708SDavid Chisnall    hash_set& operator=(const hash_set&);
537a984708SDavid Chisnall
547a984708SDavid Chisnall    allocator_type get_allocator() const;
557a984708SDavid Chisnall
567a984708SDavid Chisnall    bool      empty() const;
577a984708SDavid Chisnall    size_type size() const;
587a984708SDavid Chisnall    size_type max_size() const;
597a984708SDavid Chisnall
607a984708SDavid Chisnall    iterator       begin();
617a984708SDavid Chisnall    iterator       end();
627a984708SDavid Chisnall    const_iterator begin()  const;
637a984708SDavid Chisnall    const_iterator end()    const;
647a984708SDavid Chisnall
657a984708SDavid Chisnall    pair<iterator, bool> insert(const value_type& obj);
667a984708SDavid Chisnall    template <class InputIterator>
677a984708SDavid Chisnall        void insert(InputIterator first, InputIterator last);
687a984708SDavid Chisnall
697a984708SDavid Chisnall    void erase(const_iterator position);
707a984708SDavid Chisnall    size_type erase(const key_type& k);
717a984708SDavid Chisnall    void erase(const_iterator first, const_iterator last);
727a984708SDavid Chisnall    void clear();
737a984708SDavid Chisnall
747a984708SDavid Chisnall    void swap(hash_set&);
757a984708SDavid Chisnall
767a984708SDavid Chisnall    hasher hash_funct() const;
777a984708SDavid Chisnall    key_equal key_eq() const;
787a984708SDavid Chisnall
797a984708SDavid Chisnall    iterator       find(const key_type& k);
807a984708SDavid Chisnall    const_iterator find(const key_type& k) const;
817a984708SDavid Chisnall    size_type count(const key_type& k) const;
827a984708SDavid Chisnall    pair<iterator, iterator>             equal_range(const key_type& k);
837a984708SDavid Chisnall    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
847a984708SDavid Chisnall
857a984708SDavid Chisnall    size_type bucket_count() const;
867a984708SDavid Chisnall    size_type max_bucket_count() const;
877a984708SDavid Chisnall
887a984708SDavid Chisnall    size_type elems_in_bucket(size_type n) const;
897a984708SDavid Chisnall
907a984708SDavid Chisnall    void resize(size_type n);
917a984708SDavid Chisnall};
927a984708SDavid Chisnall
937a984708SDavid Chisnalltemplate <class Value, class Hash, class Pred, class Alloc>
947a984708SDavid Chisnall    void swap(hash_set<Value, Hash, Pred, Alloc>& x,
957a984708SDavid Chisnall              hash_set<Value, Hash, Pred, Alloc>& y);
967a984708SDavid Chisnall
977a984708SDavid Chisnalltemplate <class Value, class Hash, class Pred, class Alloc>
987a984708SDavid Chisnall    bool
997a984708SDavid Chisnall    operator==(const hash_set<Value, Hash, Pred, Alloc>& x,
1007a984708SDavid Chisnall               const hash_set<Value, Hash, Pred, Alloc>& y);
1017a984708SDavid Chisnall
1027a984708SDavid Chisnalltemplate <class Value, class Hash, class Pred, class Alloc>
1037a984708SDavid Chisnall    bool
1047a984708SDavid Chisnall    operator!=(const hash_set<Value, Hash, Pred, Alloc>& x,
1057a984708SDavid Chisnall               const hash_set<Value, Hash, Pred, Alloc>& y);
1067a984708SDavid Chisnall
1077a984708SDavid Chisnalltemplate <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
1087a984708SDavid Chisnall          class Alloc = allocator<Value>>
1097a984708SDavid Chisnallclass hash_multiset
1107a984708SDavid Chisnall{
1117a984708SDavid Chisnallpublic:
1127a984708SDavid Chisnall    // types
1137a984708SDavid Chisnall    typedef Value                                                      key_type;
1147a984708SDavid Chisnall    typedef key_type                                                   value_type;
1157a984708SDavid Chisnall    typedef Hash                                                       hasher;
1167a984708SDavid Chisnall    typedef Pred                                                       key_equal;
1177a984708SDavid Chisnall    typedef Alloc                                                      allocator_type;
1187a984708SDavid Chisnall    typedef value_type&                                                reference;
1197a984708SDavid Chisnall    typedef const value_type&                                          const_reference;
1207a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::pointer         pointer;
1217a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
1227a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::size_type       size_type;
1237a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
1247a984708SDavid Chisnall
1257a984708SDavid Chisnall    typedef /unspecified/ iterator;
1267a984708SDavid Chisnall    typedef /unspecified/ const_iterator;
1277a984708SDavid Chisnall
1287a984708SDavid Chisnall    explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(),
1297a984708SDavid Chisnall                           const key_equal& eql = key_equal(),
1307a984708SDavid Chisnall                           const allocator_type& a = allocator_type());
1317a984708SDavid Chisnall    template <class InputIterator>
1327a984708SDavid Chisnall        hash_multiset(InputIterator f, InputIterator l,
1337a984708SDavid Chisnall                      size_type n = 193, const hasher& hf = hasher(),
1347a984708SDavid Chisnall                      const key_equal& eql = key_equal(),
1357a984708SDavid Chisnall                      const allocator_type& a = allocator_type());
1367a984708SDavid Chisnall    hash_multiset(const hash_multiset&);
1377a984708SDavid Chisnall    ~hash_multiset();
1387a984708SDavid Chisnall    hash_multiset& operator=(const hash_multiset&);
1397a984708SDavid Chisnall
1407a984708SDavid Chisnall    allocator_type get_allocator() const;
1417a984708SDavid Chisnall
1427a984708SDavid Chisnall    bool      empty() const;
1437a984708SDavid Chisnall    size_type size() const;
1447a984708SDavid Chisnall    size_type max_size() const;
1457a984708SDavid Chisnall
1467a984708SDavid Chisnall    iterator       begin();
1477a984708SDavid Chisnall    iterator       end();
1487a984708SDavid Chisnall    const_iterator begin()  const;
1497a984708SDavid Chisnall    const_iterator end()    const;
1507a984708SDavid Chisnall
1517a984708SDavid Chisnall    iterator insert(const value_type& obj);
1527a984708SDavid Chisnall    template <class InputIterator>
1537a984708SDavid Chisnall        void insert(InputIterator first, InputIterator last);
1547a984708SDavid Chisnall
1557a984708SDavid Chisnall    void erase(const_iterator position);
1567a984708SDavid Chisnall    size_type erase(const key_type& k);
1577a984708SDavid Chisnall    void erase(const_iterator first, const_iterator last);
1587a984708SDavid Chisnall    void clear();
1597a984708SDavid Chisnall
1607a984708SDavid Chisnall    void swap(hash_multiset&);
1617a984708SDavid Chisnall
1627a984708SDavid Chisnall    hasher hash_funct() const;
1637a984708SDavid Chisnall    key_equal key_eq() const;
1647a984708SDavid Chisnall
1657a984708SDavid Chisnall    iterator       find(const key_type& k);
1667a984708SDavid Chisnall    const_iterator find(const key_type& k) const;
1677a984708SDavid Chisnall    size_type count(const key_type& k) const;
1687a984708SDavid Chisnall    pair<iterator, iterator>             equal_range(const key_type& k);
1697a984708SDavid Chisnall    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
1707a984708SDavid Chisnall
1717a984708SDavid Chisnall    size_type bucket_count() const;
1727a984708SDavid Chisnall    size_type max_bucket_count() const;
1737a984708SDavid Chisnall
1747a984708SDavid Chisnall    size_type elems_in_bucket(size_type n) const;
1757a984708SDavid Chisnall
1767a984708SDavid Chisnall    void resize(size_type n);
1777a984708SDavid Chisnall};
1787a984708SDavid Chisnall
1797a984708SDavid Chisnalltemplate <class Value, class Hash, class Pred, class Alloc>
1807a984708SDavid Chisnall    void swap(hash_multiset<Value, Hash, Pred, Alloc>& x,
1817a984708SDavid Chisnall              hash_multiset<Value, Hash, Pred, Alloc>& y);
1827a984708SDavid Chisnall
1837a984708SDavid Chisnalltemplate <class Value, class Hash, class Pred, class Alloc>
1847a984708SDavid Chisnall    bool
1857a984708SDavid Chisnall    operator==(const hash_multiset<Value, Hash, Pred, Alloc>& x,
1867a984708SDavid Chisnall               const hash_multiset<Value, Hash, Pred, Alloc>& y);
1877a984708SDavid Chisnall
1887a984708SDavid Chisnalltemplate <class Value, class Hash, class Pred, class Alloc>
1897a984708SDavid Chisnall    bool
1907a984708SDavid Chisnall    operator!=(const hash_multiset<Value, Hash, Pred, Alloc>& x,
1917a984708SDavid Chisnall               const hash_multiset<Value, Hash, Pred, Alloc>& y);
1927a984708SDavid Chisnall}  // __gnu_cxx
1937a984708SDavid Chisnall
1947a984708SDavid Chisnall*/
1957a984708SDavid Chisnall
1967a984708SDavid Chisnall#include <__config>
1977a984708SDavid Chisnall#include <__hash_table>
1987a984708SDavid Chisnall#include <functional>
1997a984708SDavid Chisnall#include <ext/__hash>
2007a984708SDavid Chisnall
2017a984708SDavid Chisnall#if __DEPRECATED
202*5517e702SDimitry Andric#if defined(_LIBCPP_WARNING)
2034f7ab58eSDimitry Andric    _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>")
2044f7ab58eSDimitry Andric#else
2057a984708SDavid Chisnall#   warning Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>
2067a984708SDavid Chisnall#endif
2074f7ab58eSDimitry Andric#endif
2087a984708SDavid Chisnall
2097a984708SDavid Chisnallnamespace __gnu_cxx {
2107a984708SDavid Chisnall
2117a984708SDavid Chisnallusing namespace std;
2127a984708SDavid Chisnall
2137a984708SDavid Chisnalltemplate <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
2147a984708SDavid Chisnall          class _Alloc = allocator<_Value> >
215aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS hash_set
2167a984708SDavid Chisnall{
2177a984708SDavid Chisnallpublic:
2187a984708SDavid Chisnall    // types
2197a984708SDavid Chisnall    typedef _Value                                                     key_type;
2207a984708SDavid Chisnall    typedef key_type                                                   value_type;
2217a984708SDavid Chisnall    typedef _Hash                                                      hasher;
2227a984708SDavid Chisnall    typedef _Pred                                                      key_equal;
2237a984708SDavid Chisnall    typedef _Alloc                                                     allocator_type;
2247a984708SDavid Chisnall    typedef value_type&                                                reference;
2257a984708SDavid Chisnall    typedef const value_type&                                          const_reference;
2267a984708SDavid Chisnall
2277a984708SDavid Chisnallprivate:
2287a984708SDavid Chisnall    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
2297a984708SDavid Chisnall
2307a984708SDavid Chisnall    __table __table_;
2317a984708SDavid Chisnall
2327a984708SDavid Chisnallpublic:
2337a984708SDavid Chisnall    typedef typename __table::pointer         pointer;
2347a984708SDavid Chisnall    typedef typename __table::const_pointer   const_pointer;
2357a984708SDavid Chisnall    typedef typename __table::size_type       size_type;
2367a984708SDavid Chisnall    typedef typename __table::difference_type difference_type;
2377a984708SDavid Chisnall
2387a984708SDavid Chisnall    typedef typename __table::const_iterator       iterator;
2397a984708SDavid Chisnall    typedef typename __table::const_iterator       const_iterator;
2407a984708SDavid Chisnall
2417a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2427a984708SDavid Chisnall    hash_set() {__table_.rehash(193);}
2437a984708SDavid Chisnall    explicit hash_set(size_type __n, const hasher& __hf = hasher(),
2447a984708SDavid Chisnall                           const key_equal& __eql = key_equal());
2457a984708SDavid Chisnall    hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
2467a984708SDavid Chisnall                  const allocator_type& __a);
2477a984708SDavid Chisnall    template <class _InputIterator>
2487a984708SDavid Chisnall        hash_set(_InputIterator __first, _InputIterator __last);
2497a984708SDavid Chisnall    template <class _InputIterator>
2507a984708SDavid Chisnall        hash_set(_InputIterator __first, _InputIterator __last,
2517a984708SDavid Chisnall                      size_type __n, const hasher& __hf = hasher(),
2527a984708SDavid Chisnall                      const key_equal& __eql = key_equal());
2537a984708SDavid Chisnall    template <class _InputIterator>
2547a984708SDavid Chisnall        hash_set(_InputIterator __first, _InputIterator __last,
2557a984708SDavid Chisnall                      size_type __n, const hasher& __hf, const key_equal& __eql,
2567a984708SDavid Chisnall                      const allocator_type& __a);
2577a984708SDavid Chisnall    hash_set(const hash_set& __u);
2587a984708SDavid Chisnall
2597a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2607a984708SDavid Chisnall    allocator_type get_allocator() const
2617a984708SDavid Chisnall        {return allocator_type(__table_.__node_alloc());}
2627a984708SDavid Chisnall
2637a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2647a984708SDavid Chisnall    bool      empty() const {return __table_.size() == 0;}
2657a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2667a984708SDavid Chisnall    size_type size() const  {return __table_.size();}
2677a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2687a984708SDavid Chisnall    size_type max_size() const {return __table_.max_size();}
2697a984708SDavid Chisnall
2707a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2717a984708SDavid Chisnall    iterator       begin()        {return __table_.begin();}
2727a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2737a984708SDavid Chisnall    iterator       end()          {return __table_.end();}
2747a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2757a984708SDavid Chisnall    const_iterator begin()  const {return __table_.begin();}
2767a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2777a984708SDavid Chisnall    const_iterator end()    const {return __table_.end();}
2787a984708SDavid Chisnall
2797a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2807a984708SDavid Chisnall    pair<iterator, bool> insert(const value_type& __x)
2817a984708SDavid Chisnall        {return __table_.__insert_unique(__x);}
2827a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2837a984708SDavid Chisnall    iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
2847a984708SDavid Chisnall    template <class _InputIterator>
2857c82a1ecSDimitry Andric        _LIBCPP_INLINE_VISIBILITY
2867a984708SDavid Chisnall        void insert(_InputIterator __first, _InputIterator __last);
2877a984708SDavid Chisnall
2887a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2897a984708SDavid Chisnall    void erase(const_iterator __p) {__table_.erase(__p);}
2907a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2917a984708SDavid Chisnall    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
2927a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2937a984708SDavid Chisnall    void erase(const_iterator __first, const_iterator __last)
2947a984708SDavid Chisnall        {__table_.erase(__first, __last);}
2957a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2967a984708SDavid Chisnall    void clear() {__table_.clear();}
2977a984708SDavid Chisnall
2987a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2997a984708SDavid Chisnall    void swap(hash_set& __u) {__table_.swap(__u.__table_);}
3007a984708SDavid Chisnall
3017a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3027a984708SDavid Chisnall    hasher hash_funct() const {return __table_.hash_function();}
3037a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3047a984708SDavid Chisnall    key_equal key_eq() const {return __table_.key_eq();}
3057a984708SDavid Chisnall
3067a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3077a984708SDavid Chisnall    iterator       find(const key_type& __k)       {return __table_.find(__k);}
3087a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3097a984708SDavid Chisnall    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
3107a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3117a984708SDavid Chisnall    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
3127a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3137a984708SDavid Chisnall    pair<iterator, iterator>             equal_range(const key_type& __k)
3147a984708SDavid Chisnall        {return __table_.__equal_range_unique(__k);}
3157a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3167a984708SDavid Chisnall    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
3177a984708SDavid Chisnall        {return __table_.__equal_range_unique(__k);}
3187a984708SDavid Chisnall
3197a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3207a984708SDavid Chisnall    size_type bucket_count() const {return __table_.bucket_count();}
3217a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3227a984708SDavid Chisnall    size_type max_bucket_count() const {return __table_.max_bucket_count();}
3237a984708SDavid Chisnall
3247a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3257a984708SDavid Chisnall    size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
3267a984708SDavid Chisnall
3277a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3287a984708SDavid Chisnall    void resize(size_type __n) {__table_.rehash(__n);}
3297a984708SDavid Chisnall};
3307a984708SDavid Chisnall
3317a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
3327a984708SDavid Chisnallhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
3337a984708SDavid Chisnall        const hasher& __hf, const key_equal& __eql)
3347a984708SDavid Chisnall    : __table_(__hf, __eql)
3357a984708SDavid Chisnall{
3367a984708SDavid Chisnall    __table_.rehash(__n);
3377a984708SDavid Chisnall}
3387a984708SDavid Chisnall
3397a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
3407a984708SDavid Chisnallhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
3417a984708SDavid Chisnall        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
3427a984708SDavid Chisnall    : __table_(__hf, __eql, __a)
3437a984708SDavid Chisnall{
3447a984708SDavid Chisnall    __table_.rehash(__n);
3457a984708SDavid Chisnall}
3467a984708SDavid Chisnall
3477a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
3487a984708SDavid Chisnalltemplate <class _InputIterator>
3497a984708SDavid Chisnallhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
3507a984708SDavid Chisnall        _InputIterator __first, _InputIterator __last)
3517a984708SDavid Chisnall{
3527a984708SDavid Chisnall    __table_.rehash(193);
3537a984708SDavid Chisnall    insert(__first, __last);
3547a984708SDavid Chisnall}
3557a984708SDavid Chisnall
3567a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
3577a984708SDavid Chisnalltemplate <class _InputIterator>
3587a984708SDavid Chisnallhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
3597a984708SDavid Chisnall        _InputIterator __first, _InputIterator __last, size_type __n,
3607a984708SDavid Chisnall        const hasher& __hf, const key_equal& __eql)
3617a984708SDavid Chisnall    : __table_(__hf, __eql)
3627a984708SDavid Chisnall{
3637a984708SDavid Chisnall    __table_.rehash(__n);
3647a984708SDavid Chisnall    insert(__first, __last);
3657a984708SDavid Chisnall}
3667a984708SDavid Chisnall
3677a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
3687a984708SDavid Chisnalltemplate <class _InputIterator>
3697a984708SDavid Chisnallhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
3707a984708SDavid Chisnall        _InputIterator __first, _InputIterator __last, size_type __n,
3717a984708SDavid Chisnall        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
3727a984708SDavid Chisnall    : __table_(__hf, __eql, __a)
3737a984708SDavid Chisnall{
3747a984708SDavid Chisnall    __table_.rehash(__n);
3757a984708SDavid Chisnall    insert(__first, __last);
3767a984708SDavid Chisnall}
3777a984708SDavid Chisnall
3787a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
3797a984708SDavid Chisnallhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
3807a984708SDavid Chisnall        const hash_set& __u)
3817a984708SDavid Chisnall    : __table_(__u.__table_)
3827a984708SDavid Chisnall{
3837a984708SDavid Chisnall    __table_.rehash(__u.bucket_count());
3847a984708SDavid Chisnall    insert(__u.begin(), __u.end());
3857a984708SDavid Chisnall}
3867a984708SDavid Chisnall
3877a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
3887a984708SDavid Chisnalltemplate <class _InputIterator>
3897c82a1ecSDimitry Andricinline
3907a984708SDavid Chisnallvoid
3917a984708SDavid Chisnallhash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
3927a984708SDavid Chisnall                                                    _InputIterator __last)
3937a984708SDavid Chisnall{
3947a984708SDavid Chisnall    for (; __first != __last; ++__first)
3957a984708SDavid Chisnall        __table_.__insert_unique(*__first);
3967a984708SDavid Chisnall}
3977a984708SDavid Chisnall
3987a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
3997a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4007a984708SDavid Chisnallvoid
4017a984708SDavid Chisnallswap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
4027a984708SDavid Chisnall     hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
4037a984708SDavid Chisnall{
4047a984708SDavid Chisnall    __x.swap(__y);
4057a984708SDavid Chisnall}
4067a984708SDavid Chisnall
4077a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
4087a984708SDavid Chisnallbool
4097a984708SDavid Chisnalloperator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
4107a984708SDavid Chisnall           const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
4117a984708SDavid Chisnall{
4127a984708SDavid Chisnall    if (__x.size() != __y.size())
4137a984708SDavid Chisnall        return false;
4147a984708SDavid Chisnall    typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
4157a984708SDavid Chisnall                                                                 const_iterator;
4167a984708SDavid Chisnall    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
4177a984708SDavid Chisnall            __i != __ex; ++__i)
4187a984708SDavid Chisnall    {
4197a984708SDavid Chisnall        const_iterator __j = __y.find(*__i);
4207a984708SDavid Chisnall        if (__j == __ey || !(*__i == *__j))
4217a984708SDavid Chisnall            return false;
4227a984708SDavid Chisnall    }
4237a984708SDavid Chisnall    return true;
4247a984708SDavid Chisnall}
4257a984708SDavid Chisnall
4267a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
4277a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4287a984708SDavid Chisnallbool
4297a984708SDavid Chisnalloperator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
4307a984708SDavid Chisnall           const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
4317a984708SDavid Chisnall{
4327a984708SDavid Chisnall    return !(__x == __y);
4337a984708SDavid Chisnall}
4347a984708SDavid Chisnall
4357a984708SDavid Chisnalltemplate <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
4367a984708SDavid Chisnall          class _Alloc = allocator<_Value> >
437aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS hash_multiset
4387a984708SDavid Chisnall{
4397a984708SDavid Chisnallpublic:
4407a984708SDavid Chisnall    // types
4417a984708SDavid Chisnall    typedef _Value                                                     key_type;
4427a984708SDavid Chisnall    typedef key_type                                                   value_type;
4437a984708SDavid Chisnall    typedef _Hash                                                      hasher;
4447a984708SDavid Chisnall    typedef _Pred                                                      key_equal;
4457a984708SDavid Chisnall    typedef _Alloc                                                     allocator_type;
4467a984708SDavid Chisnall    typedef value_type&                                                reference;
4477a984708SDavid Chisnall    typedef const value_type&                                          const_reference;
4487a984708SDavid Chisnall
4497a984708SDavid Chisnallprivate:
4507a984708SDavid Chisnall    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
4517a984708SDavid Chisnall
4527a984708SDavid Chisnall    __table __table_;
4537a984708SDavid Chisnall
4547a984708SDavid Chisnallpublic:
4557a984708SDavid Chisnall    typedef typename __table::pointer         pointer;
4567a984708SDavid Chisnall    typedef typename __table::const_pointer   const_pointer;
4577a984708SDavid Chisnall    typedef typename __table::size_type       size_type;
4587a984708SDavid Chisnall    typedef typename __table::difference_type difference_type;
4597a984708SDavid Chisnall
4607a984708SDavid Chisnall    typedef typename __table::const_iterator       iterator;
4617a984708SDavid Chisnall    typedef typename __table::const_iterator       const_iterator;
4627a984708SDavid Chisnall
4637a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4647a984708SDavid Chisnall    hash_multiset() {__table_.rehash(193);}
4657a984708SDavid Chisnall    explicit hash_multiset(size_type __n, const hasher& __hf = hasher(),
4667a984708SDavid Chisnall                                const key_equal& __eql = key_equal());
4677a984708SDavid Chisnall    hash_multiset(size_type __n, const hasher& __hf,
4687a984708SDavid Chisnall                       const key_equal& __eql, const allocator_type& __a);
4697a984708SDavid Chisnall    template <class _InputIterator>
4707a984708SDavid Chisnall        hash_multiset(_InputIterator __first, _InputIterator __last);
4717a984708SDavid Chisnall    template <class _InputIterator>
4727a984708SDavid Chisnall        hash_multiset(_InputIterator __first, _InputIterator __last,
4737a984708SDavid Chisnall                      size_type __n, const hasher& __hf = hasher(),
4747a984708SDavid Chisnall                      const key_equal& __eql = key_equal());
4757a984708SDavid Chisnall    template <class _InputIterator>
4767a984708SDavid Chisnall        hash_multiset(_InputIterator __first, _InputIterator __last,
4777a984708SDavid Chisnall                      size_type __n , const hasher& __hf,
4787a984708SDavid Chisnall                      const key_equal& __eql, const allocator_type& __a);
4797a984708SDavid Chisnall    hash_multiset(const hash_multiset& __u);
4807a984708SDavid Chisnall
4817a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4827a984708SDavid Chisnall    allocator_type get_allocator() const
4837a984708SDavid Chisnall        {return allocator_type(__table_.__node_alloc());}
4847a984708SDavid Chisnall
4857a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4867a984708SDavid Chisnall    bool      empty() const {return __table_.size() == 0;}
4877a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4887a984708SDavid Chisnall    size_type size() const  {return __table_.size();}
4897a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4907a984708SDavid Chisnall    size_type max_size() const {return __table_.max_size();}
4917a984708SDavid Chisnall
4927a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4937a984708SDavid Chisnall    iterator       begin()        {return __table_.begin();}
4947a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4957a984708SDavid Chisnall    iterator       end()          {return __table_.end();}
4967a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4977a984708SDavid Chisnall    const_iterator begin()  const {return __table_.begin();}
4987a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4997a984708SDavid Chisnall    const_iterator end()    const {return __table_.end();}
5007a984708SDavid Chisnall
5017a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5027a984708SDavid Chisnall    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
5037a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5047a984708SDavid Chisnall    iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
5057a984708SDavid Chisnall    template <class _InputIterator>
5067c82a1ecSDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5077a984708SDavid Chisnall        void insert(_InputIterator __first, _InputIterator __last);
5087a984708SDavid Chisnall
5097a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5107a984708SDavid Chisnall    void erase(const_iterator __p) {__table_.erase(__p);}
5117a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5127a984708SDavid Chisnall    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
5137a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5147a984708SDavid Chisnall    void erase(const_iterator __first, const_iterator __last)
5157a984708SDavid Chisnall        {__table_.erase(__first, __last);}
5167a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5177a984708SDavid Chisnall    void clear() {__table_.clear();}
5187a984708SDavid Chisnall
5197a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5207a984708SDavid Chisnall    void swap(hash_multiset& __u) {__table_.swap(__u.__table_);}
5217a984708SDavid Chisnall
5227a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5237a984708SDavid Chisnall    hasher hash_funct() const {return __table_.hash_function();}
5247a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5257a984708SDavid Chisnall    key_equal key_eq() const {return __table_.key_eq();}
5267a984708SDavid Chisnall
5277a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5287a984708SDavid Chisnall    iterator       find(const key_type& __k)       {return __table_.find(__k);}
5297a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5307a984708SDavid Chisnall    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
5317a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5327a984708SDavid Chisnall    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
5337a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5347a984708SDavid Chisnall    pair<iterator, iterator>             equal_range(const key_type& __k)
5357a984708SDavid Chisnall        {return __table_.__equal_range_multi(__k);}
5367a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5377a984708SDavid Chisnall    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
5387a984708SDavid Chisnall        {return __table_.__equal_range_multi(__k);}
5397a984708SDavid Chisnall
5407a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5417a984708SDavid Chisnall    size_type bucket_count() const {return __table_.bucket_count();}
5427a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5437a984708SDavid Chisnall    size_type max_bucket_count() const {return __table_.max_bucket_count();}
5447a984708SDavid Chisnall
5457a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5467a984708SDavid Chisnall    size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
5477a984708SDavid Chisnall
5487a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5497a984708SDavid Chisnall    void resize(size_type __n) {__table_.rehash(__n);}
5507a984708SDavid Chisnall};
5517a984708SDavid Chisnall
5527a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
5537a984708SDavid Chisnallhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
5547a984708SDavid Chisnall        size_type __n, const hasher& __hf, const key_equal& __eql)
5557a984708SDavid Chisnall    : __table_(__hf, __eql)
5567a984708SDavid Chisnall{
5577a984708SDavid Chisnall    __table_.rehash(__n);
5587a984708SDavid Chisnall}
5597a984708SDavid Chisnall
5607a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
5617a984708SDavid Chisnallhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
5627a984708SDavid Chisnall        size_type __n, const hasher& __hf, const key_equal& __eql,
5637a984708SDavid Chisnall        const allocator_type& __a)
5647a984708SDavid Chisnall    : __table_(__hf, __eql, __a)
5657a984708SDavid Chisnall{
5667a984708SDavid Chisnall    __table_.rehash(__n);
5677a984708SDavid Chisnall}
5687a984708SDavid Chisnall
5697a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
5707a984708SDavid Chisnalltemplate <class _InputIterator>
5717a984708SDavid Chisnallhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
5727a984708SDavid Chisnall        _InputIterator __first, _InputIterator __last)
5737a984708SDavid Chisnall{
5747a984708SDavid Chisnall    __table_.rehash(193);
5757a984708SDavid Chisnall    insert(__first, __last);
5767a984708SDavid Chisnall}
5777a984708SDavid Chisnall
5787a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
5797a984708SDavid Chisnalltemplate <class _InputIterator>
5807a984708SDavid Chisnallhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
5817a984708SDavid Chisnall        _InputIterator __first, _InputIterator __last, size_type __n,
5827a984708SDavid Chisnall        const hasher& __hf, const key_equal& __eql)
5837a984708SDavid Chisnall    : __table_(__hf, __eql)
5847a984708SDavid Chisnall{
5857a984708SDavid Chisnall    __table_.rehash(__n);
5867a984708SDavid Chisnall    insert(__first, __last);
5877a984708SDavid Chisnall}
5887a984708SDavid Chisnall
5897a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
5907a984708SDavid Chisnalltemplate <class _InputIterator>
5917a984708SDavid Chisnallhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
5927a984708SDavid Chisnall        _InputIterator __first, _InputIterator __last, size_type __n,
5937a984708SDavid Chisnall        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
5947a984708SDavid Chisnall    : __table_(__hf, __eql, __a)
5957a984708SDavid Chisnall{
5967a984708SDavid Chisnall    __table_.rehash(__n);
5977a984708SDavid Chisnall    insert(__first, __last);
5987a984708SDavid Chisnall}
5997a984708SDavid Chisnall
6007a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
6017a984708SDavid Chisnallhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
6027a984708SDavid Chisnall        const hash_multiset& __u)
6037a984708SDavid Chisnall    : __table_(__u.__table_)
6047a984708SDavid Chisnall{
6057a984708SDavid Chisnall    __table_.rehash(__u.bucket_count());
6067a984708SDavid Chisnall    insert(__u.begin(), __u.end());
6077a984708SDavid Chisnall}
6087a984708SDavid Chisnall
6097a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
6107a984708SDavid Chisnalltemplate <class _InputIterator>
6117c82a1ecSDimitry Andricinline
6127a984708SDavid Chisnallvoid
6137a984708SDavid Chisnallhash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
6147a984708SDavid Chisnall                                                         _InputIterator __last)
6157a984708SDavid Chisnall{
6167a984708SDavid Chisnall    for (; __first != __last; ++__first)
6177a984708SDavid Chisnall        __table_.__insert_multi(*__first);
6187a984708SDavid Chisnall}
6197a984708SDavid Chisnall
6207a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
6217a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
6227a984708SDavid Chisnallvoid
6237a984708SDavid Chisnallswap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
6247a984708SDavid Chisnall     hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
6257a984708SDavid Chisnall{
6267a984708SDavid Chisnall    __x.swap(__y);
6277a984708SDavid Chisnall}
6287a984708SDavid Chisnall
6297a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
6307a984708SDavid Chisnallbool
6317a984708SDavid Chisnalloperator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
6327a984708SDavid Chisnall           const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
6337a984708SDavid Chisnall{
6347a984708SDavid Chisnall    if (__x.size() != __y.size())
6357a984708SDavid Chisnall        return false;
6367a984708SDavid Chisnall    typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
6377a984708SDavid Chisnall                                                                 const_iterator;
6387a984708SDavid Chisnall    typedef pair<const_iterator, const_iterator> _EqRng;
6397a984708SDavid Chisnall    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
6407a984708SDavid Chisnall    {
6417a984708SDavid Chisnall        _EqRng __xeq = __x.equal_range(*__i);
6427a984708SDavid Chisnall        _EqRng __yeq = __y.equal_range(*__i);
6437a984708SDavid Chisnall        if (_VSTD::distance(__xeq.first, __xeq.second) !=
6447a984708SDavid Chisnall            _VSTD::distance(__yeq.first, __yeq.second) ||
6457a984708SDavid Chisnall                  !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
6467a984708SDavid Chisnall            return false;
6477a984708SDavid Chisnall        __i = __xeq.second;
6487a984708SDavid Chisnall    }
6497a984708SDavid Chisnall    return true;
6507a984708SDavid Chisnall}
6517a984708SDavid Chisnall
6527a984708SDavid Chisnalltemplate <class _Value, class _Hash, class _Pred, class _Alloc>
6537a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
6547a984708SDavid Chisnallbool
6557a984708SDavid Chisnalloperator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
6567a984708SDavid Chisnall           const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
6577a984708SDavid Chisnall{
6587a984708SDavid Chisnall    return !(__x == __y);
6597a984708SDavid Chisnall}
6607a984708SDavid Chisnall
6617a984708SDavid Chisnall} // __gnu_cxx
6627a984708SDavid Chisnall
6637a984708SDavid Chisnall#endif  // _LIBCPP_HASH_SET
664