16 #ifndef STXXL_CONTAINERS_VECTOR_HEADER
17 #define STXXL_CONTAINERS_VECTOR_HEADER
36 #define STXXL_VERBOSE_VECTOR(msg) STXXL_VERBOSE1("vector[" << static_cast<const void*>(this) << "]::" << msg)
47 template <
typename SizeType, SizeType modulo2, SizeType modulo1>
52 static const size_type modulo12 = modulo1 * modulo2;
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>
284 DiffType, BlockSize, PagerType, PageSize>;
295 friend class vector<ValueType, PageSize, PagerType, BlockSize, AllocStr, SizeType>;
320 : offset(o), p_vector(v)
326 : offset(0), p_vector(NULL)
350 return p_vector->bid(offset);
361 return p_vector->element(offset);
366 return &(p_vector->element(offset));
371 return p_vector->const_element(offset);
376 return &(p_vector->const_element(offset));
381 return p_vector->element(offset.get_pos() + i);
384 #ifdef _LIBCPP_VERSION
394 return p_vector->const_element(offset.get_pos() + i);
415 return self_type(p_vector, offset.get_pos() - i);
420 return self_type(p_vector, offset.get_pos() + i);
469 return offset == a.
offset;
474 return offset != a.
offset;
484 return offset <= a.
offset;
494 return offset >= a.
offset;
500 return offset == a.
offset;
505 return offset != a.
offset;
515 return offset <= a.
offset;
525 return offset >= a.
offset;
535 p_vector->block_externally_updated(offset);
549 template <
typename ValueType,
typename AllocStr,
typename SizeType,
typename DiffType,
550 unsigned BlockSize,
typename PagerType,
unsigned PageSize>
551 class const_vector_iterator
553 typedef const_vector_iterator<ValueType, AllocStr, SizeType, DiffType,
560 BlockSize, PagerType, PageSize>;
571 friend class vector<ValueType, PageSize, PagerType, BlockSize, AllocStr, SizeType>;
596 : offset(o), p_vector(v)
602 : offset(0), p_vector(NULL)
606 : offset(a.offset), p_vector(a.p_vector)
610 : offset(a.offset), p_vector(a.p_vector)
640 return p_vector->const_element(offset);
645 return &(p_vector->const_element(offset));
650 return p_vector->const_element(offset.get_pos() + i);
671 return self_type(p_vector, offset.get_pos() - i);
676 return self_type(p_vector, offset.get_pos() + i);
725 return offset == a.
offset;
730 return offset != a.
offset;
740 return offset <= a.
offset;
750 return offset >= a.
offset;
756 return offset == a.
offset;
761 return offset != a.
offset;
771 return offset <= a.
offset;
781 return offset >= a.
offset;
791 p_vector->block_externally_updated(offset);
822 unsigned PageSize = 4,
823 typename PagerType = lru_pager<8>,
852 block_size = BlockSize,
853 page_size = PageSize,
913 enum { valid_on_disk = 0, uninitialized = 1, dirty = 2 };
928 stxxl::uint64 rest = file_length - blocks_fit *
stxxl::uint64(block_type::raw_size);
929 return (cur_size + rest / stxxl::uint64(
sizeof(
value_type)));
936 size_type num_full_blocks = cur_size / block_type::size;
937 if (cur_size % block_type::size != 0)
939 size_type rest = cur_size - num_full_blocks * block_type::size;
940 return file_size_type(num_full_blocks) * block_type::raw_size + rest *
sizeof(
value_type);
942 return file_size_type(num_full_blocks) * block_type::raw_size;
957 m_page_status(
div_ceil(m_bids.size(), page_size)),
958 m_page_to_slot(
div_ceil(m_bids.size(), page_size)),
959 m_slot_to_page(npages),
964 m_bm = block_manager::get_instance();
966 allocate_page_cache();
968 for (
size_t i = 0; i < m_page_status.size(); ++i)
970 m_page_status[i] = uninitialized;
971 m_page_to_slot[i] = on_disk;
975 m_free_slots.push(i);
977 m_bm->new_blocks(m_alloc_strategy, m_bids.begin(), m_bids.end(), 0);
988 std::swap(m_alloc_strategy, obj.m_alloc_strategy);
989 std::swap(m_size, obj.m_size);
990 std::swap(m_bids, obj.m_bids);
991 std::swap(m_pager, obj.m_pager);
992 std::swap(m_page_status, obj.m_page_status);
993 std::swap(m_page_to_slot, obj.m_page_to_slot);
994 std::swap(m_slot_to_page, obj.m_slot_to_page);
995 std::swap(m_free_slots, obj.m_free_slots);
996 std::swap(m_cache, obj.m_cache);
997 std::swap(m_from, obj.m_from);
998 std::swap(m_exported, obj.m_exported);
1010 if (!m_cache && numpages() > 0)
1041 return size_type(m_bids.size()) * block_type::size;
1046 return size_type(m_bids.size()) * block_type::raw_size;
1059 if (n <= capacity())
1065 m_page_status.resize(new_pages, uninitialized);
1066 m_page_to_slot.resize(new_pages, on_disk);
1068 m_bids.resize(new_bids_size);
1071 m_bm->new_blocks(m_alloc_strategy,
1072 m_bids.begin() + old_bids_size, m_bids.end(),
1079 it != m_bids.end(); ++it, offset +=
size_type(block_type::raw_size))
1081 (*it).storage = m_from;
1082 (*it).offset = offset;
1085 ((
void*)m_from) <<
" to " << offset);
1086 m_from->set_size(offset);
1102 if (shrink_capacity)
1103 _resize_shrink_capacity(n);
1118 for (
size_t i = first_page_to_evict; i < m_page_status.size(); ++i) {
1119 if (m_page_to_slot[i] != on_disk) {
1120 m_free_slots.push(m_page_to_slot[i]);
1121 m_page_to_slot[i] = on_disk;
1123 m_page_status[i] = uninitialized;
1135 if (new_bids_size > old_bids_size)
1139 else if (new_bids_size < old_bids_size)
1144 new_bids_size <<
" blocks = from " <<
1145 m_page_status.size() <<
" to " <<
1146 new_pages_size <<
" pages");
1150 m_from->set_size(new_bids_size * block_type::raw_size);
1152 m_bm->delete_blocks(m_bids.begin() + old_bids_size, m_bids.end());
1154 m_bids.resize(new_bids_size);
1161 std::fill(m_page_status.begin() + new_pages_size,
1162 m_page_status.end(), (
unsigned char)valid_on_disk);
1178 m_bm->delete_blocks(m_bids.begin(), m_bids.end());
1181 m_page_status.clear();
1182 m_page_to_slot.clear();
1183 while (!m_free_slots.empty())
1187 m_free_slots.push(i);
1197 resize(old_size + 1);
1198 element(old_size) = obj;
1214 return element(m_size - 1);
1224 return const_element(m_size - 1);
1229 return const_element(0);
1245 : m_size((size ==
size_type(-1)) ? size_from_file_length(from->size()) : size),
1248 m_page_status(
div_ceil(m_bids.size(), page_size)),
1249 m_page_to_slot(
div_ceil(m_bids.size(), page_size)),
1250 m_slot_to_page(npages),
1256 if (!block_type::has_only_data)
1258 std::ostringstream str;
1259 str <<
"The block size for a vector that is mapped to a file must be a multiple of the element size (" <<
1260 sizeof(
value_type) <<
") and the page size (4096).";
1261 throw std::runtime_error(str.str());
1264 m_bm = block_manager::get_instance();
1266 allocate_page_cache();
1268 for (
size_t i = 0; i < m_page_status.size(); ++i)
1270 m_page_status[i] = valid_on_disk;
1271 m_page_to_slot[i] = on_disk;
1275 m_free_slots.push(i);
1280 it != m_bids.end(); ++it, offset +=
size_type(block_type::raw_size))
1282 (*it).storage = from;
1283 (*it).offset = offset;
1290 : m_size(obj.size()),
1292 m_pager(obj.numpages()),
1293 m_page_status(
div_ceil(m_bids.size(), page_size)),
1294 m_page_to_slot(
div_ceil(m_bids.size(), page_size)),
1295 m_slot_to_page(obj.numpages()),
1300 assert(!obj.m_exported);
1301 m_bm = block_manager::get_instance();
1303 allocate_page_cache();
1305 for (
size_t i = 0; i < m_page_status.size(); ++i)
1307 m_page_status[i] = uninitialized;
1308 m_page_to_slot[i] = on_disk;
1312 m_free_slots.push(i);
1314 m_bm->new_blocks(m_alloc_strategy, m_bids.begin(), m_bids.end(), 0);
1318 std::copy(inbegin, inend, begin());
1412 return element(offset);
1417 return const_element(offset);
1424 return element(offset);
1430 return const_element(offset);
1450 non_free_slots[i] =
true;
1452 while (!m_free_slots.empty())
1454 non_free_slots[m_free_slots.front()] =
false;
1460 m_free_slots.push(i);
1461 int_type page_no = m_slot_to_page[i];
1462 if (non_free_slots[i])
1466 write_page(page_no, i);
1468 m_page_to_slot[page_no] = on_disk;
1487 STXXL_ERRMSG(
"io_error thrown in ~vector(): " << e.what());
1496 if (m_from == NULL) {
1497 m_bm->delete_blocks(m_bids.begin(), m_bids.end());
1502 ((
void*)m_from) <<
" to " << file_length());
1506 m_from->set_size(file_length());
1510 STXXL_ERRMSG(
"Exception thrown in ~vector()...set_size()");
1528 std::ostringstream number;
1529 number << std::setw(9) << std::setfill(
'0') << no;
1531 ((i + 1) == m_bids.end() && m_size % block_type::size > 0) ?
1532 (m_size % block_type::size) *
sizeof(
value_type) :
1534 (*i).storage->export_files((*i).offset, current_block_size, filename_prefix + number.str());
1553 template <
typename ForwardIterator>
1557 m_bids.resize(new_bids_size);
1558 std::copy(bid_begin, bid_end, m_bids.begin());
1560 m_page_status.resize(new_pages, valid_on_disk);
1561 m_page_to_slot.resize(new_pages, on_disk);
1568 return m_pager.size();
1576 return (m_bids.begin() +
1577 static_cast<typename bids_container_type::size_type
>
1578 (offset / block_type::size));
1582 return (m_bids.begin() +
1583 static_cast<typename bids_container_type::size_type
>
1588 return (m_bids.begin() +
1589 static_cast<typename bids_container_type::size_type
>
1590 (offset / block_type::size));
1594 return (m_bids.begin() +
1595 static_cast<typename bids_container_type::size_type
>
1601 assert(page_no < (
int_type)m_page_status.size());
1602 if (m_page_status[page_no] == uninitialized)
1606 int_type block_no = page_no * page_size;
1608 int_type i = cache_slot * page_size, j = 0;
1609 for ( ; block_no < last_block; ++block_no, ++i, ++j)
1611 reqs[j] = (*m_cache)[i].read(m_bids[block_no]);
1613 assert(last_block - page_no * page_size > 0);
1614 wait_all(reqs, last_block - page_no * page_size);
1619 assert(page_no < (
int_type)m_page_status.size());
1620 if (!(m_page_status[page_no] & dirty))
1624 int_type block_no = page_no * page_size;
1626 assert(block_no < last_block);
1627 int_type i = cache_slot * page_size, j = 0;
1628 for ( ; block_no < last_block; ++block_no, ++i, ++j)
1630 reqs[j] = (*m_cache)[i].write(m_bids[block_no]);
1632 m_page_status[page_no] = valid_on_disk;
1633 assert(last_block - page_no * page_size > 0);
1634 wait_all(reqs, last_block - page_no * page_size);
1640 #ifdef STXXL_RANGE_CHECK
1648 #ifdef STXXL_RANGE_CHECK
1649 assert(offset.
get_pos() < size());
1652 assert(page_no < m_page_to_slot.size());
1653 int_type cache_slot = m_page_to_slot[page_no];
1656 if (m_free_slots.empty())
1658 int_type kicked_slot = m_pager.kick();
1659 m_pager.hit(kicked_slot);
1660 int_type old_page_no = m_slot_to_page[kicked_slot];
1661 m_page_to_slot[page_no] = kicked_slot;
1662 m_page_to_slot[old_page_no] = on_disk;
1663 m_slot_to_page[kicked_slot] = page_no;
1665 write_page(old_page_no, kicked_slot);
1666 read_page(page_no, kicked_slot);
1668 m_page_status[page_no] = dirty;
1674 int_type free_slot = m_free_slots.front();
1676 m_pager.hit(free_slot);
1677 m_page_to_slot[page_no] = free_slot;
1678 m_slot_to_page[free_slot] = page_no;
1680 read_page(page_no, free_slot);
1682 m_page_status[page_no] = dirty;
1689 m_page_status[page_no] = dirty;
1690 m_pager.hit(cache_slot);
1699 assert(page_no < m_page_status.size());
1701 assert(!(m_page_status[page_no] & dirty));
1702 if (m_page_to_slot[page_no] != on_disk) {
1704 m_free_slots.push(m_page_to_slot[page_no]);
1705 m_page_to_slot[page_no] = on_disk;
1706 STXXL_VERBOSE_VECTOR(
"page_externally_updated(): page_no=" << page_no <<
" flushed from cache.");
1709 STXXL_VERBOSE_VECTOR(
"page_externally_updated(): page_no=" << page_no <<
" no need to flush.");
1711 m_page_status[page_no] = valid_on_disk;
1716 page_externally_updated(
1723 page_externally_updated(offset.
get_block2());
1734 assert(page_no < m_page_to_slot.size());
1735 int_type cache_slot = m_page_to_slot[page_no];
1738 if (m_free_slots.empty())
1740 int_type kicked_slot = m_pager.kick();
1741 m_pager.hit(kicked_slot);
1742 int_type old_page_no = m_slot_to_page[kicked_slot];
1743 m_page_to_slot[page_no] = kicked_slot;
1744 m_page_to_slot[old_page_no] = on_disk;
1745 m_slot_to_page[kicked_slot] = page_no;
1747 write_page(old_page_no, kicked_slot);
1748 read_page(page_no, kicked_slot);
1754 int_type free_slot = m_free_slots.front();
1756 m_pager.hit(free_slot);
1757 m_page_to_slot[page_no] = free_slot;
1758 m_slot_to_page[free_slot] = page_no;
1760 read_page(page_no, free_slot);
1767 m_pager.hit(cache_slot);
1775 assert(page_no < m_page_to_slot.size());
1776 int_type cache_slot = m_page_to_slot[page_no];
1777 return (cache_slot >= 0);
1789 AllocStr, SizeType>& a,
1791 AllocStr, SizeType>& b)
1793 return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
1804 AllocStr, SizeType>& a,
1806 AllocStr, SizeType>& b)
1819 AllocStr, SizeType>& a,
1821 AllocStr, SizeType>& b)
1823 return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
1834 AllocStr, SizeType>& a,
1836 AllocStr, SizeType>& b)
1849 AllocStr, SizeType>& a,
1851 AllocStr, SizeType>& b)
1864 AllocStr, SizeType>& a,
1866 AllocStr, SizeType>& b)
1874 template <
typename ValueType,
typename AllocStr,
typename SizeType,
typename DiffType,
1875 unsigned BlockSize,
typename PagerType,
unsigned PageSize>
1885 template <
typename ValueType,
typename AllocStr,
typename SizeType,
typename DiffType,
1886 unsigned BlockSize,
typename PagerType,
unsigned PageSize,
typename StrictWeakOrdering>
1890 StrictWeakOrdering comp)
1900 template <
typename VectorBufReaderType>
1919 template <
typename VectorIterator>
1973 : m_begin(begin), m_end(end),
1975 m_nbuffers(nbuffers)
1979 if (m_nbuffers == 0)
1980 m_nbuffers = 2 * config::get_instance()->disks_number();
1989 : m_begin(vec.begin()), m_end(vec.end()),
1991 m_nbuffers(nbuffers)
1995 if (m_nbuffers == 0)
1996 m_nbuffers = 2 * config::get_instance()->disks_number();
2006 if (empty())
return;
2008 if (m_bufin)
delete m_bufin;
2019 for ( ; curr != m_begin; ++curr)
2026 if (m_bufin)
delete m_bufin;
2038 return &(*(*m_bufin));
2068 assert(m_begin <= m_iter && m_iter <= m_end);
2075 return (m_iter == m_end);
2106 template <
typename VectorBufReaderType>
2107 class vector_bufreader_iterator
2129 : m_bufreader(bufreader), m_iter(iter)
2135 assert(m_bufreader.m_iter == m_iter);
2136 return m_bufreader.operator * ();
2142 assert(m_bufreader.m_iter == m_iter);
2143 return m_bufreader.operator -> ();
2150 assert(m_bufreader.m_iter == m_iter);
2151 m_bufreader.operator ++ ();
2159 assert(&m_bufreader == &vbi.m_bufreader);
2160 return (m_iter == vbi.m_iter);
2166 assert(&m_bufreader == &vbi.m_bufreader);
2167 return (m_iter != vbi.m_iter);
2190 template <
typename VectorIterator>
2191 class vector_bufreader_reverse :
public noncopyable
2238 : m_begin(begin), m_end(end),
2240 m_nbuffers(nbuffers)
2244 if (m_nbuffers == 0)
2245 m_nbuffers = 2 * config::get_instance()->disks_number();
2254 : m_begin(vec.begin()), m_end(vec.end()),
2256 m_nbuffers(nbuffers)
2260 if (m_nbuffers == 0)
2261 m_nbuffers = 2 * config::get_instance()->disks_number();
2271 if (empty())
return;
2273 if (m_bufin)
delete m_bufin;
2289 for ( ; endoff != block_type::size; endoff++)
2297 if (m_bufin)
delete m_bufin;
2309 return &(*(*m_bufin));
2339 assert(m_begin <= m_iter && m_iter <= m_end);
2346 return (m_iter == m_begin);
2367 template <
typename VectorIterator>
2368 class vector_bufwriter :
public noncopyable
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);
2436 : m_iter(vec.begin()),
2437 m_end(m_iter.parent_vector()->end()),
2440 m_nbuffers(nbuffers)
2442 if (m_nbuffers == 0)
2443 m_nbuffers = 2 * config::get_instance()->disks_number();
2445 assert(m_iter <= m_end);
2466 if (m_iter.block_offset() != 0)
2472 if (m_iter.block_offset() != 0)
2473 m_iter.block_externally_updated();
2477 if (v.size() < 2 * block_type::size) {
2478 v.resize(2 * block_type::size);
2481 v.resize(2 * v.size());
2487 assert(m_iter < m_end);
2491 if (m_iter.block_offset() != 0)
2514 if (
UNLIKELY(m_iter.block_offset() == 0)) {
2515 if (m_prevblk != m_iter) {
2516 m_prevblk.block_externally_updated();
2521 return m_bufout->operator * ();
2531 if (
LIKELY(m_bufout != NULL)) m_bufout->operator ++ ();
2554 while (const_out.block_offset() != 0)
2556 m_bufout->operator * () = *const_out;
2557 m_bufout->operator ++ ();
2562 if (m_prevblk != m_iter) {
2563 m_prevblk.block_externally_updated();
2574 v.resize(m_iter - v.begin());
2596 unsigned PageSize = 4,
2597 unsigned CachePages = 8,
2604 typedef typename IF<Pager ==
lru,
2631 #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.
bids_container_type::bid_type bid_type
Const external vector iterator, model of ext_random_access_iterator concept.
vector_iterator()
constructs invalid iterator
size_type size() const
Return remaining size.
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...
compat::remove_const< Integral >::type div_ceil(Integral n, Integral2 d)
#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
bool is_sorted(ForwardIterator first, ForwardIterator last)
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
Buffered sequential reverse reader from a vector using overlapped I/O.
const Type & STXXL_MIN(const Type &a, const Type &b)
~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
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.
vector_type::size_type size_type
size of remaining data
const unsigned_type & get_block1() const
size_type size() const
return the size of the vector.
vector_type::size_type size_type
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
const unsigned_type & get_offset() const
std::random_access_iterator_tag iterator_category
void reserve(size_type n)
Reserves at least n elements in external memory.
size_type get_pos() const
iterator::value_type value_type
value type of the output vector
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.
vector_type::size_type size_type
size of remaining data
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_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
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
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.
double_blocked_index(size_type pos)
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.
double_blocked_index(unsigned_type block2, unsigned_type block1, unsigned_type offset)
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
void wait_all(RequestIterator reqs_begin, RequestIterator reqs_end)
Collection of functions to track statuses of a number of requests.
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
block_offset_type block_offset() const
return block offset of current element
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
size_type size() const
Return remaining size.
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. ...
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
bool is_sorted_helper(ForwardIterator first, ForwardIterator last)
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
const unsigned_type & get_block2() const
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.
void swap(vector &obj)
swap content