]> git.sesse.net Git - casparcg/blob - tbb/include/tbb/concurrent_unordered_set.h
2.0. Updated tbb library.
[casparcg] / tbb / include / tbb / concurrent_unordered_set.h
1 /*
2     Copyright 2005-2011 Intel Corporation.  All Rights Reserved.
3
4     This file is part of Threading Building Blocks.
5
6     Threading Building Blocks is free software; you can redistribute it
7     and/or modify it under the terms of the GNU General Public License
8     version 2 as published by the Free Software Foundation.
9
10     Threading Building Blocks is distributed in the hope that it will be
11     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with Threading Building Blocks; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19     As a special exception, you may use this file as part of a free software
20     library without restriction.  Specifically, if other files instantiate
21     templates or use macros or inline functions from this file, or you compile
22     this file and link it with other files to produce an executable, this
23     file does not by itself cause the resulting executable to be covered by
24     the GNU General Public License.  This exception does not however
25     invalidate any other reasons why the executable file might be covered by
26     the GNU General Public License.
27 */
28
29 /* Container implementations in this header are based on PPL implementations
30    provided by Microsoft. */
31
32 #ifndef __TBB_concurrent_unordered_set_H
33 #define __TBB_concurrent_unordered_set_H
34
35 #include "internal/_concurrent_unordered_impl.h"
36
37 namespace tbb
38 {
39
40 namespace interface5 {
41
42 // Template class for hash set traits
43 template<typename Key, typename Hash_compare, typename Allocator, bool Allow_multimapping>
44 class concurrent_unordered_set_traits
45 {
46 protected:
47     typedef Key value_type;
48     typedef Key key_type;
49     typedef Hash_compare hash_compare;
50     typedef typename Allocator::template rebind<value_type>::other allocator_type;
51     enum { allow_multimapping = Allow_multimapping };
52
53     concurrent_unordered_set_traits() : my_hash_compare() {}
54     concurrent_unordered_set_traits(const hash_compare& hc) : my_hash_compare(hc) {}
55
56     typedef hash_compare value_compare;
57
58     static const Key& get_key(const value_type& value) {
59         return value;
60     }
61
62     hash_compare my_hash_compare; // the comparator predicate for keys
63 };
64
65 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>, typename Allocator = tbb::tbb_allocator<Key> >
66 class concurrent_unordered_set : public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> >
67 {
68     // Base type definitions
69     typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
70     typedef internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, hash_compare, Allocator, false> > base_type;
71     typedef concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> traits_type;
72     using traits_type::my_hash_compare;
73 #if __TBB_EXTRA_DEBUG
74 public:
75 #endif
76     using traits_type::allow_multimapping;
77 public:
78     using base_type::end;
79     using base_type::find;
80     using base_type::insert;
81
82     // Type definitions
83     typedef Key key_type;
84     typedef typename base_type::value_type value_type;
85     typedef Key mapped_type;
86     typedef Hasher hasher;
87     typedef Key_equality key_equal;
88     typedef hash_compare key_compare;
89
90     typedef typename base_type::allocator_type allocator_type;
91     typedef typename base_type::pointer pointer;
92     typedef typename base_type::const_pointer const_pointer;
93     typedef typename base_type::reference reference;
94     typedef typename base_type::const_reference const_reference;
95
96     typedef typename base_type::size_type size_type;
97     typedef typename base_type::difference_type difference_type;
98
99     typedef typename base_type::iterator iterator;
100     typedef typename base_type::const_iterator const_iterator;
101     typedef typename base_type::iterator local_iterator;
102     typedef typename base_type::const_iterator const_local_iterator;
103
104     // Construction/destruction/copying
105     explicit concurrent_unordered_set(size_type n_of_buckets = 8, const hasher& a_hasher = hasher(),
106         const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
107         : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
108     {
109     }
110
111     concurrent_unordered_set(const Allocator& a) : base_type(8, key_compare(), a)
112     {
113     }
114
115     template <typename Iterator>
116     concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets = 8, const hasher& a_hasher = hasher(),
117         const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
118         : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
119     {
120         for (; first != last; ++first)
121             base_type::insert(*first);
122     }
123
124     concurrent_unordered_set(const concurrent_unordered_set& table) : base_type(table)
125     {
126     }
127
128     concurrent_unordered_set(const concurrent_unordered_set& table, const Allocator& a)
129         : base_type(table, a)
130     {
131     }
132
133     concurrent_unordered_set& operator=(const concurrent_unordered_set& table)
134     {
135         base_type::operator=(table);
136         return (*this);
137     }
138
139     iterator unsafe_erase(const_iterator where)
140     {
141         return base_type::unsafe_erase(where);
142     }
143
144     size_type unsafe_erase(const key_type& key)
145     {
146         return base_type::unsafe_erase(key);
147     }
148
149     iterator unsafe_erase(const_iterator first, const_iterator last)
150     {
151         return base_type::unsafe_erase(first, last);
152     }
153
154     void swap(concurrent_unordered_set& table)
155     {
156         base_type::swap(table);
157     }
158
159     // Observers
160     hasher hash_function() const
161     {
162         return my_hash_compare.my_hash_object;
163     }
164
165     key_equal key_eq() const
166     {
167         return my_hash_compare.my_key_compare_object;
168     }
169 };
170
171 } // namespace interface5
172
173 using interface5::concurrent_unordered_set;
174
175 } // namespace tbb
176
177 #endif// __TBB_concurrent_unordered_set_H