15 #ifndef STXXL_CONTAINERS_DEQUE_HEADER
16 #define STXXL_CONTAINERS_DEQUE_HEADER
24 template <
class ValueType,
class VectorType>
27 template <
class DequeType>
30 template <
class DequeType>
38 typedef typename deque_type::pointer
pointer;
59 : m_deque(deque), m_offset(offset)
67 size_type SelfAbsOffset = (m_offset >= m_deque->m_begin) ?
68 m_offset : (m_deque->m_vector.size() + m_offset);
72 return SelfAbsOffset - aAbsOffset;
77 size_type SelfAbsOffset = (m_offset >= m_deque->m_begin) ?
78 m_offset : (m_deque->m_vector.size() + m_offset);
82 return SelfAbsOffset - aAbsOffset;
87 return self_type(m_deque, (m_offset + m_deque->m_vector.size() - op) % m_deque->m_vector.size());
92 return self_type(m_deque, (m_offset + op) % m_deque->m_vector.size());
97 m_offset = (m_offset + m_deque->m_vector.size() - op) % m_deque->m_vector.size();
103 m_offset = (m_offset + op) % m_deque->m_vector.size();
109 return m_deque->m_vector[m_offset];
114 return &(m_deque->m_vector[m_offset]);
119 return m_deque->m_vector[m_offset];
124 return &(m_deque->m_vector[m_offset]);
129 return m_deque->m_vector[(m_offset + op) % m_deque->m_vector.size()];
134 return m_deque->m_vector[(m_offset + op) % m_deque->m_vector.size()];
139 m_offset = (m_offset + 1) % m_deque->m_vector.size();
145 m_offset = (m_offset + 1) % m_deque->m_vector.size();
150 m_offset = (m_offset + m_deque->m_vector.size() - 1) % m_deque->m_vector.size();
156 m_offset = (m_offset + m_deque->m_vector.size() - 1) % m_deque->m_vector.size();
173 return (a - (*
this)) > 0;
183 return !((*this) > a);
188 return !((*this) < a);
205 return (a - (*
this)) > 0;
215 return !((*this) > a);
220 return !((*this) < a);
224 template <
class DequeType>
225 class const_deque_iterator
232 typedef typename deque_type::const_pointer
pointer;
254 : m_deque(deque), m_offset(offset)
261 m_deque(it.m_deque), m_offset(it.m_offset)
266 size_type SelfAbsOffset = (m_offset >= m_deque->m_begin) ?
267 m_offset : (m_deque->m_vector.size() + m_offset);
271 return SelfAbsOffset - aAbsOffset;
276 size_type SelfAbsOffset = (m_offset >= m_deque->m_begin) ?
277 m_offset : (m_deque->m_vector.size() + m_offset);
281 return SelfAbsOffset - aAbsOffset;
286 return self_type(m_deque, (m_offset + m_deque->m_vector.size() - op) % m_deque->m_vector.size());
291 return self_type(m_deque, (m_offset + op) % m_deque->m_vector.size());
296 m_offset = (m_offset + m_deque->m_vector.size() - op) % m_deque->m_vector.size();
302 m_offset = (m_offset + op) % m_deque->m_vector.size();
308 return m_deque->m_vector[m_offset];
313 return &(m_deque->m_vector[m_offset]);
318 return m_deque->m_vector[(m_offset + op) % m_deque->m_vector.size()];
323 m_offset = (m_offset + 1) % m_deque->m_vector.size();
329 m_offset = (m_offset + 1) % m_deque->m_vector.size();
334 m_offset = (m_offset + m_deque->m_vector.size() - 1) % m_deque->m_vector.size();
340 m_offset = (m_offset + m_deque->m_vector.size() - 1) % m_deque->m_vector.size();
357 return (a - (*
this)) > 0;
367 return !((*this) > a);
372 return !((*this) < a);
389 return (a - (*
this)) > 0;
399 return !((*this) > a);
404 return !((*this) < a);
421 template <
class ValueType,
class VectorType = stxxl::vector<ValueType> >
422 class deque :
private noncopyable
449 const size_type old_size = m_vector.size();
450 m_vector.resize(2 * old_size);
453 const size_type new_begin = old_size + m_begin;
454 std::copy(m_vector.begin() + m_begin,
455 m_vector.begin() + old_size,
456 m_vector.begin() + new_begin);
467 m_begin(0), m_end(0), m_size(0)
472 m_begin(0), m_end(n), m_size(n)
561 return m_vector[(m_begin + n) % m_vector.size()];
567 return m_vector[(m_begin + n) % m_vector.size()];
573 return m_vector[m_begin];
579 return m_vector[m_begin];
585 return m_vector[(m_end + m_vector.size() - 1) % m_vector.size()];
591 return m_vector[(m_end + m_vector.size() - 1) % m_vector.size()];
601 if ((m_begin + m_vector.size() - 1) % m_vector.size() == m_end)
607 m_begin = (m_begin + m_vector.size() - 1) % m_vector.size();
608 m_vector[m_begin] = el;
614 if ((m_end + 1) % m_vector.size() == m_begin)
619 m_vector[m_end] = el;
620 m_end = (m_end + 1) % m_vector.size();
627 m_begin = (m_begin + 1) % m_vector.size();
634 m_end = (m_end + m_vector.size() - 1) % m_vector.size();
645 std::swap(m_vector, obj.m_vector);
646 std::swap(m_begin, obj.m_begin);
647 std::swap(m_end, obj.m_end);
648 std::swap(m_size, obj.m_size);
672 }
while (n < size());
676 if (n + 1 > m_vector.size())
678 const size_type old_size = m_vector.size();
679 m_vector.resize(2 * n);
682 const size_type new_begin = m_vector.size() - old_size + m_begin;
683 std::copy(m_vector.begin() + m_begin,
684 m_vector.begin() + old_size,
685 m_vector.begin() + new_begin);
689 m_end = (m_end + n - size()) % m_vector.size();
697 template <
class ValueType,
class VectorType>
700 return std::equal(a.begin(), a.end(), b.begin());
703 template <
class ValueType,
class VectorType>
706 return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
715 template <
typename ValueType,
typename VectorType>
724 #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
const Tp & STXXL_MAX(const Tp &a, const Tp &b)
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
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