jhuckaby / megahash

A super-fast C++ hash table with Node.js wrapper, tested up to 1 billion keys.
Other
411 stars 29 forks source link

ES6 Map compatibility #12

Open commenthol opened 2 years ago

commenthol commented 2 years ago

@jhuckaby Would you accept a PR which makes the megahash interface compatible with ES6 Map? If so, what would be your preferred option? E.g. Using class inheritance like:

const MegaHash = require('./main.js')

class Map extends MegaHash {
  get size () {
    return this.length()
  }

  * keys () {
    let key
    while (1) {
      key = this.nextKey(key)
      if (key === undefined) break
      yield key
    }
    return key
  }

//...
}

module.exports = Map

or adding the prototypes in main.js?

jhuckaby commented 2 years ago

Hello! Yes, that would be awesome. I would prefer that it be a separate subclass (possibly called MegaMap?) which inherits from MegaHash.