pull/21/head
Darrell Anderson 12 years ago
parent 6b96e6cfbb
commit d53e057f92

@ -50,11 +50,11 @@ namespace byte_io {
T read( const unsigned char* );
template<typename T>
struct byte_lenght_struct { };
struct byte_length_struct { };
template<typename T>
struct byte_lenght_struct<const T> {
static const int value = byte_lenght_struct<T>::value;
struct byte_length_struct<const T> {
static const int value = byte_length_struct<T>::value;
};
@ -63,8 +63,8 @@ namespace byte_io {
* for supported types.
*/
template<typename T>
unsigned byte_lenght() {
return byte_lenght_struct<T>::value;
unsigned byte_length() {
return byte_length_struct<T>::value;
}
}

@ -39,7 +39,7 @@ namespace byte_io {
}
template<>
struct byte_lenght_struct<uint8_t> {
struct byte_length_struct<uint8_t> {
static const int value = 1;
};
@ -60,7 +60,7 @@ namespace byte_io {
}
template<>
struct byte_lenght_struct<uint16_t> {
struct byte_length_struct<uint16_t> {
static const int value = 2;
};
@ -84,7 +84,7 @@ namespace byte_io {
return res;
}
template<>
struct byte_lenght_struct<uint32_t> {
struct byte_length_struct<uint32_t> {
static const int value = 4;
};
}

@ -50,7 +50,7 @@ uint32_t leaf_data::get_reference( unsigned idx ) const {
}
bool leaf_data::can_add( uint32_t ref ) const {
if ( ( capacity() - usedbytes() ) > ( 1 + byte_io::byte_lenght<uint32_t>() ) ) return true;
if ( ( capacity() - usedbytes() ) > ( 1 + byte_io::byte_length<uint32_t>() ) ) return true;
if ( capacity() == usedbytes() ) return false;
uint32_t last = 0;
for ( iterator first = begin(), past = end(); first != past; ++first ) {
@ -97,7 +97,7 @@ void leaf_data::add_reference( uint32_t ref ) {
} else {
*target++ = 0;
byte_io::write<uint32_t>( target, ref );
set_usedbytes( usedbytes() + 1 + byte_io::byte_lenght<uint32_t>() );
set_usedbytes( usedbytes() + 1 + byte_io::byte_length<uint32_t>() );
}
assert( usedbytes() <= capacity() );
}
@ -123,7 +123,7 @@ void leaf_data::remove_reference( uint32_t ref ) {
else {
++iter;
byte_io::write<uint32_t>(iter,byte_io::read<uint32_t>(iter)-1);
iter += byte_io::byte_lenght<uint32_t>();
iter += byte_io::byte_length<uint32_t>();
}
}
}

@ -60,7 +60,7 @@ struct leafdata_iterator : public std::iterator<STD_NAMESPACE_PREFIX input_itera
value_ += delta;
} else {
value_ = byte_io::read<uint32_t>( data_ );
data_ += byte_io::byte_lenght<uint32_t>();
data_ += byte_io::byte_length<uint32_t>();
}
return value_ - 1;
}

@ -135,7 +135,7 @@ void mempool<Traits>::print( std::ostream& out ) const {
template <typename Traits>
memory_reference<uint32_t> mempool<Traits>::free_list( unsigned order ) {
assert( order );
return memory_reference<uint32_t>( manager_->rw_base( order * byte_io::byte_lenght<uint32_t>() ) );
return memory_reference<uint32_t>( manager_->rw_base( order * byte_io::byte_length<uint32_t>() ) );
}
template <typename Traits>

@ -72,23 +72,23 @@ struct memory_iterator : public std::iterator<STD_NAMESPACE_PREFIX random_access
}
memory_iterator& operator ++() {
data_ += byte_io::byte_lenght<T>();
data_ += byte_io::byte_length<T>();
return *this;
}
memory_iterator& operator --() {
data_ -= byte_io::byte_lenght<T>();
data_ -= byte_io::byte_length<T>();
return *this;
}
memory_iterator& operator += ( ptrdiff_t dif ) {
data_ += dif * byte_io::byte_lenght<T>();
data_ += dif * byte_io::byte_length<T>();
return *this;
}
ptrdiff_t operator - ( const memory_iterator<T>& other ) const {
assert( !( ( raw() - other.raw() )%byte_io::byte_lenght<T>() ) );
return ( raw() - other.raw() )/byte_io::byte_lenght<T>();
assert( !( ( raw() - other.raw() )%byte_io::byte_length<T>() ) );
return ( raw() - other.raw() )/byte_io::byte_length<T>();
}
bool operator < ( const memory_iterator<T>& other ) const {
@ -211,8 +211,8 @@ struct memvector {
boost::scoped_ptr<memory_manager> data_;
unsigned char* address_of( unsigned i ) {
return data_->rw_base(
byte_io::byte_lenght<unsigned>() +
i * byte_io::byte_lenght<T>() );
byte_io::byte_length<unsigned>() +
i * byte_io::byte_length<T>() );
}
const unsigned char* address_of( unsigned i ) const {
return const_cast<memvector*>( this )->address_of( i );

@ -9,7 +9,7 @@ memvector<T>::memvector( std::string fname ):
data_( new mmap_manager( fname ) )
{
if ( !data_->size() ) {
data_->resize( byte_io::byte_lenght<unsigned>() );
data_->resize( byte_io::byte_length<unsigned>() );
byte_io::write<unsigned>( data_->rw_base( 0 ), 0 );
}
}
@ -31,7 +31,7 @@ void memvector<T>::resize( size_type n_s ) {
if ( size() >= n_s ) return;
using namespace byte_io;
data_->resize( n_s * byte_lenght<value_type>() + byte_lenght<unsigned>() );
data_->resize( n_s * byte_length<value_type>() + byte_length<unsigned>() );
iterator p_end = end();
write<unsigned>( data_->rw_base( 0 ), n_s );
while ( p_end != end() ) {
@ -45,10 +45,10 @@ void memvector<T>::insert( const_iterator where, const value_type v ) {
assert( !( where < begin() ) );
assert( where <= end() );
const unsigned to_idx = where.raw() - data_->ronly_base( 0 );
data_->resize( ( size() + 1 ) * byte_io::byte_lenght<value_type>() + byte_io::byte_lenght<unsigned>() );
data_->resize( ( size() + 1 ) * byte_io::byte_length<value_type>() + byte_io::byte_length<unsigned>() );
unsigned char* to = data_->rw_base( to_idx );
// make space:
std::memmove( to + byte_io::byte_lenght<value_type>(), to, end().raw() - to );
std::memmove( to + byte_io::byte_length<value_type>(), to, end().raw() - to );
byte_io::write<value_type>( to, v );
byte_io::write<unsigned>( data_->rw_base( 0 ), size() + 1 );
}
@ -68,7 +68,7 @@ void memvector<T>::erase( iterator where ) {
template <typename T>
void memvector<T>::clear() {
data_->resize( byte_io::byte_lenght<uint32_t>() );
data_->resize( byte_io::byte_length<uint32_t>() );
byte_io::write<uint32_t>( data_->rw_base( 0 ), 0 );
}

@ -157,8 +157,8 @@ struct simple_accessor {
write<uint32_t>( out, p.cast_to_uint32() ); \
} \
template<> \
struct byte_lenght_struct< pointer <name> > { \
static const unsigned value = byte_lenght_struct<uint32_t>::value; \
struct byte_length_struct< pointer <name> > { \
static const unsigned value = byte_length_struct<uint32_t>::value; \
}; \
} // namespace

Loading…
Cancel
Save