(self, key)
Yields a sequence of ``(datapos, datalength)`` tuples associated
        with the given key.
Yields a sequence of ``(datapos, datalength)`` tuples associated
        with the given key.
Yields a sequence of ( datapos datalength ) tuples associated with the given key .
def ranges_for_key(self, key):
        """Yields a sequence of ``(datapos, datalength)`` tuples associated
        with the given key.
        """

        if not isinstance(key, bytes_type):
            raise TypeError("Key %r should be bytes" % key)
        dbfile = self.dbfile

        # Hash the key
        keyhash = self.hashfn(key)
        # Get the position and number of slots for the hash table in which the
        # key may be found
        tablestart, numslots = self.tables[keyhash & 255]
        # If the hash table is empty, we know the key doesn't exists
        if not numslots:
            return

        ptrsize = _pointer.size
        unpackptr = _pointer.unpack
        lenssize = _lengths.size
        unpacklens = _lengths.unpack

        # Calculate where the key's slot should be
        slotpos = tablestart + (((keyhash >> 8) % numslots) * ptrsize)
        # Read slots looking for our key's hash value
        for _ in xrange(numslots):
            slothash, itempos = unpackptr(dbfile.get(slotpos, ptrsize))
            # If this slot is empty, we're done
            if not itempos:
                return

            # If the key hash in this slot matches our key's hash, we might have
            # a match, so read the actual key and see if it's our key
            if slothash == keyhash:
                # Read the key and value lengths
                keylen, datalen = unpacklens(dbfile.get(itempos, lenssize))
                # Only bother reading the actual key if the lengths match
                if keylen == len(key):
                    keystart = itempos + lenssize
                    if key == dbfile.get(keystart, keylen):
                        # The keys match, so yield (datapos, datalen)
                        yield (keystart + keylen, datalen)

            slotpos += ptrsize
            # If we reach the end of the hashtable, wrap around
            if slotpos == tablestart + (numslots * ptrsize):
                slotpos = tablestart
def ranges_for_key ( self , key ) : if not isinstance ( key , bytes_type ) : raise TypeError ( "Key %r should be bytes" % key ) dbfile = self . dbfile # Hash the key keyhash = self . hashfn ( key ) # Get the position and number of slots for the hash table in which the # key may be found tablestart , numslots = self . tables [ keyhash & 255 ] # If the hash table is empty, we know the key doesn't exists if not numslots : return ptrsize = _pointer . size unpackptr = _pointer . unpack lenssize = _lengths . size unpacklens = _lengths . unpack # Calculate where the key's slot should be slotpos = tablestart + ( ( ( keyhash >> 8 ) % numslots ) * ptrsize ) # Read slots looking for our key's hash value for _ in xrange ( numslots ) : slothash , itempos = unpackptr ( dbfile . get ( slotpos , ptrsize ) ) # If this slot is empty, we're done if not itempos : return # If the key hash in this slot matches our key's hash, we might have # a match, so read the actual key and see if it's our key if slothash == keyhash : # Read the key and value lengths keylen , datalen = unpacklens ( dbfile . get ( itempos , lenssize ) ) # Only bother reading the actual key if the lengths match if keylen == len ( key ) : keystart = itempos + lenssize if key == dbfile . get ( keystart , keylen ) : # The keys match, so yield (datapos, datalen) yield ( keystart + keylen , datalen ) slotpos += ptrsize # If we reach the end of the hashtable, wrap around if slotpos == tablestart + ( numslots * ptrsize ) : slotpos = tablestart