DASH  0.3.0
UnorderedMap.h
1 #ifndef DASH__UNORDERED_MAP_H__INCLUDED
2 #define DASH__UNORDERED_MAP_H__INCLUDED
3 
4 #include <dash/Types.h>
5 #include <dash/GlobRef.h>
6 #include <dash/Team.h>
7 #include <dash/Array.h>
8 #include <dash/memory/GlobHeapMem.h>
9 #include <dash/Allocator.h>
10 
11 #include <dash/atomic/GlobAtomicRef.h>
12 
13 #include <iterator>
14 #include <utility>
15 #include <limits>
16 #include <vector>
17 #include <functional>
18 #include <algorithm>
19 #include <cstddef>
20 
21 #ifdef DOXYGEN
22 
23 namespace dash {
24 
133 template<
134  typename Key,
135  typename Mapped,
136  typename Hash = dash::HashLocal<Key>,
137  typename Pred = std::equal_to<Key>,
138  typename LocalMemType = HostSpace >
139 class UnorderedMap
140 {
141  typedef UnorderedMap<Key, Mapped, Hash, Pred, LocalMemType> self_type;
142 
143  using glob_mem_type = dash::GlobHeapMem<
144  std::pair<const Key, Mapped>,
145  LocalMemorySpace,
148 
149 public:
150 
151  typedef Key key_type;
152  typedef Mapped mapped_type;
153  typedef Hash hasher;
154  typedef Pred key_equal;
155 
156  typedef dash::default_index_t index_type;
157  typedef dash::default_index_t difference_type;
158  typedef dash::default_size_t size_type;
159  typedef std::pair<const key_type, mapped_type> value_type;
160 
161  typedef typename dash::container_traits<self_type>::local_type local_type;
162 
163  typedef GlobHeapPtr<value_type, glob_mem_type> pointer;
164  typedef GlobHeapPtr<const value_type, glob_mem_type> const_pointer;
165 
166  typedef GlobSharedRef<value_type, GlobHeapPtr<value_type, glob_mem_type>>
167  reference;
168 
169  typedef GlobSharedRef<value_type const, GlobHeapPtr<value_type, glob_mem_type>>
170  const_reference;
171 
172  typedef typename reference::template rebind<mapped_type>::other
173  mapped_type_reference;
174  typedef typename const_reference::template rebind<mapped_type>::other
175  const_mapped_type_reference;
176 
177  typedef typename glob_mem_type::global_iterator
178  node_iterator;
179  typedef typename glob_mem_type::const_global_iterator
180  const_node_iterator;
181  typedef typename glob_mem_type::local_iterator
182  local_node_iterator;
183  typedef typename glob_mem_type::const_local_iterator
184  const_local_node_iterator;
185  typedef typename glob_mem_type::reverse_global_iterator
186  reverse_node_iterator;
187  typedef typename glob_mem_type::const_reverse_global_iterator
188  const_reverse_node_iterator;
189  typedef typename glob_mem_type::reverse_local_iterator
190  reverse_local_node_iterator;
191  typedef typename glob_mem_type::const_reverse_local_iterator
192  const_reverse_local_node_iterator;
193 
194  typedef typename glob_mem_type::local_iterator
195  local_node_pointer;
196  typedef typename glob_mem_type::const_local_iterator
197  const_local_node_pointer;
198 
199  typedef UnorderedMapGlobIter<Key, Mapped, Hash, Pred, glob_mem_type>
200  iterator;
201  typedef UnorderedMapGlobIter<Key, Mapped, Hash, Pred, glob_mem_type>
202  const_iterator;
203  typedef typename std::reverse_iterator<iterator>
204  reverse_iterator;
205  typedef typename std::reverse_iterator<const_iterator>
206  const_reverse_iterator;
207 
208  typedef UnorderedMapLocalIter<Key, Mapped, Hash, Pred, LocalMemType>
209  local_pointer;
210  typedef UnorderedMapLocalIter<Key, Mapped, Hash, Pred, LocalMemType>
211  const_local_pointer;
212  typedef UnorderedMapLocalIter<Key, Mapped, Hash, Pred, LocalMemType>
213  local_iterator;
214  typedef UnorderedMapLocalIter<Key, Mapped, Hash, Pred, LocalMemType>
215  const_local_iterator;
216  typedef typename std::reverse_iterator<local_iterator>
217  reverse_local_iterator;
218  typedef typename std::reverse_iterator<const_local_iterator>
219  const_reverse_local_iterator;
220 
221  typedef typename glob_mem_type::local_reference
222  local_reference;
223  typedef typename glob_mem_type::const_local_reference
224  const_local_reference;
225 
226  typedef dash::Array<
227  size_type, int, dash::CSRPattern<1, dash::ROW_MAJOR, int> >
228  local_sizes_map;
229 
230 public:
232  local_type local;
233 
235  // Distributed container
237 
244  constexpr Team & team() const noexcept;
245 
250  const glob_mem_type & globmem() const;
251 
253  // Dynamic distributed memory
255 
261  void barrier();
262 
269  bool allocate(
271  size_type nelem = 0,
273  dash::Team & team = dash::Team::All());
274 
281  void deallocate();
282 
284  // Global Iterators
286 
292  iterator & begin() noexcept;
293 
299  const_iterator & begin() const noexcept;
300 
306  const_iterator & cbegin() const noexcept;
307 
313  iterator & end() noexcept;
314 
320  const_iterator & end() const noexcept;
321 
327  const_iterator & cend() const noexcept;
328 
330  // Local Iterators
332 
338  local_iterator & lbegin() noexcept;
339 
345  const_local_iterator & lbegin() const noexcept;
346 
352  const_local_iterator & clbegin() const noexcept;
353 
359  local_iterator & lend() noexcept;
360 
366  const_local_iterator & lend() const noexcept;
367 
373  const_local_iterator & clend() const noexcept;
374 
376  // Capacity
378 
384  constexpr size_type max_size() const noexcept;
385 
391  size_type size() const noexcept;
392 
399  size_type capacity() const noexcept;
400 
406  bool empty() const noexcept;
407 
414  size_type lsize() const noexcept;
415 
422  size_type lcapacity() const noexcept;
423 
425  // Element Access
427 
454  mapped_type_reference operator[](const key_type & key);
455 
469  const_mapped_type_reference at(const key_type & key) const;
470 
484  mapped_type_reference at(const key_type & key);
485 
487  // Element Lookup
489 
500  size_type count(const key_type & key) const;
501 
514  iterator find(const key_type & key);
515 
529  const_iterator find(const key_type & key) const;
530 
532  // Modifiers
534 
558  std::pair<iterator, bool> insert(
560  const value_type & value);
561 
578  iterator insert(
579  //Iterator hint
580  const_iterator hint,
581  //The element to insert
582  const value_type & value);
583 
598  template<class InputIterator>
599  void insert(
600  // Iterator at first value in the range to insert.
601  InputIterator first,
602  // Iterator past the last value in the range to insert.
603  InputIterator last);
604 
615  iterator erase(
616  const_iterator position);
617 
628  size_type erase(
630  const key_type & key);
631 
642  iterator erase(
644  const_iterator first,
646  const_iterator last);
647 
649  // Bucket Interface
651 
659  size_type bucket(
661  const key_type & key) const;
662 
668  size_type bucket_size(
670  size_type bucket_index) const;
671 
673  // Observers
675 
679  key_equal key_eq() const;
680 
684  hasher hash_function() const;
685 
686 }; // class UnorderedMap
687 
688 } // namespace dash
689 
690 #endif // ifdef DOXYGEN
691 
692 #include <dash/map/UnorderedMap.h>
693 
694 #endif // DASH__UNORDERED_MAP_H__INCLUDED
size_type lcapacity() const noexcept
The capacity of the local part of the map.
const_iterator & cend() const noexcept
Global const iterator to the end of the map.
internal::default_unsigned_index default_size_t
Unsigned integer type used as default for size values.
Definition: Types.h:69
size_type size() const noexcept
The size of the map.
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
const glob_mem_type & globmem() const
Reference to instance of DashGlobalMemoryConcept used for underlying memory management of this contai...
const_iterator & cbegin() const noexcept
Global const iterator to the beginning of the map.
const_mapped_type_reference at(const key_type &key) const
If key matches the key of an element in the container, returns a const reference to its mapped value...
size_type lsize() const noexcept
The number of elements in the local part of the map.
Returns second operand.
Definition: Operation.h:201
iterator erase(const_iterator position)
Removes and destroys single element referenced by given iterator from the container, decreasing the container size by 1.
key_equal key_eq() const
Returns the function that compares keys for equality.
size_type bucket_size(size_type bucket_index) const
The number of elements in a specified bucket.
Global memory region with dynamic size.
Definition: GlobHeapMem.h:204
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
Definition: Types.h:59
A Team instance specifies a subset of all available units.
Definition: Team.h:41
all units allocate invdividually in local memory and synchronize in epochs
constexpr size_type max_size() const noexcept
Maximum number of elements a map container can hold, e.g.
size_type bucket(const key_type &key) const
Returns the index of the bucket for a specified key.
void deallocate()
Free global memory allocated by this container instance.
iterator & begin() noexcept
Global iterator to the beginning of the map.
A distributed array.
Definition: Array.h:89
constexpr Team & team() const noexcept
The team containing all units accessing this map.
size_type capacity() const noexcept
The number of elements that can be held in currently allocated storage of the map.
iterator & end() noexcept
Global iterator to the end of the map.
hasher hash_function() const
Returns the function that hashes the keys.
const_local_iterator & clbegin() const noexcept
Const local iterator to the local beginning of the map.
local_type local
Local proxy object, allows use in range-based for loops.
Definition: UnorderedMap.h:232
bool allocate(size_type nelem=0, dash::Team &team=dash::Team::All())
Allocate memory for this container in global memory.
local_iterator & lbegin() noexcept
Local iterator to the local beginning of the map.
void barrier()
Synchronize changes on local and global memory space of the map since initialization or the last call...
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
Definition: cstddef.h:8
iterator find(const key_type &key)
Get iterator to element with specified key.
std::pair< iterator, bool > insert(const value_type &value)
Insert a new element as key-value pair, increasing the container size by 1.
const_local_iterator & clend() const noexcept
Local const iterator to the local end of the map.
size_type count(const key_type &key) const
Count elements with a specific key.
local_iterator & lend() noexcept
Local iterator to the local end of the map.
bool empty() const noexcept
Whether the map is empty.