35 #include "galois/config.h"
52 using Vector = std::vector<T, Pow2Alloc<T>>;
56 using Deque = std::deque<T, Pow2Alloc<T>>;
59 using List = std::list<T, FixedSizeAlloc<T>>;
61 template <
typename T,
typename C = std::less<T>>
62 using Set = std::set<T, C, FixedSizeAlloc<T>>;
64 template <
typename K,
typename V,
typename C = std::less<K>>
65 using Map = std::map<K, V, C, FixedSizeAlloc<std::pair<const K, V>>>;
67 template <
typename K,
typename V,
typename Hash = std::hash<K>,
68 typename KeyEqual = std::equal_to<K>>
69 using UnorderedMap = std::unordered_map<K, V, Hash, KeyEqual,
72 template <
typename T,
typename C = std::less<T>>
80 std::basic_ostringstream<char, std::char_traits<char>,
Pow2Alloc<char>> os;
101 template <
typename T>
107 template <
typename I>
113 IterRange(
const I& b,
const I& e) : m_beg(b), m_end(e) {}
114 const I&
begin(
void)
const {
return m_beg; }
115 const I&
end(
void)
const {
return m_end; }
118 template <
typename I>
123 template <
typename C>
125 using I = decltype(std::forward<C>(cont).begin());
127 std::forward<C>(cont).end());
132 template <
typename T,
typename C>
136 explicit SerCont(
const C& q = C()) : m_q(q) {}
138 void push(
const T& x) { m_q.push_back(x); }
140 template <
typename I>
141 void push(
const I& beg,
const I& end) {
142 for (I i = beg; i != end; ++i) {
147 template <
typename... Args>
148 void emplace(Args&&... args) {
149 m_q.emplace_back(std::forward<Args>(args)...);
152 bool empty(
void)
const {
return m_q.empty(); }
154 void clear(
void) { m_q.clear(); }
157 using iterator =
typename C::iterator;
158 using const_iterator =
typename C::const_iterator;
160 iterator begin(
void) {
return m_q.begin(); }
161 iterator end(
void) {
return m_q.end(); }
163 const_iterator begin(
void)
const {
return m_q.begin(); }
164 const_iterator end(
void)
const {
return m_q.end(); }
166 const_iterator cbegin(
void)
const {
return m_q.cbegin(); }
167 const_iterator cend(
void)
const {
return m_q.cend(); }
171 template <
typename T,
typename C = std::deque<T>>
172 class SerFIFO :
public internal::SerCont<T, C> {
174 using Base = internal::SerCont<T, C>;
177 explicit SerFIFO(
const C& q = C()) : Base(q) {}
180 T ret = Base::m_q.front();
181 Base::m_q.pop_front();
186 template <
typename T,
typename C = std::vector<T>>
189 using Base = internal::SerCont<T, C>;
195 T ret = Base::m_q.back();
196 Base::m_q.pop_back();
201 template <
typename IterTy,
class Distance>
203 std::random_access_iterator_tag) {
204 if (std::distance(b, e) >= n)
210 template <
typename IterTy,
class Distance>
212 std::input_iterator_tag) {
213 while (b != e && n--)
221 template <
typename IterTy,
class Distance>
223 typename std::iterator_traits<IterTy>::iterator_category category;
231 template <
typename IterTy>
233 std::advance(b, (std::distance(b, e) + 1) / 2);
243 typename std::enable_if<!std::is_integral<IterTy>::value>::type* =
nullptr>
244 std::pair<IterTy, IterTy>
block_range(IterTy b, IterTy e,
unsigned id,
246 size_t dist = std::distance(b, e);
247 size_t numper =
std::max((dist + num - 1) / num, (
size_t)1);
248 size_t A =
std::min(numper *
id, dist);
249 size_t B =
std::min(numper * (
id + 1), dist);
254 std::advance(e, B - A);
257 return std::make_pair(b, e);
260 template <
typename IntTy,
typename std::enable_if<
261 std::is_integral<IntTy>::value>::type* =
nullptr>
262 std::pair<IntTy, IntTy>
block_range(IntTy b, IntTy e,
unsigned id,
265 IntTy numper =
std::max((dist + num - 1) / num, (IntTy)1);
266 IntTy A =
std::min(numper *
id, dist);
267 IntTy B =
std::min(numper * (
id + 1), dist);
273 return std::make_pair(b, e);
277 template <
typename I>
282 template <
typename I>
283 std::enable_if_t<!std::is_scalar<internal::Val_ty<I>>::value>
286 using T = internal::Val_ty<I>;
287 for (; first != last; ++first)
292 std::enable_if_t<std::is_scalar<internal::Val_ty<I>>::value>
typename runtime::Pow_2_BlockAllocator< T > Pow2Alloc
[define Pow_2_VarSizeAlloc]
Definition: gstl.h:44
IterRange(const I &b, const I &e)
Definition: gstl.h:113
const Str & operator()(const Str &x) const
Definition: gstl.h:93
T pop(void)
Definition: gstl.h:194
std::pair< IterTy, IterTy > block_range(IterTy b, IterTy e, unsigned id, unsigned num)
Returns a continuous block from the range based on the number of divisions and the id of the block re...
Definition: gstl.h:244
std::map< K, V, C, FixedSizeAlloc< std::pair< const K, V >>> Map
Definition: gstl.h:65
Str operator()(const char *x) const
Definition: gstl.h:98
SerFIFO(const C &q=C())
Definition: gstl.h:177
const I & end(void) const
Definition: gstl.h:115
std::set< T, C, FixedSizeAlloc< T >> Set
Definition: gstl.h:62
Definition: PriorityQueue.h:159
std::vector< T, Pow2Alloc< T >> Vector
[STL vector using Pow_2_VarSizeAlloc]
Definition: gstl.h:52
SerStack(const C &q=C())
Definition: gstl.h:192
const Ty max(std::atomic< Ty > &a, const Ty &b)
Definition: AtomicHelpers.h:40
IterTy safe_advance_dispatch(IterTy b, IterTy e, Distance n, std::random_access_iterator_tag)
Definition: gstl.h:202
typename runtime::FixedSizeAllocator< T > FixedSizeAlloc
[define Pow_2_VarSizeAlloc]
Definition: gstl.h:48
std::unordered_map< K, V, Hash, KeyEqual, FixedSizeAlloc< std::pair< const K, V >>> UnorderedMap
Definition: gstl.h:70
Definition: runtime/Mem.h:864
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
Str makeStr(const T &x)
Definition: gstl.h:102
Str operator()(const std::string &x) const
Definition: gstl.h:88
std::deque< T, Pow2Alloc< T >> Deque
[STL vector using Pow_2_VarSizeAlloc]
Definition: gstl.h:56
const I & begin(void) const
Definition: gstl.h:114
const Ty min(std::atomic< Ty > &a, const Ty &b)
Definition: AtomicHelpers.h:70
IterTy safe_advance(IterTy b, IterTy e, Distance n)
Like std::advance but returns end if end is closer than the advance amount.
Definition: gstl.h:222
T pop(void)
Definition: gstl.h:179
T value_type
Definition: Executor_ParaMeter.h:111
A fixed size block allocator.
Definition: runtime/Mem.h:703
Str operator()(const T &x) const
Definition: gstl.h:79
IterTy split_range(IterTy b, IterTy e)
Finds the midpoint of a range.
Definition: gstl.h:232
std::list< T, FixedSizeAlloc< T >> List
Definition: gstl.h:59
std::basic_string< char, std::char_traits< char >, Pow2Alloc< char >> Str
Definition: gstl.h:75
auto makeIterRange(const I &beg, const I &end)
Definition: gstl.h:119