my $self = bless {
type => TYPE_HASH,
base_offset => length(SIG_FILE),
- engine => 'DBM::Deep::Engine',
+ engine => DBM::Deep::Engine->new,
}, $class;
foreach my $param ( keys %$self ) {
? $self->_root->{filter_store_value}->($_[2])
: $_[2];
- my $md5 = $DBM::Deep::Engine::DIGEST_FUNC->($key);
+ my $md5 = $self->{engine}{digest}->($key);
unless ( _is_writable( $self->_fh ) ) {
$self->_throw_error( 'Cannot write to a readonly filehandle' );
my $self = shift->_get_self;
my $key = shift;
- my $md5 = $DBM::Deep::Engine::DIGEST_FUNC->($key);
+ my $md5 = $self->{engine}{digest}->($key);
##
# Request shared lock for reading
my $self = $_[0]->_get_self;
my $key = $_[1];
- my $md5 = $DBM::Deep::Engine::DIGEST_FUNC->($key);
+ my $md5 = $self->{engine}{digest}->($key);
##
# Request exclusive lock for writing
my $self = $_[0]->_get_self;
my $key = $_[1];
- my $md5 = $DBM::Deep::Engine::DIGEST_FUNC->($key);
+ my $md5 = $self->{engine}{digest}->($key);
##
# Request shared lock for reading
}
}
- $key = pack($DBM::Deep::Engine::LONG_PACK, $key);
+ $key = pack($self->{engine}{long_pack}, $key);
}
my $rv = $self->SUPER::FETCH( $key );
}
}
- $key = pack($DBM::Deep::Engine::LONG_PACK, $key);
+ $key = pack($self->{engine}{long_pack}, $key);
}
my $rv = $self->SUPER::STORE( $key, $value );
}
}
- $key = pack($DBM::Deep::Engine::LONG_PACK, $key);
+ $key = pack($self->{engine}{long_pack}, $key);
}
my $rv = $self->SUPER::EXISTS( $key );
}
}
- $key = pack($DBM::Deep::Engine::LONG_PACK, $key);
+ $key = pack($self->{engine}{long_pack}, $key);
}
my $rv = $self->SUPER::DELETE( $key );
$self->unlock;
if ($packed_size) {
- return int(unpack($DBM::Deep::Engine::LONG_PACK, $packed_size));
+ return int(unpack($self->{engine}{long_pack}, $packed_size));
}
return 0;
my $SAVE_FILTER = $self->_root->{filter_store_value};
$self->_root->{filter_store_value} = undef;
- my $result = $self->STORE('length', pack($DBM::Deep::Engine::LONG_PACK, $new_length));
+ my $result = $self->STORE('length', pack($self->{engine}{long_pack}, $new_length));
$self->_root->{filter_store_value} = $SAVE_FILTER;
# DO NOT decrease this value below 16, due to risk of recursive reindex overrun.
##
our $MAX_BUCKETS = 16;
-our ($DIGEST_FUNC, $HASH_SIZE);
+our ($HASH_SIZE);
our ($INDEX_SIZE, $BUCKET_SIZE, $BUCKET_LIST_SIZE);
set_digest();
-sub _precalc_sizes {
+sub precalc_sizes {
##
# Precalculate index, bucket and bucket list sizes
##
$DATA_LENGTH_SIZE = $data_s ? $data_s : 4;
$DATA_LENGTH_PACK = $data_p ? $data_p : 'N';
- _precalc_sizes();
+ precalc_sizes();
}
sub set_digest {
+ my $self = shift;
##
# Set key digest function (default is MD5)
##
my ($digest_func, $hash_size) = @_;
- $DIGEST_FUNC = $digest_func ? $digest_func : \&Digest::MD5::md5;
+ $self->{digest} = $digest_func ? $digest_func : \&Digest::MD5::md5;
+
$HASH_SIZE = $hash_size ? $hash_size : 16;
- _precalc_sizes();
+ precalc_sizes();
+}
+
+sub new {
+ my $class = shift;
+ my ($args) = @_;
+
+ my $self = bless {
+ long_size => 4,
+ long_pack => 'N',
+ data_size => 4,
+ data_pack => 'N',
+ digest => \&Digest::MD5::md5,
+ hash_size => 16,
+ max_buckets => 16,
+ }, $class;
+
+ #XXX Where does 256 come from?
+ $self->{index_size} = 256 * $self->{long_size};
+ $self->{bucket_size} = $self->{hash_size} + $self->{long_size};
+ $self->{bucket_list_size} = $self->{max_buckets} * $self->{bucket_size};
+
+ return $self;
}
sub setup_fh {
? $self->_root->{filter_store_key}->($_[1])
: $_[1];
- my $prev_md5 = $DBM::Deep::Engine::DIGEST_FUNC->($prev_key);
+ my $prev_md5 = $self->{engine}{digest}->($prev_key);
##
# Request shared lock for reading
# DBM::Deep Test
##
use strict;
-use Test;
-BEGIN { plan tests => 13 }
+use Test::More tests => 13;
use DBM::Deep;
##
# Set digest handler
##
-DBM::Deep::Engine::set_digest( \&my_digest, 8 );
+$db->_get_self->{engine}->set_digest( \&my_digest, 8 );
##
# put/get key