def get_unique_count(self): uniqueVertexes = SingleArray() for row in self._array: if uniqueVertexes.getIndexByValue(row[0]) is None: uniqueVertexes.add(row[0]) if uniqueVertexes.getIndexByValue(row[1]) is None: uniqueVertexes.add(row[1]) return uniqueVertexes.size()
def DFS2Iterative( vertexIndex: int, components: Dictionary, component_index: int, vertexes: VectorArray, cache: SingleArray, ): currentVertex = vertexes[vertexIndex] stack = BasicStack() stack.push(Node(None)) stack.push(Node(vertexIndex)) cache.add(vertexIndex) while True: components.insert(component_index, currentVertex.index) for u in currentVertex.bindedVertexes: if components[u.index] is not None \ or cache.getIndexByValue(u.index) is not None: continue else: cache.add(u.index) stack.push(Node(u.index)) components.insert(component_index, u.index) stackValue = stack.pop().getItem() if stackValue is None: return currentVertex = vertexes[stackValue]
def makeAdjacencyVector(vertexIndexes: []): uniqueCount = 0 uniqueIndexes = SingleArray() for slaveVertexes in vertexIndexes: for vertexIndex in slaveVertexes: if not uniqueIndexes.getIndexByValue(vertexIndex) is None: continue uniqueIndexes.add(vertexIndex) uniqueCount += 1 return AdjacencyVector(uniqueCount)