@Test public void testNeighborsFast() { UGraph<String> graph = Examples.yeast(); graph = LightUGraph.copy(graph); assertTrue(graph instanceof FastWalkable); for(Node<String> node : graph.nodes()) { Collection<? extends Node<String>> nbs = node.neighbors(); Collection<? extends Node<String>> col = ((FastWalkable<String,? extends Node<String>>)graph).neighborsFast(node); assertTrue(col instanceof List<?>); Set<Node<String>> nbsFast = new HashSet<Node<String>>(col); List<Integer> nbsList = new ArrayList<Integer>(); for(Node<String> nod : nbs) nbsList.add(nod.index()); List<Integer> nbsFastList = new ArrayList<Integer>(); for(Node<String> nod : nbsFast) nbsFastList.add(nod.index()); Collections.sort(nbsList); Collections.sort(nbsFastList); assertEquals(nbsList, nbsFastList); } }
@Override public List<UNode<L>> neighborsFast(Node<L> node) { if(node.graph() != this) throw new IllegalArgumentException("Cannot call with node from another graph."); List<Integer> indices = neighbors.get(node.index()); return new NodeList(indices); }
LightUGraph implements UGraph<L>, FastWalkable<L, UNode<L>> { @Override public List<UNode<L>> neighborsFast(Node<L> node) { if(node.graph() != this) throw new IllegalArgumentException("Cannot call with node from another graph."); List<Integer> indices = neighbors.get(node.index()); return new NodeList(indices); } }
LightUGraph implements UGraph<L>, FastWalkable<L, UNode<L>> { @Override public List<UNode<L>> neighborsFast(Node<L> node) { if(node.graph() != this) throw new IllegalArgumentException("Cannot call with node from another graph."); List<Integer> indices = neighbors.get(node.index()); return new NodeList(indices); } LightUGraph();  LightUGraph(int capacity); }
LightUGraph implements UGraph<L>, FastWalkable<L, UNode<L>> { @Override public List<UNode<L>> neighborsFast(Node<L> node) { if(node.graph() != this) throw new IllegalArgumentException("Cannot call with node from another graph."); List<Integer> indices = neighbors.get(node.index()); return new NodeList(indices); } LightUGraph();  LightUGraph(int capacity); @Override int size(); @Override long numLinks(); @Override UNode<L> node(L label); @Override Collection<? extends UNode<L>> nodes(L label); @Override List<? extends UNode<L>> nodes(); @Override Iterable<? extends ULink<L>> links(); @Override UNode<L> add(L label); @Override Set<L> labels(); @Override boolean connected(L from, L to); @Override long state(); String toString(); void compact(int margin); void sort(); static LightUGraph<L> copy(Graph<L> graph); @Override int hashCode(); boolean equals(Object other); @Override UNode<L> get(int i); @SuppressWarnings("unchecked") @Override Class<? extends UGraph<L>> level(); @Override List<UNode<L>> neighborsFast(Node<L> node); }
LightUGraph implements UGraph<L>, FastWalkable<L, UNode<L>> { @Override public List<UNode<L>> neighborsFast(Node<L> node) { if(node.graph() != this) throw new IllegalArgumentException("Cannot call with node from another graph."); List<Integer> indices = neighbors.get(node.index()); return new NodeList(indices); } LightUGraph();  LightUGraph(int capacity); @Override int size(); @Override long numLinks(); @Override UNode<L> node(L label); @Override Collection<? extends UNode<L>> nodes(L label); @Override List<? extends UNode<L>> nodes(); @Override Iterable<? extends ULink<L>> links(); @Override UNode<L> add(L label); @Override Set<L> labels(); @Override boolean connected(L from, L to); @Override long state(); String toString(); void compact(int margin); void sort(); static LightUGraph<L> copy(Graph<L> graph); @Override int hashCode(); boolean equals(Object other); @Override UNode<L> get(int i); @SuppressWarnings("unchecked") @Override Class<? extends UGraph<L>> level(); @Override List<UNode<L>> neighborsFast(Node<L> node); static final int NEIGHBOR_CAPACITY; }