public IntIterator getNeighbors()

in src/main/java/com/twitter/sbf/graph/SubGraphWithoutWeakLinks.java [60:95]


  public IntIterator getNeighbors(int nodeId) {
    if (!nodesOfSubgraph.contains(nodeId)) {
      return IntIterators.EMPTY_ITERATOR;
    } else {
      int[] allNeighbors = fullGraph.getNeighbors(nodeId);
      IntSet neighborsIncludingWeakLinks = new IntOpenHashSet();
      for (int n : allNeighbors) {
        if (nodesOfSubgraph.contains(n)) {
          neighborsIncludingWeakLinks.add(n);
        }
      }

      int[] neighborsWithoutWeakLinks = new int[neighborsIncludingWeakLinks.size()];
      int lengthOfNeighborsWithoutWeakLinks = 0;
      for (int neighbor : neighborsIncludingWeakLinks) {
        boolean sharedNeighborsSoFar = false;
        for (int neighborOfNeighbor: fullGraph.getNeighbors(neighbor)) {
          if (neighborsIncludingWeakLinks.contains(neighborOfNeighbor)
              && nodesOfSubgraph.contains(neighborOfNeighbor)) {
            sharedNeighborsSoFar = true;
            break;
          }
        }
        if (sharedNeighborsSoFar) {
          neighborsWithoutWeakLinks[lengthOfNeighborsWithoutWeakLinks++] = neighbor;
        } else {
          numWeakLinks++;
        }

      }

      int[] ret = Arrays.copyOf(neighborsWithoutWeakLinks, lengthOfNeighborsWithoutWeakLinks);

      return new IntIteratorFromArray(ret);
    }
  }