def load_all_nodes(self): start = MemoryGraph.node_key(0) stop = MemoryGraph.node_key(MAX_KEY_VALUE) n = 0 feats = [] ids = [] for key, value in self.db.iterator(start=start, stop=stop): node = MemoryGraph.decode_node(value) node["id"] = MemoryGraph.decode_node_key(key) cwg.add_node(self.graph, node["id"]) feats.append(node["f"]) ids.append(node["id"]) n += 1 if n % 1000 == 0: print("MemoryGraph: loading nodes", n) self.index.add_items(feats, ids) feats = [] ids = [] if len(feats) > 0: self.index.add_items(feats, ids)
def load_all_node_ids(self): start = MemoryGraph.node_key(0) stop = MemoryGraph.node_key(MAX_KEY_VALUE) for key in self.db.iterator(start=start, stop=stop, include_value=False): cwg.add_node(self.graph, MemoryGraph.decode_node_key(key))
def insert_nodes(self, nodes): node_ids = self.generate_node_ids(len(nodes)) wb = self.db.write_batch() for node_id, node in zip(node_ids, nodes): cwg.add_node(self.graph, node_id) wb.put(MemoryGraph.node_key(node_id), MemoryGraph.encode_node(node)) wb.write() self.index.add_items([n["f"] for n in nodes], node_ids) return node_ids