UNPKG

graph-builder

Version:

A graph builder library for modeling abstract graph structures.

106 lines 3.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const AbstractBaseGraph_1 = require("./AbstractBaseGraph"); const AbstractGraph_1 = require("./AbstractGraph"); const Sets_1 = require("../collect/Sets"); const Maps_1 = require("../collect/Maps"); /* * 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 */ /** * This class provides a skeletal implementation of {@link ValueGraph}. It is recommended to extend * this class rather than implement {@link ValueGraph} directly. * * <p>The methods implemented in this class should not be overridden unless the subclass admits a * more efficient implementation. */ class AbstractValueGraph extends AbstractBaseGraph_1.AbstractBaseGraph { asGraph() { const that = this; class AsGraph extends AbstractGraph_1.AbstractGraph { nodes() { return that.nodes(); } edges() { return that.edges(); } isDirected() { return that.isDirected(); } allowsSelfLoops() { return that.allowsSelfLoops(); } nodeOrder() { return that.nodeOrder(); } adjacentNodes(node) { return that.adjacentNodes(node); } predecessors(node) { return that.predecessors(node); } successors(node) { return that.successors(node); } degree(node) { return that.degree(node); } inDegree(node) { return that.inDegree(node); } outDegree(node) { return that.outDegree(node); } } ; return new AsGraph(); } edgeValue(nodeU, nodeV) { return this.edgeValueOrDefault(nodeU, nodeV, undefined); } edgeValueConnectingEndpoints(endpoints) { return this.edgeValueConnectingEndpointsOrDefault(endpoints, undefined); } equals(obj) { return this.isDirected() == obj.isDirected() && Sets_1.Sets.equals(this.nodes(), obj.nodes()) && Maps_1.Maps.equals(AbstractValueGraph.edgeValueMap(this), AbstractValueGraph.edgeValueMap(obj)); } /** Returns a string representation of this graph. */ toString() { return "isDirected: " + this.isDirected() + ", allowsSelfLoops: " + this.allowsSelfLoops() + ", nodes: " + this.nodes() + ", edges: " + AbstractValueGraph.edgeValueMap(this); } static edgeValueMap(graph) { const edgeToValueFn = (edge) => { const v = graph.edgeValue(edge.nodeU, edge.nodeV); if (v === undefined) { throw new Error('No edge connecting nodes'); } return v; }; return Maps_1.Maps.asMap(graph.edges(), edgeToValueFn); } } exports.AbstractValueGraph = AbstractValueGraph; //# sourceMappingURL=AbstractValueGraph.js.map