UNPKG

graph-builder

Version:

A graph builder library for modeling abstract graph structures.

72 lines 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ImmutableMap_1 = require("../collect/ImmutableMap"); const ImmutableSet_1 = require("../collect/ImmutableSet"); /* * Copyright (C) 2016 The Guava Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Modifications (C) 2019 Ben Sorohan */ /** * An implementation of {@link GraphConnections} for undirected graphs. */ class UndirectedGraphConnections { constructor(adjacentNodeValues) { this.adjacentNodeValues = adjacentNodeValues; } static of() { return new UndirectedGraphConnections(new Map()); } static ofImmutable(adjacentNodeValues) { return new UndirectedGraphConnections(ImmutableMap_1.ImmutableMap.copyOf(adjacentNodeValues)); } adjacentNodes() { return ImmutableSet_1.ImmutableSet.fromIterable(this.adjacentNodeValues.keys()); } predecessors() { return this.adjacentNodes(); } successors() { return this.adjacentNodes(); } value(node) { const v = this.adjacentNodeValues.get(node); if (v === undefined) { throw new Error('Node not defined'); } return v; } removePredecessor(node) { this.removeSuccessor(node); } removeSuccessor(node) { const v = this.adjacentNodeValues.get(node); if (v === undefined) { throw new Error('Node not defined'); } this.adjacentNodeValues.delete(node); return v; } addPredecessor(node, value) { this.addSuccessor(node, value); } addSuccessor(node, value) { const previousValue = this.adjacentNodeValues.get(node); this.adjacentNodeValues.set(node, value); return previousValue; } } exports.UndirectedGraphConnections = UndirectedGraphConnections; //# sourceMappingURL=UndirectedGraphConnections.js.map