From: rkinyon Date: Thu, 25 May 2006 18:22:04 +0000 (+0000) Subject: r13599@rob-kinyons-powerbook58: rob | 2006-05-25 14:21:08 -0400 X-Git-Tag: 0-99_03~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=83c43bb572732d2b5402502a2a1e89d480867599;p=dbsrgits%2FDBM-Deep.git r13599@rob-kinyons-powerbook58: rob | 2006-05-25 14:21:08 -0400 Finished converting all code to use the four primary engine methods --- diff --git a/lib/DBM/Deep.pm b/lib/DBM/Deep.pm index 961da94..3f8d128 100644 --- a/lib/DBM/Deep.pm +++ b/lib/DBM/Deep.pm @@ -507,8 +507,6 @@ sub FETCH { my ($key, $orig_key) = @_; $orig_key = $key unless defined $orig_key; - my $md5 = $self->_engine->apply_digest($key); - ## # Request shared lock for reading ## @@ -552,30 +550,15 @@ sub DELETE { ## $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; @@ -588,27 +571,12 @@ sub EXISTS { 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(); @@ -646,19 +614,16 @@ sub CLEAR { 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 ); } diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 54ec75d..723c029 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -82,11 +82,27 @@ sub key_exists { 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 ); } ################################################################################ @@ -994,34 +1010,6 @@ sub traverse_index { 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 { diff --git a/lib/DBM/Deep/Hash.pm b/lib/DBM/Deep/Hash.pm index a50be1c..ddaae9d 100644 --- a/lib/DBM/Deep/Hash.pm +++ b/lib/DBM/Deep/Hash.pm @@ -92,7 +92,7 @@ sub FIRSTKEY { ## $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(); @@ -111,14 +111,12 @@ sub NEXTKEY { ? $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();