@rimbu/graph
Version:
Immutable Graph data structures for TypeScript
68 lines • 2.62 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphEmpty = void 0;
var tslib_1 = require("tslib");
var stream_1 = require("@rimbu/stream");
var index_cjs_1 = require("../../common/index.cjs");
var GraphEmpty = /** @class */ (function (_super) {
tslib_1.__extends(GraphEmpty, _super);
function GraphEmpty(isDirected, context) {
var _this = _super.call(this) || this;
_this.isDirected = isDirected;
_this.context = context;
return _this;
}
Object.defineProperty(GraphEmpty.prototype, "linkMap", {
get: function () {
return this.context.linkMapContext.empty();
},
enumerable: false,
configurable: true
});
GraphEmpty.prototype.getConnectionsFrom = function () {
return this.context.linkConnectionsContext.empty();
};
GraphEmpty.prototype.addNode = function (node) {
return this.context.createNonEmpty(this.linkMap.context.of([
node,
this.context.linkConnectionsContext.empty(),
]), 0);
};
GraphEmpty.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);
};
GraphEmpty.prototype.connect = function (node1, node2) {
var linkMap = this.context.linkMapContext.of([
node1,
this.context.linkConnectionsContext.of(node2),
]);
if (node1 === node2)
return this.context.createNonEmpty(linkMap, 1);
var linkConnections = this.isDirected
? this.context.linkConnectionsContext.empty()
: this.context.linkConnectionsContext.of(node1);
return this.context.createNonEmpty(linkMap.set(node2, linkConnections), 1);
};
GraphEmpty.prototype.connectAll = function (links) {
return this.context.from(links);
};
GraphEmpty.prototype.toString = function () {
return "".concat(this.context.typeTag, "()");
};
GraphEmpty.prototype.toJSON = function () {
return {
dataType: this.context.typeTag,
value: [],
};
};
GraphEmpty.prototype.toBuilder = function () {
return this.context.builder();
};
return GraphEmpty;
}(index_cjs_1.GraphEmptyBase));
exports.GraphEmpty = GraphEmpty;
//# sourceMappingURL=empty.cjs.map