MCPcopy Index your code
hub / github.com/immutable-js/immutable-js / _positionOf

Method _positionOf

src/Map.js:430–458  ·  view source on GitHub ↗
(key, buildIndex)

Source from the content-addressed store, hash-verified

428 // transient inserts, where the node is reused so the O(n) build amortizes).
429 // Persistent inserts already pay an O(n) copy, so a throwaway index is skipped.
430 _positionOf(key, buildIndex) {
431 const entries = this.entries;
432 let index = this._index;
433 if (
434 index === undefined &&
435 buildIndex &&
436 entries.length >= MIN_HASH_COLLISION_INDEX_SIZE
437 ) {
438 index = this._buildIndex();
439 }
440 if (index !== undefined) {
441 const positions = index[hashCollisionKey(key)];
442 if (positions !== undefined) {
443 for (let jj = 0; jj < positions.length; jj++) {
444 const ii = positions[jj];
445 if (is(key, entries[ii][0])) {
446 return ii;
447 }
448 }
449 }
450 return -1;
451 }
452 for (let ii = 0, len = entries.length; ii < len; ii++) {
453 if (is(key, entries[ii][0])) {
454 return ii;
455 }
456 }
457 return -1;
458 }
459
460 // Builds and memoizes the secondary index. A plain object, not `Map` — which
461 // in this module resolves to the *Immutable* Map, not the native one.

Callers 2

getMethod · 0.95
updateMethod · 0.95

Calls 3

_buildIndexMethod · 0.95
hashCollisionKeyFunction · 0.90
isFunction · 0.90

Tested by

no test coverage detected