def get_neighbors_attr(graph, n, pred=False): """Get the neighbors attr of node in graph. Parameters ---------- graph: the graph to query. n: node the node to get neighbors. report_type: the report type of report graph operation, types_pb2.SUCC_ATTR_BY_NODE: get the successors attr of node, types_pb2.PRED_ATTR_BY_NODE: get the predecessors attr of node, Returns ------- attr: tuple """ if graph.graph_type == graph_def_pb2.ARROW_PROPERTY: n = graph._convert_to_label_id_tuple(n) report_t = types_pb2.PRED_ATTR_BY_NODE if pred else types_pb2.SUCC_ATTR_BY_NODE op = dag_utils.report_graph(graph, report_t, node=simdjson.dumps(n).encode("utf-8")) archive = op.eval() return simdjson.loads(archive.get_bytes())
def _get_pred_attr_cache(self, gid): op = dag_utils.report_graph(self._graph, types_pb2.PRED_ATTR_BY_GID, gid=gid) archive = op.eval() gid = archive.get_uint64() fp = io.BytesIO(archive.get_bytes()) pred_attr_cache = simdjson.load(fp) return gid, pred_attr_cache
def _get_pred_cache(self, gid): op = dag_utils.report_graph(self._graph, types_pb2.PRED_BY_GID, gid=gid) archive = op.eval() gid = archive.get_uint64() fp = io.BytesIO(archive.get_bytes()) pred_cache = msgpack.load(fp, use_list=False) return gid, pred_cache
def _get_succ_attr_cache(self, gid): op = dag_utils.report_graph(self._graph, types_pb2.SUCC_ATTR_BY_GID, gid=gid) archive = op.eval() gid = archive.get_uint64() fp = io.BytesIO(archive.get_bytes()) succ_attr_cache = msgpack.load(fp, use_list=False) return gid, succ_attr_cache
def _get_node_id_cache(self, gid): op = dag_utils.report_graph(self._graph, types_pb2.NODE_ID_CACHE_BY_GID, gid=gid) archive = op.eval() gid = archive.get_uint64() node_size = archive.get_uint32() fp = io.BytesIO(archive.get_bytes()) node_array = msgpack.load(fp, use_list=False) return gid, node_size, node_array
def get_node_data(graph, n): """Returns the attribute dictionary of node n. This is identical to `G[n]`. Parameters ---------- n : nodes Returns ------- node_dict : dictionary The node attribute dictionary. Examples -------- >>> G = nx.path_graph(4) # or DiGraph etc >>> G[0] {} Warning: Assigning to `G[n]` is not permitted. But it is safe to assign attributes `G[n]['foo']` >>> G[0]['weight'] = 7 >>> G[0]['weight'] 7 >>> G = nx.path_graph(4) # or DiGraph etc >>> G.get_node_data(0, 1) {} """ if graph.graph_type == graph_def_pb2.ARROW_PROPERTY: n = graph._convert_to_label_id_tuple(n) op = dag_utils.report_graph(graph, types_pb2.NODE_DATA, node=simdjson.dumps(n).encode("utf-8")) archive = op.eval() return msgpack.loads(archive.get_bytes(), use_list=False)