def insert_node(self, value=0): root = self.root_node while root.__getattribute__('next_node') is not None: root = root.__getattribute__('next_node') temp = Node(value) root.__setattr__('next_node', temp) temp.__setattr__('prev_node', root)
def insert_node_at_index(self, index, value=0): temp = 0 temp_node = self.root_node if index >= self.counter: raise ValueError("Incorrect Index value") while temp != (index - 1): temp_node = temp_node.get_next_node temp += 1 new_node = Node(value) new_node.next_node = temp_node.get_next_node temp_node.__setattr__('next_node', new_node) self.counter += 1
def insert_node_at_rear(self, value): root = self.root_node while root.next_node != self._tail: root = root.next_node temp = Node(value) self._tail = temp self._tail.next_node = self._head
def get_ffnet_node(self, start_id, end_id): start_id_list = list(filter(lambda node: node.id == start_id, self.topology.nodes)) if len(start_id_list) != 1: node_start = Node(start_id) self.topology.add_node(node_start) else: node_start = start_id_list[0] end_id_list = list(filter(lambda node: node.id == end_id, self.topology.nodes)) if len(end_id_list) != 1: node_end = Node(end_id) self.topology.add_node(node_end) else: node_end = end_id_list[0] return node_start, node_end
def dfs(node): for nei in node.neighbors: if nei.val not in nodes: new_node = Node(nei.val) nodes[nei.val] = new_node dfs(nei) nodes[node.val].neighbors.append(nodes[nei.val])
def cloneGraph_DFS_iter(self, node): # 41ms if not node: return nodes = {} source = Node(node.val) nodes[source.val] = source stack = [node] while stack: u = stack.pop() for nei in u.neighbors: if nei.val not in nodes: new_node = Node(nei.val) nodes[nei.val] = new_node stack.append(nei) nodes[u.val].neighbors.append(nodes[nei.val]) return source
def cloneGraph(self, node: 'Node') -> 'Node': # 40ms if not node: return nodes = {} source = Node(node.val) nodes[source.val] = source q = collections.deque([node]) while q: u = q.popleft() for nei in u.neighbors: if nei.val not in nodes: new_node = Node(nei.val) nodes[nei.val] = new_node q.append(nei) nodes[u.val].neighbors.append(nodes[nei.val]) return source
def read(self, path, size, offset, fh): try: node = Node.pathToNodeTranslator(self.rootNode, path) print("Data : " + node.getData() + " FROM node : " + node.getName()) return node.getData() except Exception as e: print(str(e) + " on .read()") return "nodata"
def mkdir(self, path, mode): print("mkdir requested on path" + path) try: pathsplit = path.split("/") folder = pathsplit[-2] filename = pathsplit[-1] node = Node.createDirectoryFile(self, None, filename, mode) if (folder == ""): self.rootNode.addChildren(node) else: Node.pathToNodeTranslator( self.rootNode, self.__getParentPath(path)).addChildren(node) except Exception as e: print(str(e) + "on creation (path" + path + ")") raise e except Exception as e: print(e) raise e
def create(self, path, mode, fi=None): print(".create on " + path) try: pathsplit = path.split("/") filename = pathsplit[-1] parent = pathsplit[-2] node = Node.createRegularFile(self, None, filename, mode) if (parent == ""): self.rootNode.addChildren(node) else: Node.pathToNodeTranslator( self.rootNode, self.__getParentPath(path)).addChildren(node) except Exception as e: print("Exception thrown : %s on create at path %s parent %s" % (str(e), path, self.__getParentPath(path))) raise e self.fd += 1 print("...completed") return self.fd
def write(self, path, data, offset, fh): print("WRITE") try: print("write op on " + str(path) + " the data " + data) node = Node.pathToNodeTranslator(self.rootNode, path) node.setSize(len(data)) node.setData(data) print("node " + node.getName() + " updated with data " + node.getData()) except Exception as e: print("ERR ON WRITE") print(str(e)) return len(data)
def loop_main(temp): flds = temp.replace("\"", "").replace("[[", "").replace("]]", "").rstrip() ope_n = OperateNode() if flds == "": node = Node(None) elif flds == "[]": node = Node(None, None) else: data = [[int(col) for col in row.split(",")] for row in flds.split("],[")] node = ope_n.createNode(data) print("node = \n{0}".format(ope_n.nodeToString(node))) sl = Solution() time0 = time.time() result = sl.cloneGraph(node) time1 = time.time() print("result = \n{0}".format(ope_n.nodeToString(result))) print("Execute time ... : {0:f}[s]\n".format(time1 - time0))
def getattr(self, path, fh=None): # raise FuseOSError(ENOENT) try: fileref = Node.pathToNodeTranslator(self.rootNode, path) if (fileref == None): raise FuseOSError(ENOENT) x = fileref.toStandardDict() print(str(x)) now = time() print("getattr COMPLETED") return x except Exception as e: print(e) raise FuseOSError(ENOENT)
def connect(self, root: 'Node') -> 'Node': # 52ms node = root tail = dummy = Node(0) while node: tail.next = node.left if tail.next: tail = tail.next tail.next = node.right if tail.next: tail = tail.next node = node.next if not node: tail = dummy node = dummy.next return root
def cloneGraph_DFS(self, node: 'Node') -> 'Node': # 40ms def dfs(node): for nei in node.neighbors: if nei.val not in nodes: new_node = Node(nei.val) nodes[nei.val] = new_node dfs(nei) nodes[node.val].neighbors.append(nodes[nei.val]) if not node: return nodes = {} source = Node(node.val) nodes[source.val] = source dfs(node) return source
def readdir(self, path, fh): """ Returns a list([]) with all files and directories available + . and .. (current and previous dir) :param path: the path of the dir asking the files WARNING , I STUCK 102810281 HOURS -> ALWAYS RETURN THE NAME OF THE FILES , WITH NO / AS THE FIRST CHARACTER :param fh: the :return: """ print(".readdir request issued on folder" + path) try: currentNodeChildren = Node.pathToNodeTranslator( self.rootNode, path).getData() retval = [".", ".."] + [x.getName() for x in currentNodeChildren] print("the returned children is " + str(retval)) return retval except Exception as e: print(e) return [".", ".."]
def main(): taskmanager = RayManager(2) coms = NodeComs('127.0.0.1', '8888') count = 0 print "create task manager object" node = Node(coms, taskmanager) while 1: if node.free_task_slots() and count < 5: new_task = get_task() node.add_task(new_task) count += 1 print count node.get_finished_tasks() active_tasks = node.taskmanager.active_items print 'active_tasks', active_tasks if count == 5 and active_tasks == 0: sys.exit() sleep(1)
def __init__(self): self.fd = 4 #Just a random number , we dont care about file desciptors because we know for the prototype that only one user will perform calls self.rootNode = Node.createDirectoryFile(self, None, "/", 0o755) #this is the root node
def __init__(self): self.root_node = Node(10, None, None) self.counter = 1
def __init__(self, data, successor): Node.__init__(self, data) self.__successor = successor
def insert_node_at_rear(self, value=0): temp = self.root_node while temp.get_next_node is not None: temp = temp.__getattribute__('next_node') temp.__setattr__('next_node', Node(value)) self.counter += 1
def __init__(self): self.root_node = Node(50, None, None)
def __init__(self): self.root_node = Node(30) self._head = self.root_node self._tail = self.root_node
def insert_node_at_front(self, value=0): temp = Node(value) temp.next_node = self.root_node self.root_node = temp self.counter += 1