@Test public void testNeighbors() { UGraph<String> graph = new LightUGraph<String>(); UNode<String> a = graph.add("a"); UNode<String> b = graph.add("b"); UNode<String> c = graph.add("c"); a.connect(a); b.connect(c); c.connect(a); a.connect(c); a.connect(c); Set<Node<String>> aNbsExpected = new HashSet<Node<String>>(Arrays.asList(a, c)); Set<Node<String>> bNbsExpected = new HashSet<Node<String>>(Arrays.asList(c)); Set<Node<String>> cNbsExpected = new HashSet<Node<String>>(Arrays.asList(b, a)); Set<Node<String>> aNbsActual = new HashSet<Node<String>>(a.neighbors()); Set<Node<String>> bNbsActual = new HashSet<Node<String>>(b.neighbors()); Set<Node<String>> cNbsActual = new HashSet<Node<String>>(c.neighbors()); assertEquals(aNbsExpected, aNbsActual); assertEquals(bNbsExpected, bNbsActual); assertEquals(cNbsExpected, cNbsActual); }
@Override public UNode<L> add(L label) { labels.add(label); neighbors.add(new ArrayList<Integer>(NEIGHBOR_CAPACITY)); sorted = false; return new LightUNode(neighbors.size() - 1); }
LightUGraph implements UGraph<L>, FastWalkable<L, UNode<L>> { @Override public UNode<L> add(L label) { labels.add(label); neighbors.add(new ArrayList<Integer>(NEIGHBOR_CAPACITY)); sorted = false; return new LightUNode(neighbors.size() - 1); } }
LightUGraph implements UGraph<L>, FastWalkable<L, UNode<L>> { @Override public UNode<L> add(L label) { labels.add(label); neighbors.add(new ArrayList<Integer>(NEIGHBOR_CAPACITY)); sorted = false; return new LightUNode(neighbors.size() - 1); } LightUGraph();  LightUGraph(int capacity); }
LightUGraph implements UGraph<L>, FastWalkable<L, UNode<L>> { @Override public UNode<L> add(L label) { labels.add(label); neighbors.add(new ArrayList<Integer>(NEIGHBOR_CAPACITY)); sorted = false; return new LightUNode(neighbors.size() - 1); } 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 UNode<L> add(L label) { labels.add(label); neighbors.add(new ArrayList<Integer>(NEIGHBOR_CAPACITY)); sorted = false; return new LightUNode(neighbors.size() - 1); } 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; }