Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OrderedList.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 #ifndef GALOIS_WORKLIST_ORDEREDLIST_H
21 #define GALOIS_WORKLIST_ORDEREDLIST_H
22 
23 #include "galois/config.h"
24 #include "galois/FlatMap.h"
25 
26 namespace galois {
27 namespace worklists {
28 
29 template <class Compare = std::less<int>, typename T = int,
30  bool concurrent = true>
31 class OrderedList : private boost::noncopyable,
32  private substrate::PaddedLock<concurrent> {
33  typedef galois::flat_map<T, std::deque<T>, Compare> Map;
34 
35  Map map;
36 
40 
41 public:
42  template <typename Tnew>
44 
45  template <bool b>
47 
48  typedef T value_type;
49 
50  void push(value_type val) {
51  lock();
52  std::deque<T>& list = map[val];
53  list.push_back(val);
54  unlock();
55  }
56 
57  template <typename Iter>
58  void push(Iter b, Iter e) {
59  lock();
60  while (b != e) {
61  std::deque<T>& list = map[*b];
62  list.push_back(*b);
63  ++b;
64  }
65  unlock();
66  }
67 
68  template <typename RangeTy>
69  void push_initial(RangeTy range) {
71  push(range.begin(), range.end());
72  }
73 
75  lock();
76  if (map.empty()) {
77  unlock();
79  }
80  auto ii = map.begin();
81  std::deque<T>& list = ii->second;
82  galois::optional<value_type> v(list.front());
83  list.pop_front();
84  if (list.empty())
85  map.erase(ii);
86  unlock();
87  return v;
88  }
89 };
90 GALOIS_WLCOMPILECHECK(OrderedList)
91 } // namespace worklists
92 } // namespace galois
93 #endif
T value_type
Definition: OrderedList.h:48
Definition: OrderedList.h:31
void push(Iter b, Iter e)
Definition: OrderedList.h:58
Galois version of boost::optional.
Definition: optional.h:34
static unsigned getTID()
Definition: ThreadPool.h:204
Simple map data structure, based off a single array.
Definition: FlatMap.h:36
#define GALOIS_WLCOMPILECHECK(name)
Definition: WLCompileCheck.h:26
void push(value_type val)
Definition: OrderedList.h:50
iterator erase(const_iterator __position)
Definition: FlatMap.h:262
PaddedLock is a spinlock.
Definition: PaddedLock.h:32
void push_initial(RangeTy range)
Definition: OrderedList.h:69
galois::optional< value_type > pop()
Definition: OrderedList.h:74
bool empty() const
Definition: FlatMap.h:180
iterator begin()
Definition: FlatMap.h:163