1 #TODO: Convert this to a string
2 package DBM::Deep::Engine::Sector::Index;
7 use warnings FATAL => 'all';
9 use DBM::Deep::Engine::Sector;
10 our @ISA = qw( DBM::Deep::Engine::Sector );
15 my $engine = $self->engine;
17 unless ( $self->offset ) {
18 my $leftover = $self->size - $self->base_size;
20 $self->{offset} = $engine->_request_index_sector( $self->size );
21 $engine->storage->print_at( $self->offset, $engine->SIG_INDEX ); # Sector type
22 # Skip staleness counter
23 $engine->storage->print_at( $self->offset + $self->base_size,
24 chr(0) x $leftover, # Zero-fill the rest
34 unless ( $self->{size} ) {
35 my $e = $self->engine;
36 $self->{size} = $self->base_size + $e->byte_size * $e->hash_chars;
41 sub free_meth { return '_add_free_index_sector' }
45 my $e = $self->engine;
47 for my $i ( 0 .. $e->hash_chars - 1 ) {
48 my $l = $self->get_entry( $i ) or next;
49 $e->_load_sector( $l )->free;
58 return $self->offset + $self->base_size + $idx * $self->engine->byte_size;
65 my $e = $self->engine;
67 DBM::Deep->_throw_error( "get_entry: Out of range ($idx)" )
68 if $idx < 0 || $idx >= $e->hash_chars;
71 $e->StP($e->byte_size),
72 $e->storage->read_at( $self->_loc_for( $idx ), $e->byte_size ),
80 my $e = $self->engine;
82 DBM::Deep->_throw_error( "set_entry: Out of range ($idx)" )
83 if $idx < 0 || $idx >= $e->hash_chars;
85 $self->engine->storage->print_at(
86 $self->_loc_for( $idx ),
87 pack( $e->StP($e->byte_size), $loc ),