1 package DBM::Deep::Engine::Sector::Index;
3 use base qw( DBM::Deep::Engine::Sector );
7 # Please refer to the pack() documentation for further information
9 1 => 'C', # Unsigned char value (no order needed as it's just one byte)
10 2 => 'n', # Unsigned short in "network" (big-endian) order
11 4 => 'N', # Unsigned long in "network" (big-endian) order
12 8 => 'Q', # Usigned quad (no order specified, presumably machine-dependent)
18 my $engine = $self->engine;
20 unless ( $self->offset ) {
21 my $leftover = $self->size - $self->base_size;
23 $self->{offset} = $engine->_request_index_sector( $self->size );
24 $engine->storage->print_at( $self->offset, $engine->SIG_INDEX ); # Sector type
25 # Skip staleness counter
26 $engine->storage->print_at( $self->offset + $self->base_size,
27 chr(0) x $leftover, # Zero-fill the rest
37 unless ( $self->{size} ) {
38 my $e = $self->engine;
39 $self->{size} = $self->base_size + $e->byte_size * $e->hash_chars;
44 sub free_meth { return '_add_free_index_sector' }
48 my $e = $self->engine;
50 for my $i ( 0 .. $e->hash_chars - 1 ) {
51 my $l = $self->get_entry( $i ) or next;
52 $e->_load_sector( $l )->free;
61 return $self->offset + $self->base_size + $idx * $self->engine->byte_size;
68 my $e = $self->engine;
70 DBM::Deep->_throw_error( "get_entry: Out of range ($idx)" )
71 if $idx < 0 || $idx >= $e->hash_chars;
75 $e->storage->read_at( $self->_loc_for( $idx ), $e->byte_size ),
83 my $e = $self->engine;
85 DBM::Deep->_throw_error( "set_entry: Out of range ($idx)" )
86 if $idx < 0 || $idx >= $e->hash_chars;
88 $self->engine->storage->print_at(
89 $self->_loc_for( $idx ),
90 pack( $StP{$e->byte_size}, $loc ),