Example #1
0
 def key_in_range(self, key):
     """
     Checks if a key is within the range covered by this bucket. Returns
     a boolean to indicate if a certain key should be placed within this
     bucket.
     """
     if isinstance(key, str):
         key = hex_to_long(key)
     return self.range_min <= key < self.range_max
Example #2
0
 def _bucket_index(self, key):
     """
     Returns the index of the bucket responsible for the specified key
     string.
     """
     if isinstance(key, str):
         key = hex_to_long(key)
     # Bound check for key too small.
     if key < 0:
         raise ValueError('Key out of range')
     for i, bucket in enumerate(self._buckets):
         if bucket.key_in_range(key):
             return i
     # Key was too big given the key space.
     raise ValueError('Key out of range.')