22 #include "lfVectorIterator.h"
27 template<
class T,
int32_t nSlots >
31 setZero( slots_, nSlots *
sizeof( T* ));
34 template<
class T,
int32_t nSlots >
39 setZero( slots_, nSlots *
sizeof( T* ));
41 for( int32_t i = 0; i <= s; ++i )
42 slots_[ i ] =
new T[ 1<<i ];
45 template<
class T,
int32_t nSlots >
50 setZero( slots_, nSlots *
sizeof( T* ));
52 for( int32_t i = 0; i <= s; ++i )
54 const size_t sz = 1<<i;
55 slots_[ i ] =
new T[ sz ];
56 for(
size_t j = 0; size_ < n && j < sz ; ++j )
62 LBASSERTINFO( size_ == n, size_ <<
" != " << n );
65 template<
class T,
int32_t nSlots >
73 template<
class T,
int32_t nSlots >
74 template<
int32_t fromSlots >
82 template<
class T,
int32_t nSlots >
85 for(
size_t i=0; i < nSlots; ++i )
98 for( int32_t i = 0; i < nSlots; ++i )
102 const size_t sz = 1<<i;
104 slots_[ i ] =
new T[ sz ];
106 for(
size_t j = 0; size_ < from.size_ && j < sz ; ++j )
108 slots_[ i ][ j ] = from.slots_[ i ][ j ];
112 else if( slots_[ i ] )
114 delete [] slots_[ i ];
119 LBASSERTINFO( size_ == from.size_, size_ <<
" != " << from.size_ );
123 template<
class T,
int32_t nSlots >
129 if( size() != rhs.
size() )
134 for( ; it != end() && rhsIt != end(); ++it, ++rhsIt )
144 #ifdef LB_GCC_4_6_OR_LATER
145 # pragma GCC diagnostic push
146 # pragma GCC diagnostic ignored "-Warray-bounds"
149 template<
class T,
int32_t nSlots >
153 LBASSERTINFO( size_ >= i, size_ <<
" < " << i );
156 const size_t index = i ^ ( size_t( 1 )<<slot );
158 LBASSERTINFO( slot >=0 && slot < nSlots, slot );
159 LBASSERT( slots_[ slot ] );
160 LBASSERT( index < (1ull<<slot) );
161 return slots_[ slot ][ index ];
164 template<
class T,
int32_t nSlots >
167 LBASSERTINFO( size_ > i, size_ <<
" <= " << i );
170 const size_t index = i ^ ( size_t( 1 )<<slot );
172 LBASSERTINFO( slot >=0 && slot < nSlots, slot );
173 LBASSERT( slots_[ slot ] );
174 LBASSERT( index < (1ull<<slot) );
175 return slots_[ slot ][ index ];
178 #ifdef LB_GCC_4_6_OR_LATER
179 # pragma GCC diagnostic pop
182 template<
class T,
int32_t nSlots >
185 LBASSERT( !empty( ));
186 return slots_[ 0 ][ 0 ];
189 template<
class T,
int32_t nSlots >
192 LBASSERT( !empty( ));
193 return (*
this)[ size_ - 1 ];
196 template<
class T,
int32_t nSlots >
200 while( newSize > size( ))
201 push_back_unlocked_( item );
204 template<
class T,
int32_t nSlots >
208 push_back_unlocked_( item );
211 template<
class T,
int32_t nSlots >
218 (*this)[size_] = T();
222 template<
class T,
int32_t nSlots >
231 (*this)[size_] = T();
239 LBASSERT( pos.container_ ==
this );
240 if( pos.container_ !=
this || pos.i_ >= size_ )
245 #pragma warning (push)
246 #pragma warning (disable: 4996) // unchecked iterators
247 std::copy( pos+1, end()+1, pos );
248 #pragma warning (pop)
249 (*this)[size_] = T();
258 for(
size_t i = size_; i != 0 ; --i )
260 if( (*
this)[i-1] == element )
264 #pragma warning (push)
265 #pragma warning (disable: 4996) // unchecked iterators
266 std::copy( pos+1, end()+1, pos );
267 #pragma warning (pop)
276 template<
class T,
int32_t nSlots >
280 while( size_ > newSize )
283 (*this)[size_] = T();
287 while( size_ < newSize )
288 push_back_unlocked_( value );
291 template<
class T,
int32_t nSlots >
298 (*this)[size_] = T();
300 for( int32_t i = 0; i < nSlots; ++i )
302 delete [] slots_[ i ];
313 template<
class T,
int32_t nSlots >
314 template<
int32_t fromSlots >
317 setZero( slots_, nSlots *
sizeof( T* ));
320 for( int32_t i = 0; i < nSlots; ++i )
322 if( i >= fromSlots || !from.slots_[i] )
324 LBASSERTINFO( size_ == from.size_,
325 size_ <<
" != " << from.size_ );
329 const size_t sz = 1<<i;
330 slots_[ i ] =
new T[ sz ];
331 for(
size_t j = 0; size_ < from.size_ && j < sz ; ++j )
333 slots_[ i ][ j ] = from.slots_[ i ][ j ];
339 template<
class T,
int32_t nSlots >
340 void LFVector< T, nSlots >::push_back_unlocked_(
const T& item )
342 const size_t i = size_ + 1;
344 const size_t sz = ( size_t( 1 )<<slot );
345 if( !slots_[ slot ] )
346 slots_[ slot ] =
new T[ sz ];
348 const ssize_t index = i ^ sz;
349 slots_[ slot ][ index ] = item;
353 template<
class T,
int32_t nSlots >
354 void LFVector< T, nSlots >::trim_()
357 if( nextSlot < nSlots && slots_[ nextSlot ] )
359 delete [] slots_[ nextSlot ];
360 slots_[ nextSlot ] = 0;
364 template<
class T,
int32_t nSlots >
inline typename
370 template<
class T,
int32_t nSlots >
inline typename
376 template<
class T,
int32_t nSlots >
inline typename
382 template<
class T,
int32_t nSlots >
inline typename
389 template<
class T,
int32_t nSlots >
template<
class Archive >
391 const unsigned int version )
const
394 for(
size_t i = 0; i < size_; ++i )
398 template<
class T,
int32_t nSlots >
template<
class Archive >
399 inline void LFVector< T, nSlots >::load( Archive& ar,
400 const unsigned int version )
405 LBASSERT( size_ == newSize );
407 for(
size_t i = 0; i < size_; ++i )
413 std::ostream& operator << ( std::ostream& os, const LFVector< T >& v )
415 os <<
className( &v ) <<
" size " << v.size() <<
" [ ";
418 if( i.getPosition() > 255 )
425 return os <<
']' << std::endl;