typescript-dotnet-amd
Version:
A JavaScript-Friendly .NET Based TypeScript Library.
7 lines • 3.21 kB
JavaScript
/*!
* @author electricessence / https://github.com/electricessence/
* Original: http://linqjs.codeplex.com/
* Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
*/
define(["require","exports","../../Compare","../../Types","../Enumeration/EnumeratorBase","../LinkedNodeList","../../Disposable/ObjectPool","./getIdentifier","./DictionaryBase","../../../extends"],function(e,t,r,n,o,i,u,s,a,l){"use strict";function c(e){return f||(f=new u.ObjectPool(20,function(){return new i.LinkedNodeList},function(e){return e.clear()})),e?void f.add(e):f.take()}Object.defineProperty(t,"__esModule",{value:!0});var f,d=l["default"],y=void 0,p=function(){function e(e,t,r,n){this.key=e,this.value=t,this.previous=r,this.next=n}return e}(),v=function(e){function t(t){var r=e.call(this)||this;return r._keyGenerator=t,r._entries=c(),r._buckets={},r}return d(t,e),t.prototype._onDispose=function(){e.prototype._onDispose.call(this);var t=this;t._entries=null,t._buckets=null,t._hashGenerator=null},t.prototype.getCount=function(){return this._entries&&this._entries.unsafeCount||0},t.prototype._getBucket=function(e,t){if(null==e||!t&&!this.getCount())return null;n.Type.isPrimitiveOrSymbol(e)||console.warn("Key type not indexable and could cause Dictionary to be extremely slow.");var r=this._buckets,o=r[e];return t&&!o&&(r[e]=o=c()),o||null},t.prototype._getBucketEntry=function(e,t,r){if(null==e||!this.getCount())return null;var n=this,o=n._keyGenerator,i=o?o(e):e;return r||(r=n._getBucket(t||s.getIdentifier(i))),r&&(o?r.find(function(e){return o(e.key)===i}):r.find(function(e){return e.key===i}))},t.prototype._getEntry=function(e){var t=this._getBucketEntry(e);return t&&t.value},t.prototype.getValue=function(e){var t=this._getEntry(e);return t?t.value:y},t.prototype._setValueInternal=function(e,t){var n=this,o=n._buckets,i=n._entries,u=n._keyGenerator?n._keyGenerator(e):e,a=s.getIdentifier(u),l=n._getBucket(a),f=l&&n._getBucketEntry(e,a,l);if(f){var d=l;if(t!==y){var v=f.value.value;return f.value.value=t,!r.areEqual(t,v)}var _=d.removeNode(f),h=i.removeNode(f.value);if(_&&!d.count&&(delete o[a],c(d),l=null),_!==h)throw"Entries and buckets are out of sync.";if(_)return!0}else if(t!==y){if(l||(l=n._getBucket(a,!0)),!l)throw new Error('"'+a.toString()+'" cannot be added to lookup table.');var k=new p(e,t);return i.addNode(k),l.addNode(new p(e,k)),!0}return!1},t.prototype._clearInternal=function(){var e=this,t=e._buckets;for(var r in t)if(t.hasOwnProperty(r)){var n=t[r];delete t[r],c(n)}return e._entries.clear()},t.prototype.getEnumerator=function(){var e=this;e.throwIfDisposed();var t,r;return new o.EnumeratorBase(function(){e.throwIfDisposed(),t=e._version,r=e._entries.first},function(n){if(r){e.throwIfDisposed(),e.assertVersion(t);var o={key:r.key,value:r.value};return r=r.next||null,n.yieldReturn(o)}return n.yieldBreak()})},t.prototype.getKeys=function(){for(var e=this,t=[],r=e._entries&&e._entries.first;r;)t.push(r.key),r=r.next;return t},t.prototype.getValues=function(){for(var e=this,t=[],r=e._entries&&e._entries.first;r;)t.push(r.value),r=r.next;return t},t}(a["default"]);t.Dictionary=v,t["default"]=v});
//# sourceMappingURL=Dictionary.js.map