@rimbu/graph
Version:
Immutable Graph data structures for TypeScript
74 lines • 3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphContext = void 0;
var stream_1 = require("@rimbu/stream");
var custom_1 = require("@rimbu/stream/custom");
var custom_2 = require("@rimbu/graph/custom");
var GraphContext = /** @class */ (function () {
function GraphContext(isDirected, typeTag, linkMapContext, linkConnectionsContext) {
var _this = this;
this.isDirected = isDirected;
this.typeTag = typeTag;
this.linkMapContext = linkMapContext;
this.linkConnectionsContext = linkConnectionsContext;
this.empty = function () {
return _this._empty;
};
this.from = function () {
var sources = [];
for (var _i = 0; _i < arguments.length; _i++) {
sources[_i] = arguments[_i];
}
var builder = _this.builder();
var i = -1;
var length = sources.length;
while (++i < length) {
var source = sources[i];
if ((0, custom_1.isEmptyStreamSourceInstance)(source))
continue;
if (builder.isEmpty &&
_this.isNonEmptyInstance(source) &&
source.context === _this) {
if (i === length - 1)
return source;
builder = source.toBuilder();
continue;
}
builder.addGraphElements(source);
}
return builder.build();
};
// prettier-ignore
this.of = function () {
var values = [];
for (var _i = 0; _i < arguments.length; _i++) {
values[_i] = arguments[_i];
}
return _this.from(values).assumeNonEmpty();
};
this.builder = function () {
return new custom_2.GraphBuilder(_this.isDirected, _this);
};
this.reducer = function (source) {
return stream_1.Reducer.create(function () {
return undefined === source ? _this.builder() : _this.from(source).toBuilder();
}, function (builder, entry) {
builder.addGraphElement(entry);
return builder;
}, function (builder) { return builder.build(); });
};
this._empty = Object.freeze(new custom_2.GraphEmpty(isDirected, this));
}
GraphContext.prototype.isNonEmptyInstance = function (source) {
return source instanceof custom_2.GraphNonEmpty;
};
GraphContext.prototype.createBuilder = function (source) {
return new custom_2.GraphBuilder(this.isDirected, this, source);
};
GraphContext.prototype.createNonEmpty = function (linkMap, connectionSize) {
return new custom_2.GraphNonEmpty(this.isDirected, this, linkMap, connectionSize);
};
return GraphContext;
}());
exports.GraphContext = GraphContext;
//# sourceMappingURL=context.cjs.map