def __init__(self, initial_elements=17, load_factor=2, cmpfunction=None): self.size = 0 self.spaces = initial_elements self.load_factor = load_factor self.cmpfunction = cmpfunction self.table = lt.lista('AL', cmpfunction, 0) for i in range(self.spaces): bucket = lt.lista('SL', cmpfunction) for j in range(int(load_factor)): bucket.add_last(map_entry()) self.table.add_last(bucket)
def value_set(self): value_list = lt.lista('SL', self.cmpfunction) for bucket in self.table: for entry in bucket: if entry.info.key is not None: value_list.add_last(entry.value) return value_list
def key_set(self): key_list = lt.lista('SL', self.cmpfunction) for bucket in self.table: for entry in bucket: if entry.key is not None: key_list.add_last(entry.key) return key_list
def __init__(self, initial_elements=17, load_factor=0.5, cmpfunction=None): self.size = 0 self.spaces = initial_elements self.load_factor = load_factor self.current_factor = load_factor self.cmpfunction = cmpfunction self.table = lt.lista('AL', cmpfunction, 0) for bucket in range(initial_elements * int(load_factor**-1)): self.table.add_last(map_entry())
def in_adjacents(self, vertex): vertex_index = self.vertexes.get(vertex).value in_adjacents_list = lt.lista('SL', self.cmpfunction) current_index = 1 for vertex_edges in self.edges: if vertex_edges.get_element(vertex_index) != math.inf: in_adjacents_list.add_last(self.__find_vertex(current_index)) current_index += 1 return in_adjacents_list
def out_adjacents(self, vertex): vertex_index = self.vertexes.get(vertex).value out_adjacents_list = lt.lista('SL', self.cmpfunction) current_index = 1 for edge in self.edges.get_element(vertex_index): if edge != math.inf: out_adjacents_list.add_last(self.__find_vertex(current_index)) current_index += 1 return out_adjacents_list
def insert_vertex(self, vertex): self.num_vertexes += 1 self.vertexes.put(vertex, self.num_vertexes) edges_lst = lt.lista('AL', self.cmpfunction) for i in range(self.num_vertexes): edges_lst.add_last(math.inf) for vertex_edges in self.edges: vertex_edges.add_last(math.inf) self.edges.add_last(edges_lst)
def __rehash(self): self.spaces *= 2 self.size = 0 old_table = self.table new_table = lt.lista('AL', self.cmpfunction, 0) self.table = new_table for bucket in range(self.spaces): self.table.add_first(map_entry()) for bucket in old_table: if bucket.key is not None and bucket.key != '__EMPTY__': self.put(bucket.key, bucket.value)
def edges_list(self): edges_list = lt.lista('SL', self.cmpfunction) edges_iterator_1 = lt.lt_iterator(self.edges) vertex_A_index = 1 for vertex_edges in self.edges: vertex_B_index = 1 for edge in vertex_edges: if edge != math.inf: edges_list.add_last({ 'vertex_A': self.__find_vertex(vertex_A_index), 'vertex_B': self.__find_vertex(vertex_B_index), 'weight': edge }) vertex_B_index += 1 vertex_A_index += 1 return edges_list
def keys_range(self, low_key, high_key): return self.__tree_keys_range(low_key, high_key, self.root, lt.lista('SL', self.cmpfunction))
def value_set(self): value_list = lt.lista('SL', self.cmpfunction) for entry in self.table: if entry.key is not None and entry.key != '__EMPTY__': value_list.add_last(entry.value) return value_list
def key_set(self): key_list = lt.lista('SL', self.cmpfunction) for entry in self.table: if entry.key is not None and entry.key != '__EMPTY__': key_list.add_last(entry.key) return key_list
def key_set(self): return self.__tree_key_set(self.root, lt.lista('SL', self.cmpfunction))
def __init__(self, initial_elements=17, cmpfunction=None): self.edges = lt.lista('AL', cmpfunction) self.vertexes = mp.mapa('CHT', initial_elements, 1, cmpfunction) self.num_vertexes = 0 self.num_edges = 0 self.cmpfunction = cmpfunction
def inorder(self): if self.root is not None: return self.__tree_inorder(self.root, lt.lista('SL', self.cmpfunction)) return None
def __init__(self): self.stack = lt.lista('SL') self.size = 0
def __entry_set(self): return self.__tree_entry_set( self.root, lt.lista('SL', cmpfunction=self.cmpfunction))
def __init__(self, cmpfunction=None): self.size = 0 self.cmpfunction = cmpfunction self.heap = lt.lista('AL', self.cmpfunction)
def value_set(self): return self.__tree_value_set(self.root, lt.lista('SL', self.cmpfunction))
def __init__(self): self.queue = lt.lista('SL') self.size = 0