From: rkinyon Date: Tue, 28 Feb 2006 20:07:09 +0000 (+0000) Subject: Moved _bucket_exists to Engine X-Git-Tag: 0-99_01~110 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=912d50b1c7fab3433aa812baebd75ae7c975ee71;p=dbsrgits%2FDBM-Deep.git Moved _bucket_exists to Engine --- diff --git a/lib/DBM/Deep.pm b/lib/DBM/Deep.pm index bd3a6e7..e08ba84 100644 --- a/lib/DBM/Deep.pm +++ b/lib/DBM/Deep.pm @@ -203,42 +203,6 @@ sub TIEARRAY { #sub DESTROY { #} -sub _bucket_exists { - ## - # Check existence of single key given tag and MD5 digested key. - ## - my $self = shift; - my ($tag, $md5) = @_; - my $keys = $tag->{content}; - - ## - # 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 -- return true - ## - return 1; - } # i loop - - return; -} - sub _find_bucket_list { ## # Locate offset for bucket list, given digested key @@ -897,7 +861,7 @@ sub EXISTS { ## # Check if bucket exists and return 1 or '' ## - my $result = $self->_bucket_exists( $tag, $md5 ) || ''; + my $result = $self->{engine}->bucket_exists( $self, $tag, $md5 ) || ''; $self->unlock(); diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 8ee33a0..68d39d8 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -559,5 +559,41 @@ sub delete_bucket { return; } +sub bucket_exists { + ## + # Check existence of single key given tag and MD5 digested key. + ## + my $self = shift; + my ($obj, $tag, $md5) = @_; + my $keys = $tag->{content}; + + ## + # 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 -- return true + ## + return 1; + } # i loop + + return; +} + 1; __END__