- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# concurrent_unordered_set.h

    00001 /*
    00002     Copyright 2005-2012 Intel Corporation.  All Rights Reserved.
    00003
    00004     This file is part of Threading Building Blocks.
    00005
    00006     Threading Building Blocks is free software; you can redistribute it
    00007     and/or modify it under the terms of the GNU General Public License
    00008     version 2 as published by the Free Software Foundation.
    00009
    00010     Threading Building Blocks is distributed in the hope that it will be
    00011     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
    00012     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013     GNU General Public License for more details.
    00014
    00015     You should have received a copy of the GNU General Public License
    00016     along with Threading Building Blocks; if not, write to the Free Software
    00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    00018
    00019     As a special exception, you may use this file as part of a free software
    00020     library without restriction.  Specifically, if other files instantiate
    00021     templates or use macros or inline functions from this file, or you compile
    00022     this file and link it with other files to produce an executable, this
    00023     file does not by itself cause the resulting executable to be covered by
    00024     the GNU General Public License.  This exception does not however
    00025     invalidate any other reasons why the executable file might be covered by
    00026     the GNU General Public License.
    00027 */
    00028
    00029 /* Container implementations in this header are based on PPL implementations
    00030    provided by Microsoft. */
    00031
    00032 #ifndef __TBB_concurrent_unordered_set_H
    00033 #define __TBB_concurrent_unordered_set_H
    00034
    00035 #include "internal/_concurrent_unordered_impl.h"
    00036
    00037 namespace tbb
    00038 {
    00039
    00040 namespace interface5 {
    00041
    00042 // Template class for hash set traits
    00043 template<typename Key, typename Hash_compare, typename Allocator, bool Allow_multimapping>
    00044 class concurrent_unordered_set_traits
    00045 {
    00046 protected:
    00047     typedef Key value_type;
    00048     typedef Key key_type;
    00049     typedef Hash_compare hash_compare;
    00050     typedef typename Allocator::template rebind<value_type>::other allocator_type;
    00051     enum { allow_multimapping = Allow_multimapping };
    00052
    00053     concurrent_unordered_set_traits() : my_hash_compare() {}
    00054     concurrent_unordered_set_traits(const hash_compare& hc) : my_hash_compare(hc) {}
    00055
    00056     typedef hash_compare value_compare;
    00057
    00058     static const Key& get_key(const value_type& value) {
    00059         return value;
    00060     }
    00061
    00062     hash_compare my_hash_compare; // the comparator predicate for keys
    00063 };
    00064
    00065 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>, typename Allocator = tbb::tbb_allocator<Key> >
    00066 class concurrent_unordered_set : public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> >
    00067 {
    00068     // Base type definitions
    00069     typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
    00070     typedef internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, hash_compare, Allocator, false> > base_type;
    00071     typedef concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> traits_type;
    00072     using traits_type::my_hash_compare;
    00073 #if __TBB_EXTRA_DEBUG
    00074 public:
    00075 #endif
    00076     using traits_type::allow_multimapping;
    00077 public:
    00078     using base_type::end;
    00079     using base_type::find;
    00080     using base_type::insert;
    00081
    00082     // Type definitions
    00083     typedef Key key_type;
    00084     typedef typename base_type::value_type value_type;
    00085     typedef Key mapped_type;
    00086     typedef Hasher hasher;
    00087     typedef Key_equality key_equal;
    00088     typedef hash_compare key_compare;
    00089
    00090     typedef typename base_type::allocator_type allocator_type;
    00091     typedef typename base_type::pointer pointer;
    00092     typedef typename base_type::const_pointer const_pointer;
    00093     typedef typename base_type::reference reference;
    00094     typedef typename base_type::const_reference const_reference;
    00095
    00096     typedef typename base_type::size_type size_type;
    00097     typedef typename base_type::difference_type difference_type;
    00098
    00099     typedef typename base_type::iterator iterator;
    00100     typedef typename base_type::const_iterator const_iterator;
    00101     typedef typename base_type::iterator local_iterator;
    00102     typedef typename base_type::const_iterator const_local_iterator;
    00103
    00104     // Construction/destruction/copying
    00105     explicit concurrent_unordered_set(size_type n_of_buckets = 8, const hasher& a_hasher = hasher(),
    00106         const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
    00107         : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
    00108     {
    00109     }
    00110
    00111     concurrent_unordered_set(const Allocator& a) : base_type(8, key_compare(), a)
    00112     {
    00113     }
    00114
    00115     template <typename Iterator>
    00116     concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets = 8, const hasher& a_hasher = hasher(),
    00117         const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
    00118         : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
    00119     {
    00120         for (; first != last; ++first)
    00121             base_type::insert(*first);
    00122     }
    00123
    00124     concurrent_unordered_set(const concurrent_unordered_set& table) : base_type(table)
    00125     {
    00126     }
    00127
    00128     concurrent_unordered_set(const concurrent_unordered_set& table, const Allocator& a)
    00129         : base_type(table, a)
    00130     {
    00131     }
    00132
    00133     concurrent_unordered_set& operator=(const concurrent_unordered_set& table)
    00134     {
    00135         base_type::operator=(table);
    00136         return (*this);
    00137     }
    00138
    00139     iterator unsafe_erase(const_iterator where)
    00140     {
    00141         return base_type::unsafe_erase(where);
    00142     }
    00143
    00144     size_type unsafe_erase(const key_type& key)
    00145     {
    00146         return base_type::unsafe_erase(key);
    00147     }
    00148
    00149     iterator unsafe_erase(const_iterator first, const_iterator last)
    00150     {
    00151         return base_type::unsafe_erase(first, last);
    00152     }
    00153
    00154     void swap(concurrent_unordered_set& table)
    00155     {
    00156         base_type::swap(table);
    00157     }
    00158
    00159     // Observers
    00160     hasher hash_function() const
    00161     {
    00162         return my_hash_compare.my_hash_object;
    00163     }
    00164
    00165     key_equal key_eq() const
    00166     {
    00167         return my_hash_compare.my_key_compare_object;
    00168     }
    00169 };
    00170
    00171 } // namespace interface5
    00172
    00173 using interface5::concurrent_unordered_set;
    00174
    00175 } // namespace tbb
    00176
    00177 #endif// __TBB_concurrent_unordered_set_H

Copyright © 2005-2012 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.