15 #ifndef STXXL_CONTAINERS_DEQUE_HEADER
16 #define STXXL_CONTAINERS_DEQUE_HEADER
23 template <
class ValueType,
class VectorType>
26 template <
class DequeType>
29 template <
class DequeType>
37 typedef typename deque_type::pointer
pointer;
58 : m_deque(deque), m_offset(offset)
66 size_type SelfAbsOffset = (m_offset >= m_deque->m_begin) ?
67 m_offset : (m_deque->m_vector.size() + m_offset);
71 return SelfAbsOffset - aAbsOffset;
76 size_type SelfAbsOffset = (m_offset >= m_deque->m_begin) ?
77 m_offset : (m_deque->m_vector.size() + m_offset);
81 return SelfAbsOffset - aAbsOffset;
86 return self_type(m_deque, (m_offset + m_deque->m_vector.size() - op) % m_deque->m_vector.size());
91 return self_type(m_deque, (m_offset + op) % m_deque->m_vector.size());
96 m_offset = (m_offset + m_deque->m_vector.size() - op) % m_deque->m_vector.size();
102 m_offset = (m_offset + op) % m_deque->m_vector.size();
108 return m_deque->m_vector[m_offset];
113 return &(m_deque->m_vector[m_offset]);
118 return m_deque->m_vector[m_offset];
123 return &(m_deque->m_vector[m_offset]);
128 return m_deque->m_vector[(m_offset + op) % m_deque->m_vector.size()];
133 return m_deque->m_vector[(m_offset + op) % m_deque->m_vector.size()];
138 m_offset = (m_offset + 1) % m_deque->m_vector.size();
144 m_offset = (m_offset + 1) % m_deque->m_vector.size();
149 m_offset = (m_offset + m_deque->m_vector.size() - 1) % m_deque->m_vector.size();
155 m_offset = (m_offset + m_deque->m_vector.size() - 1) % m_deque->m_vector.size();
172 return (a - (*
this)) > 0;
182 return !((*this) > a);
187 return !((*this) < a);
204 return (a - (*
this)) > 0;
214 return !((*this) > a);
219 return !((*this) < a);
223 template <
class DequeType>
224 class const_deque_iterator
231 typedef typename deque_type::const_pointer
pointer;
253 : m_deque(deque), m_offset(offset)
260 : m_deque(it.m_deque), m_offset(it.m_offset)
265 size_type SelfAbsOffset = (m_offset >= m_deque->m_begin) ?
266 m_offset : (m_deque->m_vector.size() + m_offset);
270 return SelfAbsOffset - aAbsOffset;
275 size_type SelfAbsOffset = (m_offset >= m_deque->m_begin) ?
276 m_offset : (m_deque->m_vector.size() + m_offset);
280 return SelfAbsOffset - aAbsOffset;
285 return self_type(m_deque, (m_offset + m_deque->m_vector.size() - op) % m_deque->m_vector.size());
290 return self_type(m_deque, (m_offset + op) % m_deque->m_vector.size());
295 m_offset = (m_offset + m_deque->m_vector.size() - op) % m_deque->m_vector.size();
301 m_offset = (m_offset + op) % m_deque->m_vector.size();
307 return m_deque->m_vector[m_offset];
312 return &(m_deque->m_vector[m_offset]);
317 return m_deque->m_vector[(m_offset + op) % m_deque->m_vector.size()];
322 m_offset = (m_offset + 1) % m_deque->m_vector.size();
328 m_offset = (m_offset + 1) % m_deque->m_vector.size();
333 m_offset = (m_offset + m_deque->m_vector.size() - 1) % m_deque->m_vector.size();
339 m_offset = (m_offset + m_deque->m_vector.size() - 1) % m_deque->m_vector.size();
356 return (a - (*
this)) > 0;
366 return !((*this) > a);
371 return !((*this) < a);
388 return (a - (*
this)) > 0;
398 return !((*this) > a);
403 return !((*this) < a);
420 template <
class ValueType,
class VectorType = stxxl::vector<ValueType> >
421 class deque :
private noncopyable
448 const size_type old_size = m_vector.size();
449 m_vector.resize(2 * old_size);
452 const size_type new_begin = old_size + m_begin;
453 std::copy(m_vector.begin() + m_begin,
454 m_vector.begin() + old_size,
455 m_vector.begin() + new_begin);
466 m_begin(0), m_end(0), m_size(0)
471 m_begin(0), m_end(n), m_size(n)
560 return m_vector[(m_begin + n) % m_vector.size()];
566 return m_vector[(m_begin + n) % m_vector.size()];
572 return m_vector[m_begin];
578 return m_vector[m_begin];
584 return m_vector[(m_end + m_vector.size() - 1) % m_vector.size()];
590 return m_vector[(m_end + m_vector.size() - 1) % m_vector.size()];
600 if ((m_begin + m_vector.size() - 1) % m_vector.size() == m_end)
606 m_begin = (m_begin + m_vector.size() - 1) % m_vector.size();
607 m_vector[m_begin] = el;
613 if ((m_end + 1) % m_vector.size() == m_begin)
618 m_vector[m_end] = el;
619 m_end = (m_end + 1) % m_vector.size();
626 m_begin = (m_begin + 1) % m_vector.size();
633 m_end = (m_end + m_vector.size() - 1) % m_vector.size();
644 std::swap(m_vector, obj.m_vector);
645 std::swap(m_begin, obj.m_begin);
646 std::swap(m_end, obj.m_end);
647 std::swap(m_size, obj.m_size);
671 }
while (n < size());
675 if (n + 1 > m_vector.size())
677 const size_type old_size = m_vector.size();
678 m_vector.resize(2 * n);
681 const size_type new_begin = m_vector.size() - old_size + m_begin;
682 std::copy(m_vector.begin() + m_begin,
683 m_vector.begin() + old_size,
684 m_vector.begin() + new_begin);
688 m_end = (m_end + n - size()) % m_vector.size();
696 template <
class ValueType,
class VectorType>
699 return std::equal(a.begin(), a.end(), b.begin());
702 template <
class ValueType,
class VectorType>
705 return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
714 template <
typename ValueType,
typename VectorType>
723 #endif // !STXXL_CONTAINERS_DEQUE_HEADER
deque_type::reference reference
deque_type::const_reference const_reference
#define STXXL_DEFAULT_BLOCK_SIZE(type)
deque_iterator(deque_type *deque, size_type offset)
const_deque_iterator< deque_type > const_iterator
VectorType::difference_type difference_type
const value_type * const_pointer
deque_type::size_type size_type
const_deque_iterator(const deque_iterator< deque_type > &it)
std::reverse_iterator< iterator > reverse_iterator
const_reference front() const
const_reference back() const
A deque container. Introduction to deque container: see STXXL Deque tutorial. Design and Interna...
const_deque_iterator< self_type > const_iterator
reverse_iterator rbegin()
deque_iterator< deque_type > iterator
std::random_access_iterator_tag iterator_category
deque< ValueType, VectorType > self_type
deque_type::difference_type difference_type
const_iterator end() const
deque_type::const_pointer const_pointer
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
std::random_access_iterator_tag iterator_category
const_deque_iterator< deque_type > const_iterator
deque_type::vector_type vector_type
uint_pair & operator+=(const uint_pair &b)
addition operator (uses 64-bit arithmetic)
deque_type::difference_type difference_type
bool operator!=(const uint_pair &b) const
inequality checking operator
bool operator<=(const uint_pair &b) const
less-or-equal comparison operator
bool operator>(const uint_pair &b) const
greater comparison operator
const_reverse_iterator rbegin() const
Container::value_type pop_back(Container &c)
size_type max_size() const
const_iterator begin() const
bool operator>=(const uint_pair &b) const
greater-or-equal comparison operator
const Type & STXXL_MAX(const Type &a, const Type &b)
bool operator<(const uint_pair &b) const
less-than comparison operator
#define STXXL_BEGIN_NAMESPACE
uint_pair & operator--()
prefix decrement operator (directly manipulates the integer parts)
deque_iterator< self_type > iterator
const_deque_iterator(const deque_type *deque, size_type offset)
deque_type::value_type value_type
deque_iterator< deque_type > iterator
VectorType::size_type size_type
deque_type::vector_type vector_type
static uint_pair max()
return an uint_pair instance containing the largest value possible
const_reverse_iterator rend() const
deque_type::const_pointer const_pointer
deque_iterator< deque_type > self_type
deque_type::const_reference const_reference
const_iterator cend() const
const_deque_iterator< deque_type > self_type
const_reverse_iterator crbegin() const
void push_back(const value_type &el)
const ValueType & const_reference
const_iterator cbegin() const
deque_type::const_reference reference
deque_type::const_pointer pointer
deque_type::value_type value_type
std::reverse_iterator< const_iterator > const_reverse_iterator
deque_type::pointer pointer
deque_type::size_type size_type
void push_front(const value_type &el)
bool operator==(const uint_pair &b) const
equality checking operator
const deque_type * m_deque
#define STXXL_END_NAMESPACE
const_reverse_iterator crend() const