16 #ifndef STXXL_CONTAINERS_VECTOR_HEADER
17 #define STXXL_CONTAINERS_VECTOR_HEADER
37 #define STXXL_VERBOSE_VECTOR(msg) STXXL_VERBOSE1("vector[" << static_cast<const void*>(this) << "]::" << msg)
49 template <
typename size_type,
size_type modulo2,
size_type modulo1>
52 static const size_type modulo12 = modulo1 * modulo2;
59 void set(size_type pos)
63 pos -= block2 * modulo12;
65 offset = (
int_type)(pos - block1 * modulo1);
67 assert(block2 * modulo12 + block1 * modulo1 + offset == this->pos);
68 assert( block1 < modulo2);
69 assert( offset < modulo1);
85 assert( block1 < modulo2);
86 assert( offset < modulo1);
88 this->block2 = block2;
89 this->block1 = block1;
90 this->offset = offset;
91 pos = block2 * modulo12 + block1 * modulo1 + offset;
105 if (offset == modulo1)
109 if (block1 == modulo2)
116 assert(block2 * modulo12 + block1 * modulo1 + offset == this->pos);
117 assert( block1 < modulo2);
118 assert( offset < modulo1);
147 assert(block2 * modulo12 + block1 * modulo1 + offset == this->pos);
148 assert( block1 < modulo2);
149 assert( offset < modulo1);
180 return pos - dbi2.
pos;
185 set(pos - subtrahend);
191 return pos == dbi2.
pos;
196 return pos != dbi2.
pos;
201 return pos < dbi2.
pos;
206 return pos <= dbi2.
pos;
211 return pos > dbi2.
pos;
216 return pos >= dbi2.
pos;
257 template <
typename ValueType,
typename AllocStr,
typename SizeType,
typename DiffType,
258 unsigned BlockSize,
typename PagerType,
unsigned PageSize>
261 template <
typename VectorIteratorType>
264 template <
typename VectorIteratorType>
267 template <
typename VectorIteratorType>
273 template <
typename ValueType,
typename AllocStr,
typename SizeType,
typename DiffType,
274 unsigned BlockSize,
typename PagerType,
unsigned PageSize>
291 friend class vector<ValueType, PageSize, PagerType, BlockSize, AllocStr, SizeType>;
316 : offset(o), p_vector(v)
322 : offset(0), p_vector(NULL)
346 return p_vector->bid(offset);
357 return p_vector->element(offset);
362 return &(p_vector->element(offset));
367 return p_vector->const_element(offset);
372 return &(p_vector->const_element(offset));
377 return p_vector->element(offset.get_pos() + i);
380 #ifdef _LIBCPP_VERSION
390 return p_vector->const_element(offset.get_pos() + i);
411 return self_type(p_vector, offset.get_pos() - i);
416 return self_type(p_vector, offset.get_pos() + i);
465 return offset == a.
offset;
470 return offset != a.
offset;
480 return offset <= a.
offset;
490 return offset >= a.
offset;
496 return offset == a.
offset;
501 return offset != a.
offset;
511 return offset <= a.
offset;
521 return offset >= a.
offset;
531 p_vector->block_externally_updated(offset);
545 template <
typename ValueType,
typename AllocStr,
typename SizeType,
typename DiffType,
546 unsigned BlockSize,
typename PagerType,
unsigned PageSize>
547 class const_vector_iterator
552 friend class vector_iterator<ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize>;
563 friend class vector<ValueType, PageSize, PagerType, BlockSize, AllocStr, SizeType>;
588 : offset(o), p_vector(v)
594 : offset(0), p_vector(NULL)
598 : offset(a.offset), p_vector(a.p_vector)
602 : offset(a.offset), p_vector(a.p_vector)
632 return p_vector->const_element(offset);
637 return &(p_vector->const_element(offset));
642 return p_vector->const_element(offset.get_pos() + i);
663 return self_type(p_vector, offset.get_pos() - i);
668 return self_type(p_vector, offset.get_pos() + i);
717 return offset == a.
offset;
722 return offset != a.
offset;
732 return offset <= a.
offset;
742 return offset >= a.
offset;
748 return offset == a.
offset;
753 return offset != a.
offset;
763 return offset <= a.
offset;
773 return offset >= a.
offset;
783 p_vector->block_externally_updated(offset);
814 unsigned PageSize = 4,
815 typename PagerType = lru_pager<8>,
844 block_size = BlockSize,
845 page_size = PageSize,
905 enum { valid_on_disk = 0, uninitialized = 1, dirty = 2 };
920 stxxl::uint64 rest = file_length - blocks_fit *
stxxl::uint64(block_type::raw_size);
921 return (cur_size + rest / stxxl::uint64(
sizeof(
value_type)));
928 size_type num_full_blocks = cur_size / block_type::size;
929 if (cur_size % block_type::size != 0)
931 size_type rest = cur_size - num_full_blocks * block_type::size;
932 return file_size_type(num_full_blocks) * block_type::raw_size + rest *
sizeof(
value_type);
934 return file_size_type(num_full_blocks) * block_type::raw_size;
949 m_page_status(
div_ceil(m_bids.size(), page_size)),
950 m_page_to_slot(
div_ceil(m_bids.size(), page_size)),
951 m_slot_to_page(npages),
956 m_bm = block_manager::get_instance();
958 allocate_page_cache();
960 for (
size_t i = 0; i < m_page_status.size(); ++i)
962 m_page_status[i] = uninitialized;
963 m_page_to_slot[i] = on_disk;
967 m_free_slots.push(i);
969 m_bm->new_blocks(m_alloc_strategy, m_bids.begin(), m_bids.end(), 0);
980 std::swap(m_alloc_strategy, obj.m_alloc_strategy);
981 std::swap(m_size, obj.m_size);
982 std::swap(m_bids, obj.m_bids);
983 std::swap(m_pager, obj.m_pager);
984 std::swap(m_page_status, obj.m_page_status);
985 std::swap(m_page_to_slot, obj.m_page_to_slot);
986 std::swap(m_slot_to_page, obj.m_slot_to_page);
987 std::swap(m_free_slots, obj.m_free_slots);
988 std::swap(m_cache, obj.m_cache);
989 std::swap(m_from, obj.m_from);
990 std::swap(m_exported, obj.m_exported);
1002 if (!m_cache && numpages() > 0)
1033 return size_type(m_bids.size()) * block_type::size;
1038 return size_type(m_bids.size()) * block_type::raw_size;
1051 if (n <= capacity())
1057 m_page_status.resize(new_pages, uninitialized);
1058 m_page_to_slot.resize(new_pages, on_disk);
1060 m_bids.resize(new_bids_size);
1063 m_bm->new_blocks(m_alloc_strategy,
1064 m_bids.begin() + old_bids_size, m_bids.end(),
1071 it != m_bids.end(); ++it, offset +=
size_type(block_type::raw_size))
1073 (*it).storage = m_from;
1074 (*it).offset = offset;
1077 ((
void*)m_from) <<
" to " << offset);
1078 m_from->set_size(offset);
1094 if (shrink_capacity)
1095 _resize_shrink_capacity(n);
1110 for (
size_t i = first_page_to_evict; i < m_page_status.size(); ++i) {
1111 if (m_page_to_slot[i] != on_disk) {
1112 m_free_slots.push(m_page_to_slot[i]);
1113 m_page_to_slot[i] = on_disk;
1115 m_page_status[i] = uninitialized;
1127 if (new_bids_size > old_bids_size)
1131 else if (new_bids_size < old_bids_size)
1136 new_bids_size <<
" blocks = from " <<
1137 m_page_status.size() <<
" to " <<
1138 new_pages_size <<
" pages");
1142 m_from->set_size(new_bids_size * block_type::raw_size);
1144 m_bm->delete_blocks(m_bids.begin() + old_bids_size, m_bids.end());
1146 m_bids.resize(new_bids_size);
1153 std::fill(m_page_status.begin() + new_pages_size,
1154 m_page_status.end(), (
unsigned char)valid_on_disk);
1170 m_bm->delete_blocks(m_bids.begin(), m_bids.end());
1173 m_page_status.clear();
1174 m_page_to_slot.clear();
1175 while (!m_free_slots.empty())
1179 m_free_slots.push(i);
1189 resize(old_size + 1);
1190 element(old_size) = obj;
1206 return element(m_size - 1);
1216 return const_element(m_size - 1);
1221 return const_element(0);
1237 : m_size((size ==
size_type(-1)) ? size_from_file_length(from->size()) : size),
1240 m_page_status(
div_ceil(m_bids.size(), page_size)),
1241 m_page_to_slot(
div_ceil(m_bids.size(), page_size)),
1242 m_slot_to_page(npages),
1248 if (!block_type::has_only_data)
1250 std::ostringstream str;
1251 str <<
"The block size for a vector that is mapped to a file must be a multiple of the element size (" <<
1252 sizeof(
value_type) <<
") and the page size (4096).";
1253 throw std::runtime_error(str.str());
1256 m_bm = block_manager::get_instance();
1258 allocate_page_cache();
1260 for (
size_t i = 0; i < m_page_status.size(); ++i)
1262 m_page_status[i] = valid_on_disk;
1263 m_page_to_slot[i] = on_disk;
1267 m_free_slots.push(i);
1273 it != m_bids.end(); ++it, offset +=
size_type(block_type::raw_size))
1275 (*it).storage = from;
1276 (*it).offset = offset;
1283 : m_size(obj.size()),
1285 m_pager(obj.numpages()),
1286 m_page_status(
div_ceil(m_bids.size(), page_size)),
1287 m_page_to_slot(
div_ceil(m_bids.size(), page_size)),
1288 m_slot_to_page(obj.numpages()),
1293 assert(!obj.m_exported);
1294 m_bm = block_manager::get_instance();
1296 allocate_page_cache();
1298 for (
size_t i = 0; i < m_page_status.size(); ++i)
1300 m_page_status[i] = uninitialized;
1301 m_page_to_slot[i] = on_disk;
1305 m_free_slots.push(i);
1307 m_bm->new_blocks(m_alloc_strategy, m_bids.begin(), m_bids.end(), 0);
1311 std::copy(inbegin, inend, begin());
1405 return element(offset);
1410 return const_element(offset);
1417 return element(offset);
1423 return const_element(offset);
1443 non_free_slots[i] =
true;
1445 while (!m_free_slots.empty())
1447 non_free_slots[m_free_slots.front()] =
false;
1453 m_free_slots.push(i);
1454 int_type page_no = m_slot_to_page[i];
1455 if (non_free_slots[i])
1459 write_page(page_no, i);
1461 m_page_to_slot[page_no] = on_disk;
1480 STXXL_ERRMSG(
"io_error thrown in ~vector(): " << e.what());
1489 if (m_from == NULL) {
1490 m_bm->delete_blocks(m_bids.begin(), m_bids.end());
1495 ((
void*)m_from) <<
" to " << file_length());
1499 m_from->set_size(file_length());
1503 STXXL_ERRMSG(
"Exception thrown in ~vector()...set_size()");
1521 std::ostringstream number;
1522 number << std::setw(9) << std::setfill(
'0') << no;
1524 ((i + 1) == m_bids.end() && m_size % block_type::size > 0) ?
1525 (m_size % block_type::size) *
sizeof(
value_type) :
1527 (*i).storage->export_files((*i).offset, current_block_size, filename_prefix + number.str());
1546 template <
typename ForwardIterator>
1550 m_bids.resize(new_bids_size);
1551 std::copy(bid_begin, bid_end, m_bids.begin());
1553 m_page_status.resize(new_pages, valid_on_disk);
1554 m_page_to_slot.resize(new_pages, on_disk);
1561 return m_pager.size();
1569 return (m_bids.begin() +
1570 static_cast<typename bids_container_type::size_type
>
1571 (offset / block_type::size));
1575 return (m_bids.begin() +
1576 static_cast<typename bids_container_type::size_type
>
1581 return (m_bids.begin() +
1582 static_cast<typename bids_container_type::size_type
>
1583 (offset / block_type::size));
1587 return (m_bids.begin() +
1588 static_cast<typename bids_container_type::size_type
>
1594 assert(page_no < (
int_type)m_page_status.size());
1595 if (m_page_status[page_no] == uninitialized)
1599 int_type block_no = page_no * page_size;
1601 int_type i = cache_slot * page_size, j = 0;
1602 for ( ; block_no < last_block; ++block_no, ++i, ++j)
1604 reqs[j] = (*m_cache)[i].read(m_bids[block_no]);
1606 assert(last_block - page_no * page_size > 0);
1607 wait_all(reqs, last_block - page_no * page_size);
1612 assert(page_no < (
int_type)m_page_status.size());
1613 if (!(m_page_status[page_no] & dirty))
1617 int_type block_no = page_no * page_size;
1619 assert(block_no < last_block);
1620 int_type i = cache_slot * page_size, j = 0;
1621 for ( ; block_no < last_block; ++block_no, ++i, ++j)
1623 reqs[j] = (*m_cache)[i].write(m_bids[block_no]);
1625 m_page_status[page_no] = valid_on_disk;
1626 assert(last_block - page_no * page_size > 0);
1627 wait_all(reqs, last_block - page_no * page_size);
1633 #ifdef STXXL_RANGE_CHECK
1641 #ifdef STXXL_RANGE_CHECK
1642 assert(offset.
get_pos() < size());
1645 assert(page_no < m_page_to_slot.size());
1646 int_type cache_slot = m_page_to_slot[page_no];
1649 if (m_free_slots.empty())
1651 int_type kicked_slot = m_pager.kick();
1652 m_pager.hit(kicked_slot);
1653 int_type old_page_no = m_slot_to_page[kicked_slot];
1654 m_page_to_slot[page_no] = kicked_slot;
1655 m_page_to_slot[old_page_no] = on_disk;
1656 m_slot_to_page[kicked_slot] = page_no;
1658 write_page(old_page_no, kicked_slot);
1659 read_page(page_no, kicked_slot);
1661 m_page_status[page_no] = dirty;
1667 int_type free_slot = m_free_slots.front();
1669 m_pager.hit(free_slot);
1670 m_page_to_slot[page_no] = free_slot;
1671 m_slot_to_page[free_slot] = page_no;
1673 read_page(page_no, free_slot);
1675 m_page_status[page_no] = dirty;
1682 m_page_status[page_no] = dirty;
1683 m_pager.hit(cache_slot);
1692 assert(page_no < m_page_status.size());
1694 assert(!(m_page_status[page_no] & dirty));
1695 if (m_page_to_slot[page_no] != on_disk) {
1697 m_free_slots.push(m_page_to_slot[page_no]);
1698 m_page_to_slot[page_no] = on_disk;
1699 STXXL_VERBOSE_VECTOR(
"page_externally_updated(): page_no=" << page_no <<
" flushed from cache.");
1702 STXXL_VERBOSE_VECTOR(
"page_externally_updated(): page_no=" << page_no <<
" no need to flush.");
1704 m_page_status[page_no] = valid_on_disk;
1709 page_externally_updated(offset / (block_type::size * page_size));
1714 page_externally_updated(offset.
get_block2());
1725 assert(page_no < m_page_to_slot.size());
1726 int_type cache_slot = m_page_to_slot[page_no];
1729 if (m_free_slots.empty())
1731 int_type kicked_slot = m_pager.kick();
1732 m_pager.hit(kicked_slot);
1733 int_type old_page_no = m_slot_to_page[kicked_slot];
1734 m_page_to_slot[page_no] = kicked_slot;
1735 m_page_to_slot[old_page_no] = on_disk;
1736 m_slot_to_page[kicked_slot] = page_no;
1738 write_page(old_page_no, kicked_slot);
1739 read_page(page_no, kicked_slot);
1745 int_type free_slot = m_free_slots.front();
1747 m_pager.hit(free_slot);
1748 m_page_to_slot[page_no] = free_slot;
1749 m_slot_to_page[free_slot] = page_no;
1751 read_page(page_no, free_slot);
1758 m_pager.hit(cache_slot);
1766 assert(page_no < m_page_to_slot.size());
1767 int_type cache_slot = m_page_to_slot[page_no];
1768 return (cache_slot >= 0);
1780 AllocStr, SizeType>& a,
1782 AllocStr, SizeType>& b)
1784 return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
1795 AllocStr, SizeType>& a,
1797 AllocStr, SizeType>& b)
1810 AllocStr, SizeType>& a,
1812 AllocStr, SizeType>& b)
1814 return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
1825 AllocStr, SizeType>& a,
1827 AllocStr, SizeType>& b)
1840 AllocStr, SizeType>& a,
1842 AllocStr, SizeType>& b)
1855 AllocStr, SizeType>& a,
1857 AllocStr, SizeType>& b)
1865 template <
typename ValueType,
typename AllocStr,
typename SizeType,
typename DiffType,
1866 unsigned BlockSize,
typename PagerType,
unsigned PageSize>
1876 template <
typename ValueType,
typename AllocStr,
typename SizeType,
typename DiffType,
1877 unsigned BlockSize,
typename PagerType,
unsigned PageSize,
typename _StrictWeakOrdering>
1881 _StrictWeakOrdering __comp)
1891 template <
typename VectorBufReaderType>
1910 template <
typename VectorIterator>
1960 : m_begin(begin), m_end(end),
1962 m_nbuffers(nbuffers)
1966 if (m_nbuffers == 0)
1967 m_nbuffers = 2 * config::get_instance()->disks_number();
1976 : m_begin(vec.begin()), m_end(vec.end()),
1978 m_nbuffers(nbuffers)
1982 if (m_nbuffers == 0)
1983 m_nbuffers = 2 * config::get_instance()->disks_number();
1993 if (empty())
return;
1995 if (m_bufin)
delete m_bufin;
2006 for ( ; curr != m_begin; ++curr)
2013 if (m_bufin)
delete m_bufin;
2025 return &(*(*m_bufin));
2055 assert(m_begin <= m_iter && m_iter <= m_end);
2056 return (m_end - m_iter);
2062 return (m_iter == m_end);
2093 template <
typename VectorBufReaderType>
2094 class vector_bufreader_iterator
2116 : m_bufreader(bufreader), m_iter(iter)
2122 assert(m_bufreader.m_iter == m_iter);
2123 return m_bufreader.operator * ();
2129 assert(m_bufreader.m_iter == m_iter);
2130 return m_bufreader.operator -> ();
2137 assert(m_bufreader.m_iter == m_iter);
2138 m_bufreader.operator ++ ();
2146 assert(&m_bufreader == &vbi.m_bufreader);
2147 return (m_iter == vbi.m_iter);
2153 assert(&m_bufreader == &vbi.m_bufreader);
2154 return (m_iter != vbi.m_iter);
2177 template <
typename VectorIterator>
2178 class vector_bufreader_reverse :
public noncopyable
2221 : m_begin(begin), m_end(end),
2223 m_nbuffers(nbuffers)
2227 if (m_nbuffers == 0)
2228 m_nbuffers = 2 * config::get_instance()->disks_number();
2237 : m_begin(vec.begin()), m_end(vec.end()),
2239 m_nbuffers(nbuffers)
2243 if (m_nbuffers == 0)
2244 m_nbuffers = 2 * config::get_instance()->disks_number();
2254 if (empty())
return;
2256 if (m_bufin)
delete m_bufin;
2272 for ( ; endoff != block_type::size; endoff++)
2280 if (m_bufin)
delete m_bufin;
2292 return &(*(*m_bufin));
2322 assert(m_begin <= m_iter && m_iter <= m_end);
2323 return (m_iter - m_begin);
2329 return (m_iter == m_begin);
2350 template <
typename VectorIterator>
2351 class vector_bufwriter :
public noncopyable
2403 m_end(m_iter.parent_vector()->end()),
2406 m_nbuffers(nbuffers)
2408 if (m_nbuffers == 0)
2409 m_nbuffers = 2 * config::get_instance()->disks_number();
2411 assert(m_iter <= m_end);
2419 : m_iter(vec.begin()),
2420 m_end(m_iter.parent_vector()->end()),
2423 m_nbuffers(nbuffers)
2425 if (m_nbuffers == 0)
2426 m_nbuffers = 2 * config::get_instance()->disks_number();
2428 assert(m_iter <= m_end);
2450 if (m_iter.block_offset() != 0)
2451 m_iter.block_externally_updated();
2455 if (v.size() < 2 * block_type::size) {
2456 v.resize(2 * block_type::size);
2459 v.resize(2 * v.size());
2465 assert(m_iter < m_end);
2469 if (m_iter.block_offset() != 0)
2492 if (
UNLIKELY(m_iter.block_offset() == 0)) {
2493 if (m_prevblk != m_iter) {
2494 m_prevblk.block_externally_updated();
2499 return m_bufout->operator * ();
2509 if (
LIKELY(m_bufout != NULL)) m_bufout->operator ++ ();
2532 while (const_out.block_offset() != 0)
2534 m_bufout->operator * () = *const_out;
2535 m_bufout->operator ++ ();
2540 if (m_prevblk != m_iter) {
2541 m_prevblk.block_externally_updated();
2552 v.resize(m_iter - v.begin());
2574 unsigned PageSize = 4,
2575 unsigned CachePages = 8,
2582 typedef typename IF<Pager ==
lru,
2609 #endif // !STXXL_CONTAINERS_VECTOR_HEADER
vector_bufreader< const_iterator > bufreader_type
vector_bufreader compatible with this vector
vector_type::reference reference
vector_iterator m_end
iterator to the end of the range.
vector_bufreader_reverse(vector_iterator begin, vector_iterator end, unsigned_type nbuffers=0)
Create overlapped reader for the given iterator range.
const_reverse_iterator crbegin() const
returns a reverse_iterator pointing to the end of the vector.
const Tp & STXXL_MIN(const Tp &a, const Tp &b)
const unsigned_type & get_offset() const
bids_container_type::bid_type bid_type
Const external vector iterator, model of ext_random_access_iterator concept.
vector_iterator()
constructs invalid iterator
void _resize(size_type n)
Resize vector, only allow capacity growth.
void read_page(int_type page_no, int_type cache_slot) const
size_type capacity() const
Return the number of elelemtsn for which external memory has been allocated. capacity() is always gre...
#define STXXL_DEFAULT_BLOCK_SIZE(type)
virtual void set_size(offset_type newsize)=0
Changes the size of the file.
std::random_access_iterator_tag iterator_category
bids_container_iterator bid(const size_type &offset)
value_type & reference
reference to value_type
bool empty() const
true if the vector's size is zero.
~vector_bufreader_reverse()
Finish reading and free buffered reader.
friend std::ostream & operator<<(std::ostream &os, const uint_pair &a)
make a uint_pair outputtable via iostreams, using unsigned long long.
iterator::vector_type vector_type
type of the output vector
vector< ValueType, PageSize, PagerType, BlockSize, AllocStr, SizeType > vector_type
vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > mutable_self_type
std::vector< unsigned char > m_page_status
status of each page (valid_on_disk, uninitialized or dirty)
std::vector< BID< block_size > > super_type
const unsigned_type & get_block1() const
Buffered sequential reverse reader from a vector using overlapped I/O.
~vector_bufwriter()
Finish writing and flush output back to vector.
vector_iterator::bids_container_iterator bids_container_iterator
block identifier iterator of the vector
vector_iterator::value_type value_type
value type of the output vector
bool is_sorted(_ForwardIter __first, _ForwardIter __last)
iterator end()
returns an iterator pointing beyond the end of the vector, see More Notes.
const_vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > self_type
void export_files(std::string filename_prefix)
Export data such that it is persistent on the file system. Resulting files will be numbered ascending...
file * get_file() const
Get the file associated with this vector, or NULL.
vector_iterator::block_type block_type
block type used in the vector
super_type::size_type size_type
vector_iterator m_begin
iterator to the beginning of the range.
#define STXXL_VERBOSE_VECTOR(msg)
void clear()
Erases all of the elements and deallocates all external memory that is occupied.
block_offset_type block_offset() const
return block offset of current element
unsigned long long int uint64
vector_type::blocked_index_type blocked_index_type
iterator::iterator vector_iterator
iterator type of vector
ValueType value_type
The type of elements stored in the vector.
const value_type & const_reference
constant reference to value_type
vector_bufreader(vector_iterator begin, vector_iterator end, unsigned_type nbuffers=0)
Create overlapped reader for the given iterator range.
void rewind()
Rewind stream back to begin. Note that this recreates the buffered reader and is thus not cheap...
const_vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > const_self_type
vector_iterator::vector_type vector_type
type of the input vector
const vector_type * p_vector
vector_iterator m_iter
Use vector_iterator to reference a point in the vector.
vector_bufreader_reverse(const vector_type &vec, unsigned_type nbuffers=0)
Create overlapped reader for the whole vector's content.
reverse_iterator rend()
returns a reverse_iterator pointing beyond the beginning of the vector.
vector(file *from, size_type size=size_type(-1), unsigned_type npages=pager_type().size())
Construct vector from a file.
const_iterator end() const
returns a const_iterator pointing beyond the end of the vector, see More Notes.
Buffered sequential writer to a vector using overlapped I/O.
bids_container_type m_bids
const_reference at(size_type offset) const
access the element at the given vector's offset
#define STXXL_DEFAULT_ALLOC_STRATEGY
iterator::block_type block_type
block type used in the vector
Adapter for vector_bufreader to match iterator requirements of C++11 range-based loop construct...
vector_iterator m_iter
internal "current" iterator into the vector.
size_type size() const
return the size of the vector.
vector_type::size_type size_type
size_t size() const
Return remaining size.
Buffered sequential reader from a vector using overlapped I/O.
vector_bufreader(const vector_type &vec, unsigned_type nbuffers=0)
Create overlapped reader for the whole vector's content.
const_iterator cend() const
returns a const_iterator pointing beyond the end of the vector, see More Notes.
unsigned block_offset_type
External vector container. Introduction to vector container: see STXXL Vector tutorial. Design and Internals of vector container: see Vector.
std::reverse_iterator< iterator > reverse_iterator
vector(size_type n=0, unsigned_type npages=pager_type().size())
Constructs external vector with n elements.
unsigned_type m_nbuffers
number of blocks to use as buffers.
Pager with random replacement strategy.
bool is_page_cached(const blocked_index_type &offset) const
bool empty() const
Returns true once the whole range has been read.
vector_iterator::vector_type vector_type
type of the input vector
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
bids_container_type::const_iterator const_bids_container_iterator
vector< ValueType, PageSize, PagerType, BlockSize, AllocStr, SizeType > vector_type
std::random_access_iterator_tag iterator_category
void reserve(size_type n)
Reserves at least n elements in external memory.
iterator::value_type value_type
value type of the output vector
void wait_all(request_iterator_ reqs_begin, request_iterator_ reqs_end)
Collection of functions to track statuses of a number of requests.
vector_bufwriter< iterator > bufwriter_type
vector_bufwriter compatible with this vector
vector_type * parent_vector() const
return pointer to vector containing iterator
std::vector< int_type > m_page_to_slot
const_reference const_element(const blocked_index_type &offset) const
vector_iterator< value_type, alloc_strategy_type, size_type, difference_type, block_size, pager_type, page_size > iterator
iterator used to iterate through a vector, see More Notes.
void resize(size_type n)
Resize vector contents to n items.
void page_externally_updated(unsigned_type page_no) const
vector_type::blocked_index_type blocked_index_type
void pop_back()
Removes the last element (without returning it, see back()).
vector_type::const_pointer pointer
bids_container_type::bid_type bid_type
vector_const_iterator m_end
iterator to the current end of the vector.
void resize(size_type n, bool shrink_capacity)
Resize vector contents to n items, and allow the allocated external memory to shrink. Internal memory allocation remains unchanged.
vector_type::const_reference const_reference
bids_container_type::iterator bids_container_iterator
vector(const vector &obj)
copy-constructor
void allocate_page_cache() const
Allocate page cache, must be called to allow access to elements.
const_vector_iterator()
constructs invalid iterator
void block_externally_updated(const blocked_index_type &offset) const
const_bids_container_iterator bid(const blocked_index_type &offset) const
const vector_type * parent_vector() const
return pointer to vector containing iterator
uint_pair & operator+=(const uint_pair &b)
addition operator (uses 64-bit arithmetic)
vector_iterator(vector_type *v, size_type o)
private constructor for initializing other iterators
iterator begin()
returns an iterator pointing to the beginning of the vector, see More Notes.
typed_block< BlockSize, ValueType > block_type
type of the block used in disk-memory transfers
const_reverse_iterator rbegin() const
returns a reverse_iterator pointing to the end of the vector.
double_blocked_index< SizeType, PageSize, block_type::size > blocked_index_type
double-index type to reference individual elements in a block
Block containing elements of fixed length.
reverse_iterator rbegin()
returns a reverse_iterator pointing to the end of the vector.
unsigned block_offset_type
VectorIterator iterator
template parameter: the vector iterator type
~vector_bufreader()
Finish reading and free buffered reader.
Defines interface of file.
void deallocate_page_cache() const
allows to free the cache, but you may not access any element until call allocate_page_cache() again ...
bufreader_iterator end()
Return vector_bufreader_iterator for C++11 range-based for loop.
vector_type::pointer pointer
vector_iterator m_iter
internal "current" iterator into the vector.
bool operator!=(const uint_pair &b) const
inequality checking operator
bool operator<=(const uint_pair &b) const
less-or-equal comparison operator
vector_type::size_type size_type
choose_int_types< my_pointer_size >::int_type int_type
bool operator>(const uint_pair &b) const
greater comparison operator
vector_type::block_type block_type
iterator::const_iterator vector_const_iterator
const value_type * const_pointer
constant pointer to value_type
size_type raw_capacity() const
Returns the number of bytes that the vector has allocated on disks.
blocked_index_type offset
void block_externally_updated()
super_type::value_type bid_type
Buffered input stream, reading the items in the blocks in reverse order.
vector_type::bids_container_type bids_container_type
vector_type::bids_container_type bids_container_type
alloc_strategy_type m_alloc_strategy
unsigned_type numpages() const
Number of pages used by the pager.
bool operator>=(const uint_pair &b) const
greater-or-equal comparison operator
const unsigned_type & get_block2() const
const_reverse_iterator crend() const
returns a reverse_iterator pointing beyond the beginning of the vector.
void rewind()
Rewind stream back to begin. Note that this recreates the buffered reader and is thus not cheap...
vector_type::value_type value_type
bool operator<(const uint_pair &b) const
less-than comparison operator
vector_type::difference_type difference_type
size_t size() const
Return remaining size.
buf_ostream_type * m_bufout
buffered output stream used to overlapped I/O.
#define STXXL_BEGIN_NAMESPACE
vector_iterator::bids_container_iterator bids_container_iterator
block identifier iterator of the vector
bids_container_type::iterator bids_container_iterator
mutable_self_type iterator
vector_bufwriter(vector_iterator begin, unsigned_type nbuffers=0)
Create overlapped writer beginning at the given iterator.
const_vector_iterator(const mutable_self_type &a)
copy-constructor from mutable iterator
uint_pair & operator--()
prefix decrement operator (directly manipulates the integer parts)
bids_container_type::iterator bids_container_iterator
vector_type::difference_type difference_type
bids_container_iterator bid() const
return iterator to BID containg current element
vector_bufreader_reverse< const_iterator > bufreader_reverse_type
vector_bufreader compatible with this vector
vector_iterator::value_type value_type
value type of the output vector
double_blocked_index(unsigned_type block2, unsigned_type block1, unsigned_type offset)
size_type get_pos() const
AllocStr alloc_strategy_type
reference element(size_type offset)
void push_back(const_reference obj)
Append a new element at the end.
bufreader_iterator begin()
Return vector_bufreader_iterator for C++11 range-based for loop.
vector_type::const_reference reference
External vector iterator, model of ext_random_access_iterator concept.
vector_iterator m_begin
iterator to the beginning of the range.
value_type * pointer
pointer to value_type
vector_bufreader_type & m_bufreader
Buffered reader used to access elements in vector.
buf_istream< block_type, bids_container_iterator > buf_istream_type
construct output buffered stream used for overlapped reading
buf_istream_type * m_bufin
buffered input stream used to overlapped I/O.
vector_iterator(const self_type &a)
copy-constructor
stxxl::int64 difference_type
unsigned_type m_nbuffers
number of blocks to use as buffers.
buf_ostream< block_type, bids_container_iterator > buf_ostream_type
construct output buffered stream used for overlapped writing
VectorBufReaderType vector_bufreader_type
The underlying buffered reader type.
vector_iterator m_end
iterator to the end of the range.
blocked_index_type offset
bids_container_iterator bid() const
return iterator to BID containg current element
vector_bufreader_iterator(vector_bufreader_type &bufreader, const vector_iterator &iter)
Construct iterator using vector_iterator.
const_vector_iterator< value_type, alloc_strategy_type, size_type, difference_type, block_size, pager_type, page_size > const_iterator
constant iterator used to iterate through a vector, see More Notes.
vector_type::const_reference const_reference
bids_container_iterator bid(const blocked_index_type &offset)
iterator::bids_container_iterator bids_container_iterator
block identifier iterator of the vector
void write_page(int_type page_no, int_type cache_slot) const
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
block_offset_type block_offset() const
return block offset of current element
compat::remove_const< Integral >::type div_ceil(Integral __n, Integral2 __d)
bool empty() const
Returns true once the whole range has been read.
const_reference back() const
Returns a constant reference to the last element, see More Notes.
reference at(size_type offset)
access the element at the given vector's offset
IF< Pager==lru, lru_pager< CachePages >, random_pager< CachePages > >::result PagerType
void _resize_shrink_capacity(size_type n)
Resize vector, also allow reduction of external memory capacity.
vector_iterator::block_type block_type
block type used in the vector
SizeType size_type
an unsigned 64-bit integral type
void finish()
Finish writing and flush output back to vector.
vector_type::block_type block_type
vector_bufreader_type::value_type value_type
Value type of vector.
vector< ValueType, PageSize, PagerType, BlockSize, AllocStr > result
const_reference const_element(size_type offset) const
const_reverse_iterator rend() const
returns a reverse_iterator pointing beyond the beginning of the vector.
IF template metaprogramming statement.
const_iterator cbegin() const
returns a const_iterator pointing to the beginning of the vector, see More Notes. ...
bool is_sorted_helper(_ForwardIter __first, _ForwardIter __last)
void block_externally_updated()
const_self_type const_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
VectorIterator vector_iterator
template parameter: the vector iterator type
vector_type::const_pointer const_pointer
bid_vector bids_container_type
const_vector_iterator(const self_type &a)
copy-constructor
vector_bufwriter(vector_type &vec, unsigned_type nbuffers=0)
Create overlapped writer for the vector's beginning.
VectorIterator vector_iterator
template parameter: the vector iterator type
stxxl::uint64 file_length() const
void set_content(const ForwardIterator &bid_begin, const ForwardIterator &bid_end, size_type n)
Set the blocks and the size of this container explicitly. The vector must be completely empty before...
std::queue< int_type > m_free_slots
bool is_element_cached(size_type offset) const
return true if the given vector offset is in cache
buf_istream_reverse< block_type, bids_container_iterator > buf_istream_type
construct output buffered stream used for overlapped reading
vector_bufreader_iterator< vector_bufreader > bufreader_iterator
construct an iterator for vector_bufreader (for C++11 range-based for loop)
unsigned_type m_nbuffers
number of blocks to use as buffers.
void block_externally_updated(size_type offset) const
const_vector_iterator(const vector_type *v, size_type o)
private constructor for initializing other iterators
vector_type::value_type value_type
size_type size_from_file_length(stxxl::uint64 file_length) const
reference element(const blocked_index_type &offset)
vector_iterator m_iter
internal iterator into the vector.
External vector type generator.
simple_vector< int_type > m_slot_to_page
const_bids_container_iterator bid(const size_type &offset) const
reference back()
Returns a reference to the last element, see More Notes.
bool m_grown
boolean whether the vector was grown, will shorten at finish().
void flush() const
Flushes the cache pages to the external memory.
vector_type::const_pointer const_pointer
bool operator==(const uint_pair &b) const
equality checking operator
vector_const_iterator m_prevblk
iterator into vector of the last block accessed (used to issue updates when the block is switched)...
reference front()
Returns a reference to the first element, see More Notes.
const_reference front() const
Returns a constant reference to the first element, see More Notes.
#define STXXL_END_NAMESPACE
simple_vector< block_type > * m_cache
const_iterator begin() const
returns a const_iterator pointing to the beginning of the vector, see More Notes. ...
vector_iterator< ValueType, AllocStr, SizeType, DiffType, BlockSize, PagerType, PageSize > self_type
vector_bufreader_type::vector_iterator vector_iterator
Use vector_iterator to reference a point in the vector.
buf_istream_type * m_bufin
buffered input stream used to overlapped I/O.
double_blocked_index(size_type pos)
void swap(vector &obj)
swap content