Home > OS >  What hash functions does Typescript Object/Map/Set use to avoid collision?
What hash functions does Typescript Object/Map/Set use to avoid collision?

Time:10-31

I recently learned about hash table implementation and I am really interested in how Typescript implements it. I found that differnt languages might use different implementations for hashing. Does Typescript use methods like quadratic probing, double hashing, or seperate chaining?

I tried to search about implementations used by Javascript/Typescript but could not find the answer I want.

CodePudding user response:

JS/TS is generally running on Chromium JS engine calledV8

Here's an ansver that answers your question

es6 Map and Set complexity, v8 implementation

Is it a fair assumption that in v8 implementation retrieval / lookup is O(1)?

Yes. V8 uses a variant of hash tables that generally have O(1) complexity for these operations.

For details, you might want to have a look at https://codereview.chromium.org/220293002/ where OrderedHashTable is implemented based on https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables.

  • Related