Exemplo n.º 1
0
 def _get_smaller(self, value):
     left_index = get_first_index(self._container, value, self._key)
     if left_index == len(self._container):
         return self._container
     if left_index == -1:
         return []
     # in case value doesn't exist left_index will point on the first one smaller than it
     if self._key(self._container[left_index]) != value:
         return self._container[: left_index + 1]
         
     return self._container[:left_index]
Exemplo n.º 2
0
 def __get_equal(self, value: int or float):
     """
     Returns the pattern matches whose keys are equal to the given value.
     """
     left_index = get_first_index(self._partial_matches, value,
                                  self._get_key)
     if left_index == len(self._partial_matches) or left_index == -1 or \
             self._get_key(self._partial_matches[left_index]) != value:
         return []
     right_index = get_last_index(self._partial_matches, value,
                                  self._get_key)
     return self._partial_matches[left_index:right_index + 1]
Exemplo n.º 3
0
 def __get_smaller_aux(self, value: int or float, return_equal: bool):
     """
     An auxiliary method for implementing "smaller than" or "smaller than or equal to" conditions.
     """
     left_index = get_last_index(self._partial_matches, value, self._get_key) if return_equal \
         else get_first_index(self._partial_matches, value, self._get_key)
     if left_index == len(self._partial_matches):
         return self._partial_matches
     if left_index == -1:
         return []
     # in case value doesn't exist left_index will point on the first one smaller than it
     if self._get_key(self._partial_matches[left_index]) != value:
         return self._partial_matches[:left_index + 1]
     return self._partial_matches[:left_index +
                                  1] if return_equal else self._partial_matches[:
                                                                                left_index]
Exemplo n.º 4
0
 def __get_greater_aux(self, value: int or float, return_equal: bool):
     """
     An auxiliary method for implementing "greater than" or "greater than or equal to" conditions.
     """
     right_index = get_first_index(self._partial_matches, value, self._get_key) if return_equal \
         else get_last_index(self._partial_matches, value, self._get_key)
     if right_index == len(self._partial_matches):
         return []
     if right_index == -1:
         return self._partial_matches
     # in case value doesn't exist right_index will point on the first one greater than it
     if self._get_key(self._partial_matches[right_index]) != value:
         return self._partial_matches[right_index:]
     return self._partial_matches[
         right_index:] if return_equal else self._partial_matches[
             right_index + 1:]
Exemplo n.º 5
0
 def _get_equal(self, value):
     left_index = get_first_index(self._container, value, self._key)
     if left_index == len(self._container) or left_index == -1 or self._key(self._container[left_index]) != value:
         return []
     right_index = get_last_index(self._container, value, self._key)
     return self._container[left_index : right_index + 1]