Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have a really huge object, you could use a nice <a href="https://github.com/Benvie/WeakMap" rel="nofollow">weakmap implementation</a> <em>with the complexity of O(1)</em> to store keys per single object. Therefor you have to implement your hash collection, so when setting a key-value pair, you also store the key in the weakmap. I made also some bench. comparison of this custom HashMap vs RawObject search - <a href="http://jsperf.com/store-keys-in-weakmap-vs-continues-search" rel="nofollow">jsperf</a></p> <pre><code>function HashMap() { this.__map = new WeakMap; this.__hash = {}; } HashMap.prototype = { set: function(key, value){ this.unset(key); if (value == null) return; this.__hash[key] = value; var keys = this.__map.get(value); if (keys == null) this.__map.set(value, keys = []); keys.push(key); }, unset: function(key){ var value = this.__hash[key]; if (value) { var keys = this.__map.get(value), index = keys.indexOf(key); keys.splice(index, 1); } this.__hash[key] = void 0; }, get: function(key){ return this.__hash[key]; }, getKeys: function(value){ return this.__map.get(value); } }; </code></pre> <p>WeakMap uses <code>Object.defineProperty</code> method in its core. For this reason there are some limitations:</p> <ul> <li>browsers: IE9+</li> <li>Objects as Values in above HashMap example, because they are used as Keys in WeakMap Collection</li> </ul> <p>But this approach makes a huge performance boost, as there is no need to iterate over the object, to look for a specific value. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload