示例#1
0
  public int testGraphIterators() {
    int foo = 0;

    // Iterating on all nodes
    start = System.currentTimeMillis();
    Iterator<Node> nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      if (n.hasAttribute("foo")) foo++;
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.GRAPH_NODE_IT, end - start);

    // iterating on all edges
    start = System.currentTimeMillis();
    Iterator<Edge> edgeIt = g.getEdgeIterator();
    while (edgeIt.hasNext()) {
      Edge e = edgeIt.next();
      if (e.hasAttribute("foo")) foo++;
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.GRAPH_EDGE_IT, end - start);

    return foo;
  }
示例#2
0
  public int testNodeIterators() {
    int foo = 0;

    // For each node n, iterating on all edges of n
    start = System.currentTimeMillis();
    Iterator<Node> nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      Iterator<Edge> edgeIt = n.getEdgeIterator();
      while (edgeIt.hasNext()) {
        Edge e = edgeIt.next();
        if (e.hasAttribute("foo")) foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_EDGE_IT, end - start);

    // For each node n, iterating on all entering edges of n
    start = System.currentTimeMillis();
    nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      Iterator<Edge> edgeIt = n.getEnteringEdgeIterator();
      while (edgeIt.hasNext()) {
        Edge e = edgeIt.next();
        if (e.hasAttribute("foo")) foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_ENTERING_EDGE_IT, end - start);

    // For each node n, iterating on all leaving edges of n
    start = System.currentTimeMillis();
    nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      Iterator<Edge> edgeIt = n.getLeavingEdgeIterator();
      while (edgeIt.hasNext()) {
        Edge e = edgeIt.next();
        if (e.hasAttribute("foo")) foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_LEAVING_EDGE_IT, end - start);

    // For each node n, iterating on all neighbors of n
    start = System.currentTimeMillis();
    nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      Iterator<Node> neighborIt = n.getNeighborNodeIterator();
      while (neighborIt.hasNext()) {
        Node neighbor = neighborIt.next();
        if (neighbor.hasAttribute("foo")) foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_NEIGHBOR_IT, end - start);

    // For each node n, iterating on all edges of n using n.getEdge(i)
    start = System.currentTimeMillis();
    nodeIt = g.getNodeIterator();
    while (nodeIt.hasNext()) {
      Node n = nodeIt.next();
      for (int i = 0; i < n.getDegree(); i++) {
        Edge e = n.getEdge(i);
        if (e.hasAttribute("foo")) foo++;
      }
    }
    end = System.currentTimeMillis();
    measureValues.put(Measures.NODE_GET_EDGE, end - start);

    return foo;
  }