multi-key-cache
Version:
A JavaScript (JS) cache that can have multiple complex values as keys
2 lines (1 loc) • 3.22 kB
JavaScript
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.multiKeyCache=t()}}(function(){var t,e,i;return function t(e,i,s){function n(o,h){if(!i[o]){if(!e[o]){var f="function"==typeof require&&require;if(!h&&f)return f(o,!0);if(r)return r(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var a=i[o]={exports:{}};e[o][0].call(a.exports,function(t){var i=e[o][1][t];return n(i?i:t)},a,a.exports,t,e,i,s)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;o<s.length;o++)n(s[o]);return n}({1:[function(t,e,i){"function"!=typeof Map||process&&process.env&&"true"===process.env.TEST_MAPORSIMILAR?e.exports=t("./similar"):e.exports=Map},{"./similar":2}],2:[function(t,e,i){function s(){return this.list=[],this.lastItem=void 0,this.size=0,this}s.prototype.get=function(t){var e;return this.lastItem&&this.lastItem.key===t?this.lastItem.val:(e=this.indexOf(t),e>=0?(this.lastItem=this.list[e],this.list[e].val):void 0)},s.prototype.set=function(t,e){var i;return this.lastItem&&this.lastItem.key===t?(this.lastItem.val=e,this):(i=this.indexOf(t),i>=0?(this.lastItem=this.list[i],this.list[i].val=e,this):(this.lastItem={key:t,val:e},this.list.push(this.lastItem),this.size++,this))},s.prototype.delete=function(t){var e;return this.lastItem&&this.lastItem.key===t&&(this.lastItem=void 0),e=this.indexOf(t),e>=0?(this.size--,this.list.splice(e,1)[0]):void 0},s.prototype.has=function(t){var e;return this.lastItem&&this.lastItem.key===t?!0:(e=this.indexOf(t),e>=0?(this.lastItem=this.list[e],!0):!1)},s.prototype.forEach=function(t,e){var i;for(i=0;i<this.size;i++)t.call(e||this,this.list[i].val,this.list[i].key,this)},s.prototype.indexOf=function(t){var e;for(e=0;e<this.size;e++)if(this.list[e].key===t)return e;return-1},e.exports=s},{}],3:[function(t,e,i){function s(){this.cache=new n,this._vAl_kEY_nAMe_no_cOLLision_="_vAl_kEY_nAMe_no_cOLLision_"}var n=t("map-or-similar");s.prototype.set=function(t,e){var i=t.length,s=this.cache,r,o;if(!i)return this;for(o=0;i>o;o++)s.has(t[o])?s=s.get(t[o]):(r=new n,s.set(t[o],r),s=r);return s.set(this._vAl_kEY_nAMe_no_cOLLision_,e),this},s.prototype.get=function(t){var e=t.length,i=this.cache,s;if(e){for(s=0;e>s;s++)if(i=i.get(t[s]),!i)return;return i.get(this._vAl_kEY_nAMe_no_cOLLision_)}},s.prototype.delete=function(t){var e=t.length,i=this.cache,s=[i],n;if(!e)return!1;for(n=0;e>n;n++)if(i=i.get(t[n]),s.push(i),!i)return!1;for(i.delete(this._vAl_kEY_nAMe_no_cOLLision_),n=e-1;n>=0&&(i=s[n].get(t[n]),!i.size);n--)s[n].delete(t[n]);return!0},s.prototype.has=function(t){var e=t.length,i=this.cache,s;if(!e)return!1;for(s=0;e>s;s++)if(i=i.get(t[s]),!i)return!1;return!0},s.prototype.values=function(){function t(s){s.forEach(function(s,n){n===e._vAl_kEY_nAMe_no_cOLLision_?i.push(s):t(s)})}var e=this,i=[];return t(this.cache),i},s.prototype.keyNodes=function(){function t(i){i.forEach(function(i,s){e.push(s),i&&i.size&&t(i)})}var e=[];return t(this.cache),e},e.exports=s},{"map-or-similar":1}]},{},[3])(3)});