static <N, V> DirectedGraphConnections<N, V> of() { // We store predecessors and successors in the same map, so double the initial capacity. int initialCapacity = INNER_CAPACITY * 2; return new DirectedGraphConnections<>( new HashMap<N, Object>(initialCapacity, INNER_LOAD_FACTOR), 0, 0); }
private GraphConnections<N, V> newConnections() { return isDirected() ? DirectedGraphConnections.<N, V>of() : UndirectedGraphConnections.<N, V>of(); } }
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) { Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS); return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), edgeValueFn)); }
private static <N, V> GraphConnections<N, V> connectionsOf( final ValueGraph<N, V> graph, final N node) { Function<N, V> successorNodeToValueFn = new Function<N, V>() { @Override public V apply(N successorNode) { return graph.edgeValueOrDefault(node, successorNode, null); } }; return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), successorNodeToValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), successorNodeToValueFn)); } }
private static <N, V> GraphConnections<N, V> connectionsOf( final ValueGraph<N, V> graph, final N node) { Function<N, V> successorNodeToValueFn = new Function<N, V>() { @Override public V apply(N successorNode) { return graph.edgeValueOrDefault(node, successorNode, null); } }; return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), successorNodeToValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), successorNodeToValueFn)); } }
static <N, V> DirectedGraphConnections<N, V> ofImmutable( Set<N> predecessors, Map<N, V> successorValues) { Map<N, Object> adjacentNodeValues = new HashMap<>(); adjacentNodeValues.putAll(successorValues); for (N predecessor : predecessors) { Object value = adjacentNodeValues.put(predecessor, PRED); if (value != null) { adjacentNodeValues.put(predecessor, new PredAndSucc(value)); } } return new DirectedGraphConnections<>( ImmutableMap.copyOf(adjacentNodeValues), predecessors.size(), successorValues.size()); }
private GraphConnections<N, V> newConnections() { return isDirected() ? DirectedGraphConnections.<N, V>of() : UndirectedGraphConnections.<N, V>of(); } }
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) { Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS); return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), edgeValueFn)); }
static <N, V> DirectedGraphConnections<N, V> of() { // We store predecessors and successors in the same map, so double the initial capacity. int initialCapacity = INNER_CAPACITY * 2; return new DirectedGraphConnections<>( new HashMap<N, Object>(initialCapacity, INNER_LOAD_FACTOR), 0, 0); }
private GraphConnections<N, V> newConnections() { return isDirected() ? DirectedGraphConnections.<N, V>of() : UndirectedGraphConnections.<N, V>of(); } }
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) { Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS); return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), edgeValueFn)); }
static <N, V> DirectedGraphConnections<N, V> of() { // We store predecessors and successors in the same map, so double the initial capacity. int initialCapacity = INNER_CAPACITY * 2; return new DirectedGraphConnections<>( new HashMap<N, Object>(initialCapacity, INNER_LOAD_FACTOR), 0, 0); }
private GraphConnections<N, V> newConnections() { return isDirected() ? DirectedGraphConnections.<N, V>of() : UndirectedGraphConnections.<N, V>of(); } }
private static <N, V> GraphConnections<N, V> connectionsOf( final ValueGraph<N, V> graph, final N node) { Function<N, V> successorNodeToValueFn = new Function<N, V>() { @Override public V apply(N successorNode) { return graph.edgeValueOrDefault(node, successorNode, null); } }; return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), successorNodeToValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), successorNodeToValueFn)); } }
static <N, V> DirectedGraphConnections<N, V> ofImmutable( Set<N> predecessors, Map<N, V> successorValues) { Map<N, Object> adjacentNodeValues = new HashMap<>(); adjacentNodeValues.putAll(successorValues); for (N predecessor : predecessors) { Object value = adjacentNodeValues.put(predecessor, PRED); if (value != null) { adjacentNodeValues.put(predecessor, new PredAndSucc(value)); } } return new DirectedGraphConnections<>( ImmutableMap.copyOf(adjacentNodeValues), predecessors.size(), successorValues.size()); }
private GraphConnections<N, V> newConnections() { return isDirected() ? DirectedGraphConnections.<N, V>of() : UndirectedGraphConnections.<N, V>of(); } }
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) { Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS); return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), edgeValueFn)); }
static <N, V> DirectedGraphConnections<N, V> ofImmutable( Set<N> predecessors, Map<N, V> successorValues) { Map<N, Object> adjacentNodeValues = new HashMap<>(); adjacentNodeValues.putAll(successorValues); for (N predecessor : predecessors) { Object value = adjacentNodeValues.put(predecessor, PRED); if (value != null) { adjacentNodeValues.put(predecessor, new PredAndSucc(value)); } } return new DirectedGraphConnections<>( ImmutableMap.copyOf(adjacentNodeValues), predecessors.size(), successorValues.size()); }
private static <N> GraphConnections<N, Presence> connectionsOf(Graph<N> graph, N node) { Function<Object, Presence> edgeValueFn = Functions.constant(Presence.EDGE_EXISTS); return graph.isDirected() ? DirectedGraphConnections.ofImmutable( graph.predecessors(node), Maps.asMap(graph.successors(node), edgeValueFn)) : UndirectedGraphConnections.ofImmutable( Maps.asMap(graph.adjacentNodes(node), edgeValueFn)); }
static <N, V> DirectedGraphConnections<N, V> of() { // We store predecessors and successors in the same map, so double the initial capacity. int initialCapacity = INNER_CAPACITY * 2; return new DirectedGraphConnections<>( new HashMap<N, Object>(initialCapacity, INNER_LOAD_FACTOR), 0, 0); }