// Const access and load on demand inline const ItemType& operator()( const int i ) { assert( i < static_cast<int>( forward_ptr.size() ) ); if ( -1 == forward_ptr[i] ) { assert( LAZY_BUFFER_INPUT == type ); if ( -1 != limit && static_cast<int>( backward_ptr.size() ) >= limit ) { int pos = fl.discard(); int unload = forward_ptr[pos]; forward_ptr[pos] = -1; assert( -1 != unload ); fseek( fdata, offsets[i], SEEK_SET ); items[unload] = std::move( ItemType( fdata ) ); forward_ptr[i] = unload; backward_ptr[unload] = i; } else { fseek( fdata, offsets[i], SEEK_SET ); items.push_back( std::move( ItemType( fdata ) ) ); forward_ptr[i] = static_cast<int>( items.size() - 1 ); backward_ptr.push_back( i ); assert( backward_ptr.size() == items.size() ); } fl.promote( i ); } else { assert( ( 0 <= forward_ptr[i] ) && ( forward_ptr[i] < static_cast<int>( items.size() ) ) ); } return items[forward_ptr[i]]; }
inline void evacuate() { assert( LAZY_BUFFER_INPUT == type ); for ( auto& ele : backward_ptr ) { forward_ptr[ele] = -1; fl.discard(); } backward_ptr.clear(); items.clear(); }