26 #include <boost/iterator/iterator_facade.hpp>
28 #include "galois/config.h"
41 template <
typename T,
unsigned int BlockSize = 0>
51 typedef std::pair<header*, header*> PerThread;
55 class Iterator :
public boost::iterator_facade<Iterator<U>, U,
56 boost::forward_traversal_tag> {
66 v = p ? p->dbegin : 0;
70 bool advance_local() {
78 bool advance_chunk() {
81 v = p ? p->dbegin : 0;
86 void advance_thread() {
87 while (thr < hd->size()) {
102 template <
typename OtherTy>
103 bool equal(
const Iterator<OtherTy>& o)
const {
104 return hd == o.hd && thr == o.thr && p == o.p && v == o.v;
107 U& dereference()
const {
return *v; }
112 template <
typename OtherTy>
114 : hd(o.hd), thr(o.thr), p(o.p), v(o.v) {}
119 : hd(h), thr(t), p(0), v(0) {
130 void insHeader(header* h) {
131 PerThread& hpair = *heads.
getLocal();
133 hpair.second->next = h;
136 hpair.first = hpair.second = h;
140 header* newHeaderFromHeap(
void* m,
unsigned size) {
141 header* H =
new (m) header();
143 if (
sizeof(T) <
sizeof(header))
144 offset +=
sizeof(header) /
sizeof(T);
145 T* a =
reinterpret_cast<T*
>(m);
146 H->dbegin = &a[offset];
148 H->dlast = &a[(size /
sizeof(T))];
153 header* newHeader() {
155 return newHeaderFromHeap(heap.
allocate(BlockSize), BlockSize);
162 void destruct_serial() {
163 for (
unsigned x = 0; x < heads.
size(); ++x) {
165 header*& h = hpair.first;
179 void destruct_parallel(
void) {
181 [
this](
const unsigned int tid,
const unsigned int) {
182 PerThread& hpair = *heads.
getLocal(tid);
183 header*& h = hpair.first;
205 std::swap(heap, o.heap);
206 std::swap(heads, o.heads);
210 std::swap(heap, o.heap);
211 std::swap(heads, o.heads);
220 void clear() { destruct_parallel(); }
225 std::swap(heap, o.heap);
226 std::swap(heads, o.heads);
251 for (
unsigned x = 0; x < heads.
size(); ++x) {
259 template <
typename... Args>
261 header* H = heads.
getLocal()->second;
263 if (!H || H->dend == H->dlast) {
267 rv =
new (H->dend) T(std::forward<Args>(args)...);
272 template <
typename... Args>
274 return emplace(std::forward<Args>(args)...);
282 header* H = heads.
getLocal()->second;
283 if (H->dbegin == H->dend) {
284 throw std::out_of_range(
"InsertBag::pop");
291 template <
typename ItemTy>
293 return emplace(std::forward<ItemTy>(val));
297 template <
typename ItemTy>
299 return emplace(std::forward<ItemTy>(val));
const_iterator begin() const
Definition: Bag.h:240
reference push(ItemTy &&val)
Thread safe bag insertion.
Definition: Bag.h:292
~InsertBag()
Definition: Bag.h:218
InsertBag(InsertBag &&o)
Definition: Bag.h:204
reference emplace(Args &&...args)
Thread safe bag insertion.
Definition: Bag.h:260
iterator local_iterator
Definition: Bag.h:236
friend class boost::iterator_core_access
Definition: Bag.h:57
iterator begin()
Definition: Bag.h:238
Iterator(const Iterator< OtherTy > &o)
Definition: Bag.h:113
T * getLocal()
Definition: PerThreadStorage.h:128
reference emplace_back(Args &&...args)
Definition: Bag.h:273
local_iterator local_begin()
Definition: Bag.h:243
T & reference
Definition: Bag.h:233
Iterator()
Definition: Bag.h:110
void on_each_gen(FunctionTy &&fn, const TupleTy &tpl)
Definition: Executor_OnEach.h:74
void clear_serial()
Definition: Bag.h:222
iterator end()
Definition: Bag.h:239
Iterator< const T > const_iterator
Definition: Bag.h:235
const T & const_reference
Definition: Bag.h:232
size_t pagePoolSize()
Definition: PagePool.cpp:50
static unsigned getTID()
Definition: ThreadPool.h:204
void pagePoolFree(void *)
Definition: PagePool.cpp:48
Definition: PerThreadStorage.h:88
Unordered collection of elements.
Definition: Bag.h:42
std::enable_if_t<!std::is_scalar< internal::Val_ty< I > >::value > uninitialized_destroy(I first, I last)
Destroy a range.
Definition: gstl.h:284
bool empty() const
Definition: Bag.h:250
Main scalable allocator in Galois.
Definition: runtime/Mem.h:642
const_iterator end() const
Definition: Bag.h:241
const T * const_pointer
Definition: Bag.h:231
void swap(InsertBag &o)
Definition: Bag.h:224
unsigned size() const
Definition: PerThreadStorage.h:159
void * pagePoolAlloc()
Low level page pool (individual pages, use largeMalloc for large blocks)
Definition: PagePool.cpp:41
InsertBag()
Definition: Bag.h:203
InsertBag & operator=(InsertBag &&o)
Definition: Bag.h:209
reference push_back(ItemTy &&val)
Thread safe bag insertion.
Definition: Bag.h:298
void * allocate(size_t size)
Definition: runtime/Mem.h:655
void clear()
Definition: Bag.h:220
T * getRemote(unsigned int thread)
Definition: PerThreadStorage.h:149
Iterator(galois::substrate::PerThreadStorage< std::pair< header *, header * >> *h, unsigned t)
Definition: Bag.h:116
Iterator< T > iterator
Definition: Bag.h:234
local_iterator local_end()
Definition: Bag.h:246
T value_type
Definition: Bag.h:229
void pop()
Pop the last element pushed by this thread.
Definition: Bag.h:281
T * pointer
Definition: Bag.h:230
void deallocate(void *ptr)
Definition: runtime/Mem.h:664