internalMakeMultimap = mapConstructor => {
  // eslint-disable-next-line new-cap
  const map = new mapConstructor();
  return {
    add: (key, value) => {
      let set = map.get(key);
      if (set === undefined) {
        set = new Set();
        map.set(key, set);
      }
      set.add(value);
    },

    delete: (key, value) => {
      const set = map.get(key);
      if (set !== undefined) {
        const result = set.delete(value);
        if (set.size === 0) {
          map.delete(key);
        }
        return result;
      }
      return false;
    },

    deleteAll: key => map.delete(key),

    get: key => map.get(key)?.keys().next().value,

    getAllFor: key => Array.from(map.get(key) ?? []),

    has: key => map.has(key),
  };
}
@param {new () => (Map | WeakMap)} mapConstructor
@returns {Multimap<any, any>}