MCPcopy Create free account
hub / github.com/denoland/std / deleteEntry

Method deleteEntry

data_structures/unstable_multimap.ts:317–336  ·  view source on GitHub ↗

* Removes the first occurrence of the `[key, value]` entry from the map. * If the key's list becomes empty, the key is also removed. * * @experimental **UNSTABLE**: New API, yet to be vetted. * * @param key The key to look up. * @param value The value to remove. * @returns `true

(key: K, value: V)

Source from the content-addressed store, hash-verified

315 * ```
316 */
317 deleteEntry(key: K, value: V): boolean {
318 const list = this.#map.get(key);
319 if (!list) return false;
320 // SameValueZero, matching `hasEntry()` / `Map` / `Set` semantics so that
321 // `NaN` values can be removed. `Array.prototype.indexOf` uses strict
322 // equality and would never match `NaN`.
323 let index = -1;
324 for (let i = 0; i < list.length; i++) {
325 const v = list[i]!;
326 if (v === value || (v !== v && value !== value)) {
327 index = i;
328 break;
329 }
330 }
331 if (index === -1) return false;
332 list.splice(index, 1);
333 this.#valueCount--;
334 if (list.length === 0) this.#map.delete(key);
335 return true;
336 }
337
338 /**
339 * Removes all entries.

Callers 1

Calls 2

getMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected