| 1 | package DBM::Deep::Sector::File::Index; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 47 | ▶ | use base qw( DBM::Deep::Sector::File ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 47 | my $STALE_SIZE = 2; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Please refer to the pack() documentation for further information | ||||||||||||||||||||||||||||
| 8 | 47 | my %StP = ( | |||||||||||||||||||||||||||
| 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) | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub _init { | ||||||||||||||||||||||||||||
| 16 | 4101 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4101 | my $engine = $self->engine; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 4101 | ▶ | unless ( $self->offset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 11 | my $leftover = $self->size - $self->base_size; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | $self->{offset} = $engine->_request_index_sector( $self->size ); | |||||||||||||||||||||||||||
| 24 | 11 | $engine->storage->print_at( $self->offset, $engine->SIG_INDEX ); # Sector type | |||||||||||||||||||||||||||
| 25 | # Skip staleness counter | ||||||||||||||||||||||||||||
| 26 | 11 | $engine->storage->print_at( $self->offset + $self->base_size, | |||||||||||||||||||||||||||
| 27 | chr(0) x $leftover, # Zero-fill the rest | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 4101 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | #XXX Change here | ||||||||||||||||||||||||||||
| 35 | sub size { | ||||||||||||||||||||||||||||
| 36 | 24 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 24 | ▶ | unless ( $self->{size} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 13 | my $e = $self->engine; | |||||||||||||||||||||||||||
| 39 | 13 | $self->{size} = $self->base_size + $e->byte_size * $e->hash_chars; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 24 | return $self->{size}; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub free_meth { return '_add_free_index_sector' } | ||||||||||||||||||||||||||
|
Subroutine
free_meth: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub free { | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
free: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 0 | my $e = $self->engine; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | for my $i ( 0 .. $e->hash_chars - 1 ) { | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $l = $self->get_entry( $i ) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | $e->load_sector( $l )->free; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | $self->SUPER::free(); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub _loc_for { | ||||||||||||||||||||||||||||
| 59 | 8610 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_loc_for: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 8610 | my ($idx) = @_; | |||||||||||||||||||||||||||
| 61 | 8610 | return $self->offset + $self->base_size + $idx * $self->engine->byte_size; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub get_entry { | ||||||||||||||||||||||||||||
| 65 | 8168 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_entry: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 8168 | my ($idx) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 8168 | my $e = $self->engine; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 8168 | ▶ | DBM::Deep->_throw_error( "get_entry: Out of range ($idx)" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$idx < 0 or $idx >= $e->hash_chars
MC/DC0%0/2
$idx < 0 or $idx >= $e->hash_chars
$idx < 0
$idx >= $e->hash_chars
Truth table33%1/3
A or B
A= $idx < 0B= $idx >= $e->hash_chars
| |||||||||||||||||||||||||||||
| 71 | if $idx < 0 || $idx >= $e->hash_chars; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | return unpack( | ||||||||||||||||||||||||||||
| 74 | 8168 | $StP{$e->byte_size}, | |||||||||||||||||||||||||||
| 75 | $e->storage->read_at( $self->_loc_for( $idx ), $e->byte_size ), | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub set_entry { | ||||||||||||||||||||||||||||
| 80 | 442 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
set_entry: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 442 | my ($idx, $loc) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 442 | my $e = $self->engine; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 442 | ▶ | DBM::Deep->_throw_error( "set_entry: Out of range ($idx)" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$idx < 0 or $idx >= $e->hash_chars
MC/DC0%0/2
$idx < 0 or $idx >= $e->hash_chars
$idx < 0
$idx >= $e->hash_chars
Truth table33%1/3
A or B
A= $idx < 0B= $idx >= $e->hash_chars
| |||||||||||||||||||||||||||||
| 86 | if $idx < 0 || $idx >= $e->hash_chars; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | $self->engine->storage->print_at( | ||||||||||||||||||||||||||||
| 89 | $self->_loc_for( $idx ), | ||||||||||||||||||||||||||||
| 90 | 442 | pack( $StP{$e->byte_size}, $loc ), | |||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 47 | 1; | |||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||