Пример #1
0
 def add(self, pm):
     self._access_count += 1
     if self._in_leaf and self._sorted_by_first_timestamp:
         self._container.append(pm)
     else:
         index = get_last_index(self._container, self._key(pm), self._key)
         index = 0 if index == -1 else index
         self._container.insert(index, pm)
Пример #2
0
 def _get_greater(self, value):
     right_index = get_last_index(self._container, value, self._key)
     if right_index == len(self._container):
         return []
     if right_index == -1:
         return self._container
     # in case value doesn't exist right_index will point on the first one greater than it
     if self._key(self._container[right_index]) != value:
         return self._container[right_index:] 
     return self._container[right_index + 1 :]
Пример #3
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]
Пример #4
0
 def add(self, pm: PatternMatch):
     """
     Efficiently inserts the new pattern match to the storage according to its key.
     """
     self._access_count += 1
     if self._sorted_by_arrival_order:
         # no need for artificially sorting
         self._partial_matches.append(pm)
         return
     index = get_last_index(self._partial_matches, self._get_key(pm),
                            self._get_key)
     index = 0 if index == -1 else index
     self._partial_matches.insert(index, pm)
Пример #5
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]
Пример #6
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:]
Пример #7
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]