From: rkinyon Date: Tue, 28 Feb 2006 20:04:34 +0000 (+0000) Subject: Moved _delete_bucket to Engine X-Git-Tag: 0-99_01~111 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ab0e4957df46c7adc09230b5f8dcf60e5a33d0d8;p=dbsrgits%2FDBM-Deep.git Moved _delete_bucket to Engine --- diff --git a/lib/DBM/Deep.pm b/lib/DBM/Deep.pm index 884d202..bd3a6e7 100644 --- a/lib/DBM/Deep.pm +++ b/lib/DBM/Deep.pm @@ -203,48 +203,6 @@ sub TIEARRAY { #sub DESTROY { #} -sub _delete_bucket { - ## - # Delete single key/value pair given tag and MD5 digested key. - ## - my $self = shift; - my ($tag, $md5) = @_; - my $keys = $tag->{content}; - - my $fh = $self->_fh; - - ## - # Iterate through buckets, looking for a key match - ## - BUCKET: - for (my $i=0; $i<$MAX_BUCKETS; $i++) { - my $key = substr($keys, $i * $BUCKET_SIZE, $HASH_SIZE); - my $subloc = unpack($LONG_PACK, substr($keys, ($i * $BUCKET_SIZE) + $HASH_SIZE, $LONG_SIZE)); - - if (!$subloc) { - ## - # Hit end of list, no match - ## - return; - } - - if ( $md5 ne $key ) { - next BUCKET; - } - - ## - # Matched key -- delete bucket and return - ## - seek($fh, $tag->{offset} + ($i * $BUCKET_SIZE) + $self->_root->{file_offset}, SEEK_SET); - print( $fh substr($keys, ($i+1) * $BUCKET_SIZE ) ); - print( $fh chr(0) x $BUCKET_SIZE ); - - return 1; - } # i loop - - return; -} - sub _bucket_exists { ## # Check existence of single key given tag and MD5 digested key. @@ -900,7 +858,7 @@ sub DELETE { $value = $self->_root->{filter_fetch_value}->($value); } - my $result = $self->_delete_bucket( $tag, $md5 ); + my $result = $self->{engine}->delete_bucket( $self, $tag, $md5 ); ## # If this object is an array and the key deleted was on the end of the stack, diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 6e9df64..8ee33a0 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -516,5 +516,48 @@ sub get_bucket_value { return; } + +sub delete_bucket { + ## + # Delete single key/value pair given tag and MD5 digested key. + ## + my $self = shift; + my ($obj, $tag, $md5) = @_; + my $keys = $tag->{content}; + + my $fh = $obj->_fh; + + ## + # Iterate through buckets, looking for a key match + ## + BUCKET: + for (my $i=0; $i<$DBM::Deep::MAX_BUCKETS; $i++) { + my $key = substr($keys, $i * $DBM::Deep::BUCKET_SIZE, $DBM::Deep::HASH_SIZE); + my $subloc = unpack($DBM::Deep::LONG_PACK, substr($keys, ($i * $DBM::Deep::BUCKET_SIZE) + $DBM::Deep::HASH_SIZE, $DBM::Deep::LONG_SIZE)); + + if (!$subloc) { + ## + # Hit end of list, no match + ## + return; + } + + if ( $md5 ne $key ) { + next BUCKET; + } + + ## + # Matched key -- delete bucket and return + ## + seek($fh, $tag->{offset} + ($i * $DBM::Deep::BUCKET_SIZE) + $obj->_root->{file_offset}, SEEK_SET); + print( $fh substr($keys, ($i+1) * $DBM::Deep::BUCKET_SIZE ) ); + print( $fh chr(0) x $DBM::Deep::BUCKET_SIZE ); + + return 1; + } # i loop + + return; +} + 1; __END__