my ($key, $orig_key) = @_;
$orig_key = $key unless defined $orig_key;
- my $md5 = $self->_engine->apply_digest($key);
-
##
# Request shared lock for reading
##
##
$self->lock( LOCK_EX );
- my $md5 = $self->_engine->apply_digest($key);
-
- my $tag = $self->_engine->find_blist( $self->_base_offset, $md5 );
- if (!$tag) {
- $self->unlock();
- return;
- }
-
##
# Delete bucket
##
- my $value = $self->_engine->get_bucket_value( $tag, $md5 );
+ my $value = $self->_engine->delete_key( $self->_base_offset, $key, $orig_key );
if (defined $value && !ref($value) && $self->_fileobj->{filter_fetch_value}) {
$value = $self->_fileobj->{filter_fetch_value}->($value);
}
- my $result = $self->_engine->delete_bucket( $tag, $md5, $orig_key );
-
- ##
- # If this object is an array and the key deleted was on the end of the stack,
- # decrement the length variable.
- ##
-
$self->unlock();
return $value;
my $self = shift->_get_self;
my ($key) = @_;
- my $md5 = $self->_engine->apply_digest($key);
-
##
# Request shared lock for reading
##
$self->lock( LOCK_SH );
- my $tag = $self->_engine->find_blist( $self->_base_offset, $md5 );
- if (!$tag) {
- $self->unlock();
-
- ##
- # For some reason, the built-in exists() function returns '' for false
- ##
- return '';
- }
-
- ##
- # Check if bucket exists and return 1 or ''
- ##
- my $result = $self->_engine->bucket_exists( $tag, $md5 ) || '';
+ my $result = $self->_engine->key_exists( $self->_base_offset, $key );
$self->unlock();
if ( $self->_type eq TYPE_HASH ) {
my $key = $self->first_key;
while ( $key ) {
+ # Retrieve the key before deleting because we depend on next_key
my $next_key = $self->next_key( $key );
- my $md5 = $self->_engine->apply_digest($key);
- my $tag = $self->_engine->find_blist( $self->_base_offset, $md5 );
- $self->_engine->delete_bucket( $tag, $md5, $key );
+ $self->_engine->delete_key( $self->_base_offset, $key, $key );
$key = $next_key;
}
}
else {
my $size = $self->FETCHSIZE;
for my $key ( 0 .. $size - 1 ) {
- my $md5 = $self->_engine->apply_digest($key);
- my $tag = $self->_engine->find_blist( $self->_base_offset, $md5 );
- $self->_engine->delete_bucket( $tag, $md5, $key );
+ $self->_engine->delete_key( $self->_base_offset, $key, $key );
}
$self->STORESIZE( 0 );
}
return $self->bucket_exists( $tag, $dig_key, $key );
}
-sub XXXget_next_key {
+sub get_next_key {
my $self = shift;
- my ($offset, $prev_key) = @_;
+ my ($offset) = @_;
-# my $dig_key = $self->apply_digest( $key );
+ # If the previous key was not specifed, start at the top and
+ # return the first one found.
+ my $temp;
+ if ( @_ > 1 ) {
+ $temp = {
+ prev_md5 => $self->apply_digest($_[1]),
+ return_next => 0,
+ };
+ }
+ else {
+ $temp = {
+ prev_md5 => chr(0) x $self->{hash_size},
+ return_next => 1,
+ };
+ }
+
+ return $self->traverse_index( $temp, $offset, 0 );
}
################################################################################
return;
}
-sub get_next_key {
- ##
- # Locate next key, given digested previous one
- ##
- my $self = shift;
- my ($obj) = @_;
-
- ##
- # If the previous key was not specifed, start at the top and
- # return the first one found.
- ##
- my $temp;
- if ( @_ > 1 ) {
- $temp = {
- prev_md5 => $_[1],
- return_next => 0,
- };
- }
- else {
- $temp = {
- prev_md5 => chr(0) x $self->{hash_size},
- return_next => 1,
- };
- }
-
- return $self->traverse_index( $temp, $obj->_base_offset, 0 );
-}
-
# Utilities
sub _get_key_subloc {
##
$self->lock( $self->LOCK_SH );
- my $result = $self->_engine->get_next_key($self);
+ my $result = $self->_engine->get_next_key($self->_base_offset);
$self->unlock();
? $self->_fileobj->{filter_store_key}->($_[0])
: $_[0];
- my $prev_md5 = $self->_engine->apply_digest($prev_key);
-
##
# Request shared lock for reading
##
$self->lock( $self->LOCK_SH );
- my $result = $self->_engine->get_next_key( $self, $prev_md5 );
+ my $result = $self->_engine->get_next_key( $self->_base_offset, $prev_key );
$self->unlock();