Giraph source code analysis (six) - Edge Analysis

1. Vertex class, storage vertices adjacency table form. Each vertex has VertexId, VertexValue, OutgoingEdges and Halt, boolean type recording halt state variable for vertex represents active, true indicates the inactive state when false. The following code fragment.

Giraph source code analysis (six) - Edge Analysis
2.org.apache.giraph.edge.Edge interface for storing vertex side, each side comprising two edgeValue targetVertexId and properties. Class diagram as follows:

Giraph source code analysis (six) - Edge Analysis

Giraph default storage class DefaultEdge side, there are two such variables: I targetVertexId and E value, I is the type ID of the vertex, E is the edge type. Note that, a DefaultEdge class inherits ReusableEdge <I, E> interface definition ReusableEdge <I, E> class, the following caption:
A Complete Edge, The target Vertex and The Edge value Can only BE One Edge with A. . destination vertex id per edge map This edge can be reused, that is you can set it's target vertex ID and edge value Note:. this class is useful for certain optimizations, but it's not meant to be exposed to the user Look at MutableEdge. instead.

Text can be seen from the above description, edge can be reused, and only need to modify the values targetVertexId value on the line. That is if every Vertex more than the edges, it will only create a DefaultEdge object to store edge.
3.org.apache.giraph.edge.OutEdges for storing each vertex out-edges. Vertex seen from the definition of classes, each edge vertices are stored in the object OutEdges edge type, the following graph OutEdges interface:

Giraph source code analysis (six) - Edge Analysis

Giraph default usage ByteArrayEdges <I, E>, all the edges of each vertex are stored in byte [] in. When sending a message to the apex of its outgoing edges, edges need to traverse the object Vertex class. Sample code is as follows:

Giraph source code analysis (six) - Edge Analysis
Note: DefaultEdge defined by apparent when traversing getEdges, the same object, the object is only changed when the value returned by Edge object. Let's continue looking at the code to prove this point of view.
See iterator ByteArrayEdges class () method as follows:

Giraph source code analysis (six) - Edge Analysis
Returns ByteArrayEdgeIterator internal class objects, are defined as follows:

Giraph source code analysis (six) - Edge Analysis

Summary: When a great degree as vertex, this optimization is very good, can be a very good save memory. The UK-2005 data, the maximum degree of the vertex is 5213.
Assume that the vertices of the vertex has a <2, 0.4>, <3, 7.8>, <5, 6.4>. The following code:

Giraph source code analysis (six) - Edge Analysis
The output is:
[2]
[3, 3]
[5,5, 5]
is not desirable [2, 3, 5]

Guess you like

Origin blog.51cto.com/14463231/2428877