sub offset { $_[0]{offset} }
sub type { $_[0]{type} }
+sub base_size { 1 + 1 } # Size of sig + staleness counter
+
sub free {
my $self = shift;
- $self->engine->storage->print_at( $self->offset, $self->engine->SIG_FREE );
+ my $e = $self->engine;
+
+ $e->storage->print_at( $self->offset, $e->SIG_FREE );
# Skip staleness counter
- $self->engine->storage->print_at( $self->offset + 1 + 1,
- chr(0) x ($self->size - 2),
+ $e->storage->print_at( $self->offset + $self->base_size,
+ chr(0) x ($self->size - $self->base_size),
);
- $self->engine->_add_free_sector(
+ $e->_add_free_sector(
$self->offset, $self->size,
);
my $engine = $self->engine;
unless ( $self->offset ) {
- my $data_section = $self->size - 3 - 1 * $engine->byte_size;
+ my $data_section = $self->size - $self->base_size - 1 * $engine->byte_size - 1;
$self->{offset} = $engine->_request_sector( $self->size );
my $self = shift;
my $buffer = $self->engine->storage->read_at(
- $self->offset + 2 + $self->engine->byte_size, 1
+ $self->offset + $self->base_size + $self->engine->byte_size, 1
);
return unpack( $StP{1}, $buffer );
sub chain_loc {
my $self = shift;
my $chain_loc = $self->engine->storage->read_at(
- $self->offset + 2, $self->engine->byte_size,
+ $self->offset + $self->base_size, $self->engine->byte_size,
);
return unpack( $StP{$self->engine->byte_size}, $chain_loc );
}
my $chain_loc = $self->chain_loc;
$data .= $self->engine->storage->read_at(
- $self->offset + 2 + $self->engine->byte_size + 1, $self->data_length,
+ $self->offset + $self->base_size + $self->engine->byte_size + 1, $self->data_length,
);
last unless $chain_loc;
my $engine = $self->engine;
unless ( $self->offset ) {
- my $leftover = $self->size - 3 - 1 * $engine->byte_size;
+ my $leftover = $self->size - $self->base_size - 1 * $engine->byte_size - 1;
$self->{offset} = $engine->_request_sector( $self->size );
$engine->storage->print_at( $self->offset, $self->type ); # Sector type
# Skip staleness counter
- $engine->storage->print_at( $self->offset + 1 + 1,
+ $engine->storage->print_at( $self->offset + $self->base_size,
pack( $StP{$engine->byte_size}, 0 ), # Chain loc
pack( $StP{1}, $self->data_length ), # Data length
chr(0) x $leftover, # Zero-fill the rest
unless ( $self->offset ) {
my $classname = Scalar::Util::blessed( delete $self->{data} );
- my $leftover = $self->size - 2 - 2 * $engine->byte_size;
+ my $leftover = $self->size - $self->base_size - 2 * $engine->byte_size;
my $class_offset = 0;
if ( defined $classname ) {
$self->{offset} = $engine->_request_sector( $self->size );
$engine->storage->print_at( $self->offset, $self->type ); # Sector type
# Skip staleness counter
- $engine->storage->print_at( $self->offset + 1 + 1,
+ $engine->storage->print_at( $self->offset + $self->base_size,
pack( $StP{$engine->byte_size}, 0 ), # Index/BList loc
pack( $StP{$engine->byte_size}, $class_offset ), # Classname loc
chr(0) x $leftover, # Zero-fill the rest
my $self = shift;
my $e = $self->engine;
- my $blist_loc = $e->storage->read_at( $self->offset + 2, $e->byte_size );
+ my $blist_loc = $e->storage->read_at( $self->offset + $self->base_size, $e->byte_size );
return unpack( $StP{$e->byte_size}, $blist_loc );
}
key_md5 => $args->{key_md5},
});
- $engine->storage->print_at( $self->offset + 2,
+ $engine->storage->print_at( $self->offset + $self->base_size,
pack( $StP{$engine->byte_size}, $blist->offset ),
);
my $self = shift;
my $class_offset = $self->engine->storage->read_at(
- $self->offset + 2 + 1 * $self->engine->byte_size, $self->engine->byte_size,
+ $self->offset + $self->base_size + 1 * $self->engine->byte_size, $self->engine->byte_size,
);
$class_offset = unpack ( $StP{$self->engine->byte_size}, $class_offset );
$self->{offset} = $engine->_request_sector( $self->size );
$engine->storage->print_at( $self->offset, $engine->SIG_BLIST ); # Sector type
# Skip staleness counter
- $engine->storage->print_at( $self->offset + 1 + 1,
+ $engine->storage->print_at( $self->offset + $self->base_size,
chr(0) x $leftover, # Zero-fill the data
);
}
return $self;
}
-sub base_size { 1 + 1 } # Sig + recycled counter
-
sub size {
my $self = shift;
unless ( $self->{size} ) {
$self->{offset} = $engine->_request_sector( $self->size );
$engine->storage->print_at( $self->offset, $engine->SIG_BLIST ); # Sector type
# Skip staleness counter
- $engine->storage->print_at( $self->offset + 1 + 1,
+ $engine->storage->print_at( $self->offset + $self->base_size,
chr(0) x $leftover, # Zero-fill the data
);
}
return $self;
}
-sub base_size { 1 + 1 } # Sig + recycled counter
-
sub size {
my $self = shift;
unless ( $self->{size} ) {
return $self->{size};
}
-sub bucket_size {
- my $self = shift;
- unless ( $self->{bucket_size} ) {
- my $e = $self->engine;
- # Key + head (location) + transactions (location + staleness-counter)
- my $location_size = $e->byte_size + $e->num_txns * ( $e->byte_size + 4 );
- $self->{bucket_size} = $e->hash_size + $location_size;
- }
- return $self->{bucket_size};
-}
-
1;
__END__