@rimbu/graph
Version:
Immutable Graph data structures for TypeScript
84 lines • 3.38 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValuedGraphEmpty = void 0;
var tslib_1 = require("tslib");
var base_1 = require("@rimbu/base");
var common_1 = require("@rimbu/common");
var stream_1 = require("@rimbu/stream");
var index_cjs_1 = require("../../common/index.cjs");
var ValuedGraphEmpty = /** @class */ (function (_super) {
tslib_1.__extends(ValuedGraphEmpty, _super);
function ValuedGraphEmpty(isDirected, context) {
var _this = _super.call(this) || this;
_this.isDirected = isDirected;
_this.context = context;
return _this;
}
Object.defineProperty(ValuedGraphEmpty.prototype, "linkMap", {
get: function () {
return this.context.linkMapContext.empty();
},
enumerable: false,
configurable: true
});
ValuedGraphEmpty.prototype.getValue = function (node1, node2, otherwise) {
return (0, common_1.OptLazy)(otherwise);
};
ValuedGraphEmpty.prototype.getConnectionsFrom = function () {
return this.context.linkConnectionsContext.empty();
};
ValuedGraphEmpty.prototype.addNode = function (node) {
return this.context.createNonEmpty(this.linkMap.context.of([
node,
this.context.linkConnectionsContext.empty(),
]), 0);
};
ValuedGraphEmpty.prototype.addNodes = function (nodes) {
var emptyConnections = this.context.linkConnectionsContext.empty();
var linkMap = this.context.linkMapContext.from(stream_1.Stream.from(nodes).map(function (node) { return [node, emptyConnections]; }));
if (!linkMap.nonEmpty())
return this;
return this.context.createNonEmpty(linkMap, 0);
};
ValuedGraphEmpty.prototype.connect = function (node1, node2, value) {
var linkMap = this.context.linkMapContext.of([
node1,
this.context.linkConnectionsContext.of([node2, value]),
]);
if (node1 === node2)
return this.context.createNonEmpty(linkMap, 1);
var linkConnections = this.isDirected
? this.context.linkConnectionsContext.empty()
: this.context.linkConnectionsContext.of([node1, value]);
return this.context.createNonEmpty(linkMap.set(node2, linkConnections), 1);
};
ValuedGraphEmpty.prototype.connectAll = function (links) {
return this.context.from(links);
};
ValuedGraphEmpty.prototype.modifyAt = function (node1, node2, options) {
if (undefined === options.ifNew)
return this;
var newValue = (0, common_1.OptLazyOr)(options.ifNew, base_1.Token);
if (base_1.Token === newValue)
return this;
return this.connect(node1, node2, newValue);
};
ValuedGraphEmpty.prototype.mapValues = function () {
return this;
};
ValuedGraphEmpty.prototype.toString = function () {
return "".concat(this.context.typeTag, "()");
};
ValuedGraphEmpty.prototype.toJSON = function () {
return {
dataType: this.context.typeTag,
value: [],
};
};
ValuedGraphEmpty.prototype.toBuilder = function () {
return this.context.builder();
};
return ValuedGraphEmpty;
}(index_cjs_1.GraphEmptyBase));
exports.ValuedGraphEmpty = ValuedGraphEmpty;
//# sourceMappingURL=empty.cjs.map