Yet another ES6 Map/Set implementation which avoids linear search when possible
Why reinvent the wheel?
Because the current implementations suck. They are all O(n) FOR ALL TYPES OF KEYS. We can do better than that!
So linear-searching objects are necessary but that restriction does not apply to primitives. This implementation uses hash for keys of primitive types so it is O(1) unless
typeof(key) === 'object' (and
'function' to be more exact).
The graph below is the average time taken to insert one element where x axis is the size of map and the y axis is time taken in ms. See how bad O(n) can be!