UNPKG

typescript-dotnet-core

Version:

A the core classes and utilities of a JavaScript-Friendly .NET Based TypeScript Library.

7 lines (6 loc) 2.62 kB
"use strict"; /*! * @author electricessence / https://github.com/electricessence/ * Licensing: MIT https://github.com/electricessence/TypeScript.NET-Core/blob/master/LICENSE.md */Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),Types_1=require("../Types"),SetBase_1=require("./SetBase"),ArgumentNullException_1=require("../Exceptions/ArgumentNullException"),Compare_1=require("../Compare"),LinkedNodeList_1=require("./LinkedNodeList"),ObjectPool_1=require("../Disposable/ObjectPool"),VOID0=void 0,bucketPool=ObjectPool_1.default.createAutoRecycled(function(){return new LinkedNodeList_1.default},100),EMPTY="";function selfHash(e){return e+EMPTY}var HashSet=function(i){function t(e,t,r){void 0===t&&(t=selfHash),void 0===r&&(r=Compare_1.areEqual);var o=i.call(this)||this;if(Types_1.default.isFunction(e))o._hashGenerator=e,o._comparer=t||r;else{if(!t)throw new ArgumentNullException_1.default("keyGenerator");o._hashGenerator=t,o._comparer=r,o._importEntries(e)}if(!o._comparer)throw new ArgumentNullException_1.default("comparer");return o}return tslib_1.__extends(t,i),t.prototype.newUsing=function(e){return new t(e,this._hashGenerator,this._comparer)},t.prototype._addInternal=function(t){var e=this,r=typeof t,o=e._hashGenerator(t),i=e._registry,n=i&&i[r],a=n&&n[o],u=this._comparer;if(a&&a.find(function(e){return u(e.value.value,t)}))return!1;i||(e._registry=i={}),n||(i[r]=n={}),a||(n[o]=a=bucketPool.take());var s={value:t};return e._getSet().addNode(s),a.addNode({value:s}),!0},t.prototype._clearInternal=function(){return wipe(this._registry,2),i.prototype._clearInternal.call(this)},t.prototype._onDispose=function(){i.prototype._onDispose.call(this),this._clearInternal(),this._registry=null,this._hashGenerator=VOID0},t.prototype._getNode=function(t){var e=this._registry,r=e&&e[typeof t],o=r&&r[this._hashGenerator(t)];if(!o)return VOID0;var i=this._comparer,n=o.find(function(e){return i(e.value.value,t)});return n&&n.value||void 0},t.prototype._removeInternal=function(t,e){if(void 0===e&&(e=1/0),0===e)return 0;var r=this._registry,o=r&&r[typeof t],i=o&&o[t],n=this._comparer,a=i&&i.find(function(e){return n(e.value.value,t)});if(a){var u=a.value;i.removeNode(a),i.first||(delete o[t],bucketPool.give(i));var s=this._set;if(s&&s.removeNode(u))return 1}return 0},t}(SetBase_1.default);function wipe(e,t){if(void 0===t&&(t=1),e&&t)for(var r=0,o=Object.keys(e);r<o.length;r++){var i=o[r],n=e[i];delete e[i],n instanceof LinkedNodeList_1.default?bucketPool.give(n):wipe(n,t-1)}}exports.HashSet=HashSet,exports.default=HashSet; //# sourceMappingURL=HashSet.js.map