Files
rss-nostr-lambda/node_modules/tstl/base/container/SetContainer.js
T

151 lines
5.1 KiB
JavaScript

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetContainer = void 0;
var Container_1 = require("./Container");
var NativeArrayIterator_1 = require("../../internal/iterator/disposable/NativeArrayIterator");
/**
* Basic set container.
*
* @template Key Key type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link SetContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
var SetContainer = /** @class */ (function (_super) {
__extends(SetContainer, _super);
/* ---------------------------------------------------------
CONSTURCTORS
--------------------------------------------------------- */
/**
* Default Constructor.
*/
function SetContainer(factory) {
var _this = _super.call(this) || this;
_this.data_ = factory(_this);
return _this;
}
/**
* @inheritDoc
*/
SetContainer.prototype.assign = function (first, last) {
// INSERT
this.clear();
this.insert(first, last);
};
/**
* @inheritDoc
*/
SetContainer.prototype.clear = function () {
// TO BE ABSTRACT
this.data_.clear();
};
/**
* @inheritDoc
*/
SetContainer.prototype.begin = function () {
return this.data_.begin();
};
/**
* @inheritDoc
*/
SetContainer.prototype.end = function () {
return this.data_.end();
};
/* ---------------------------------------------------------
ELEMENTS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
SetContainer.prototype.has = function (key) {
return !this.find(key).equals(this.end());
};
/**
* @inheritDoc
*/
SetContainer.prototype.size = function () {
return this.data_.size();
};
/* =========================================================
ELEMENTS I/O
- INSERT
- ERASE
- UTILITY
- POST-PROCESS
============================================================
INSERT
--------------------------------------------------------- */
/**
* @inheritDoc
*/
SetContainer.prototype.push = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
if (items.length === 0)
return this.size();
// INSERT BY RANGE
var first = new NativeArrayIterator_1.NativeArrayIterator(items, 0);
var last = new NativeArrayIterator_1.NativeArrayIterator(items, items.length);
this._Insert_by_range(first, last);
// RETURN SIZE
return this.size();
};
SetContainer.prototype.insert = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 1)
return this._Insert_by_key(args[0]);
else if (args[0].next instanceof Function &&
args[1].next instanceof Function)
return this._Insert_by_range(args[0], args[1]);
else
return this._Insert_by_hint(args[0], args[1]);
};
SetContainer.prototype.erase = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 1 &&
!(args[0] instanceof this.end().constructor &&
args[0].source() === this))
return this._Erase_by_val(args[0]);
else if (args.length === 1)
return this._Erase_by_range(args[0]);
else
return this._Erase_by_range(args[0], args[1]);
};
SetContainer.prototype._Erase_by_range = function (first, last) {
if (last === void 0) { last = first.next(); }
// ERASE
var it = this.data_.erase(first, last);
// POST-PROCESS
this._Handle_erase(first, last);
return it;
};
return SetContainer;
}(Container_1.Container));
exports.SetContainer = SetContainer;
//# sourceMappingURL=SetContainer.js.map