concurrent_unordered_set.h Source File

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

- File List
- File Members

# concurrent_unordered_set.h

    00001 /*
    00002     Copyright 2005-2012 Intel Corporation.  All Rights Reserved.
    00003
    00004     The source code contained or described herein and all documents related
    00005     to the source code ("Material") are owned by Intel Corporation or its
    00006     suppliers or licensors.  Title to the Material remains with Intel
    00007     Corporation or its suppliers and licensors.  The Material is protected
    00008     by worldwide copyright laws and treaty provisions.  No part of the
    00009     Material may be used, copied, reproduced, modified, published, uploaded,
    00010     posted, transmitted, distributed, or disclosed in any way without
    00011     Intel's prior express written permission.
    00012
    00013     No license under any patent, copyright, trade secret or other
    00014     intellectual property right is granted to or conferred upon you by
    00015     disclosure or delivery of the Materials, either expressly, by
    00016     implication, inducement, estoppel or otherwise.  Any license under such
    00017     intellectual property rights must be express and approved by Intel in
    00018     writing.
    00019 */
    00020
    00021 /* Container implementations in this header are based on PPL implementations
    00022    provided by Microsoft. */
    00023
    00024 #ifndef __TBB_concurrent_unordered_set_H
    00025 #define __TBB_concurrent_unordered_set_H
    00026
    00027 #include "internal/_concurrent_unordered_impl.h"
    00028
    00029 namespace tbb
    00030 {
    00031
    00032 namespace interface5 {
    00033
    00034 // Template class for hash set traits
    00035 template<typename Key, typename Hash_compare, typename Allocator, bool Allow_multimapping>
    00036 class concurrent_unordered_set_traits
    00037 {
    00038 protected:
    00039     typedef Key value_type;
    00040     typedef Key key_type;
    00041     typedef Hash_compare hash_compare;
    00042     typedef typename Allocator::template rebind<value_type>::other allocator_type;
    00043     enum { allow_multimapping = Allow_multimapping };
    00044
    00045     concurrent_unordered_set_traits() : my_hash_compare() {}
    00046     concurrent_unordered_set_traits(const hash_compare& hc) : my_hash_compare(hc) {}
    00047
    00048     typedef hash_compare value_compare;
    00049
    00050     static const Key& get_key(const value_type& value) {
    00051         return value;
    00052     }
    00053
    00054     hash_compare my_hash_compare; // the comparator predicate for keys
    00055 };
    00056
    00057 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>, typename Allocator = tbb::tbb_allocator<Key> >
    00058 class concurrent_unordered_set : public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> >
    00059 {
    00060     // Base type definitions
    00061     typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
    00062     typedef internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, hash_compare, Allocator, false> > base_type;
    00063     typedef concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> traits_type;
    00064     using traits_type::my_hash_compare;
    00065 #if __TBB_EXTRA_DEBUG
    00066 public:
    00067 #endif
    00068     using traits_type::allow_multimapping;
    00069 public:
    00070     using base_type::end;
    00071     using base_type::find;
    00072     using base_type::insert;
    00073
    00074     // Type definitions
    00075     typedef Key key_type;
    00076     typedef typename base_type::value_type value_type;
    00077     typedef Key mapped_type;
    00078     typedef Hasher hasher;
    00079     typedef Key_equality key_equal;
    00080     typedef hash_compare key_compare;
    00081
    00082     typedef typename base_type::allocator_type allocator_type;
    00083     typedef typename base_type::pointer pointer;
    00084     typedef typename base_type::const_pointer const_pointer;
    00085     typedef typename base_type::reference reference;
    00086     typedef typename base_type::const_reference const_reference;
    00087
    00088     typedef typename base_type::size_type size_type;
    00089     typedef typename base_type::difference_type difference_type;
    00090
    00091     typedef typename base_type::iterator iterator;
    00092     typedef typename base_type::const_iterator const_iterator;
    00093     typedef typename base_type::iterator local_iterator;
    00094     typedef typename base_type::const_iterator const_local_iterator;
    00095
    00096     // Construction/destruction/copying
    00097     explicit concurrent_unordered_set(size_type n_of_buckets = 8, const hasher& a_hasher = hasher(),
    00098         const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
    00099         : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
    00100     {
    00101     }
    00102
    00103     concurrent_unordered_set(const Allocator& a) : base_type(8, key_compare(), a)
    00104     {
    00105     }
    00106
    00107     template <typename Iterator>
    00108     concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets = 8, const hasher& a_hasher = hasher(),
    00109         const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
    00110         : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
    00111     {
    00112         for (; first != last; ++first)
    00113             base_type::insert(*first);
    00114     }
    00115
    00116     concurrent_unordered_set(const concurrent_unordered_set& table) : base_type(table)
    00117     {
    00118     }
    00119
    00120     concurrent_unordered_set(const concurrent_unordered_set& table, const Allocator& a)
    00121         : base_type(table, a)
    00122     {
    00123     }
    00124
    00125     concurrent_unordered_set& operator=(const concurrent_unordered_set& table)
    00126     {
    00127         base_type::operator=(table);
    00128         return (*this);
    00129     }
    00130
    00131     iterator unsafe_erase(const_iterator where)
    00132     {
    00133         return base_type::unsafe_erase(where);
    00134     }
    00135
    00136     size_type unsafe_erase(const key_type& key)
    00137     {
    00138         return base_type::unsafe_erase(key);
    00139     }
    00140
    00141     iterator unsafe_erase(const_iterator first, const_iterator last)
    00142     {
    00143         return base_type::unsafe_erase(first, last);
    00144     }
    00145
    00146     void swap(concurrent_unordered_set& table)
    00147     {
    00148         base_type::swap(table);
    00149     }
    00150
    00151     // Observers
    00152     hasher hash_function() const
    00153     {
    00154         return my_hash_compare.my_hash_object;
    00155     }
    00156
    00157     key_equal key_eq() const
    00158     {
    00159         return my_hash_compare.my_key_compare_object;
    00160     }
    00161 };
    00162
    00163 } // namespace interface5
    00164
    00165 using interface5::concurrent_unordered_set;
    00166
    00167 } // namespace tbb
    00168
    00169 #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.