Ejemplo n.º 1
0
    def get_next_edge_offset(self):
        """Returns the offset into the database file where the
        *next* edge with the same source node can be found.

        IMPORTANT: You should always read the offset using this getter
        rather than using the objects __dict__ or going around the name
        mangling.  The value is updated on each read in case the node's
        underlying data has been changed since object instantiation.

        Parameters
        ----------
        None

        Returns
        -------
        Integer"""
        st = structs.unpack_edge(self.__graph._edge_map.read(self.id))
        self.__next_edge = st[6]
        return self.__next_edge
Ejemplo n.º 2
0
    def get_next_edge_offset(self):
        """Returns the offset into the database file where the
        *next* edge with the same source node can be found.

        IMPORTANT: You should always read the offset using this getter
        rather than using the objects __dict__ or going around the name
        mangling.  The value is updated on each read in case the node's
        underlying data has been changed since object instantiation.

        Parameters
        ----------
        None

        Returns
        -------
        Integer"""
        st = structs.unpack_edge(self.__graph._edge_map.read(self.id))
        self.__next_edge = st[6]
        return self.__next_edge
Ejemplo n.º 3
0
    def _from_struct(self, graphref, id_num, bin_str):
        """Reconstructs an Edge object from a struct of binary data.

        IMPORTANT: Edge deletion in vgraph is lazy.  When a node is
        deleted, incoming edges are only deleted when a caller attempts
        to access them.  This method has the potential to return an edge
        other than the one requested if the requested edge is discovered 
        to be "dangling" during object creation.

        Parameters
        ----------
        graphref: a reference to a vgraph Graph object
        id_num: the integer ID for this Edge
        bin_str: a string of binary data

        Returns
        -------
        A vgraph Edge object"""
        edge_tuple = structs.unpack_edge(bin_str)
        node_1 = graphref.node(edge_tuple[1])
        node_2 = graphref.node(edge_tuple[2])
        e = Edge(
            graphref,
            node_1,
            node_2,
            label=re.sub(r'\x00', '', edge_tuple[3]),
            direction=edge_tuple[4],
            cost = edge_tuple[0]
        )
        e.id = id_num
        e._set_previous_edge_offset(edge_tuple[5])
        e._set_next_edge_offset(edge_tuple[6])
        if node_2 is None:
            graphref.delete_edge(e)
            if edge_tuple[6] == edge_tuple[5]:
                return []
            return graphref.edge(edge_tuple[6])
        return e
Ejemplo n.º 4
0
    def _from_struct(self, graphref, id_num, bin_str):
        """Reconstructs an Edge object from a struct of binary data.

        IMPORTANT: Edge deletion in vgraph is lazy.  When a node is
        deleted, incoming edges are only deleted when a caller attempts
        to access them.  This method has the potential to return an edge
        other than the one requested if the requested edge is discovered 
        to be "dangling" during object creation.

        Parameters
        ----------
        graphref: a reference to a vgraph Graph object
        id_num: the integer ID for this Edge
        bin_str: a string of binary data

        Returns
        -------
        A vgraph Edge object"""
        edge_tuple = structs.unpack_edge(bin_str)
        node_1 = graphref.node(edge_tuple[1])
        node_2 = graphref.node(edge_tuple[2])
        e = Edge(graphref,
                 node_1,
                 node_2,
                 label=re.sub(r'\x00', '', edge_tuple[3]),
                 direction=edge_tuple[4],
                 cost=edge_tuple[0])
        e.id = id_num
        e._set_previous_edge_offset(edge_tuple[5])
        e._set_next_edge_offset(edge_tuple[6])
        if node_2 is None:
            graphref.delete_edge(e)
            if edge_tuple[6] == edge_tuple[5]:
                return []
            return graphref.edge(edge_tuple[6])
        return e