Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ofEntries static method to Map interfaces #330

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

viciscat
Copy link

@viciscat viciscat commented Aug 13, 2024

Pretty simple PR, I think
Things to note:

  • Java doc is a bit quaint because I thought it was useless to copy paste the original methods
  • an entry(key, value) static method was also added to make it easier to use, just like java.util.Map
  • I did not include Int2IntMapTest because I would have put the same things I did in Object2ObjectMapTest
  • More tests could probably be added but I have no idea what they could be

Close #329

if (entries.length <= 8) {
return MAPS.unmodifiable(new ARRAY_MAP KEY_VALUE_GENERIC_DIAMOND(keys, vals, entries.length));
} else {
return MAPS.unmodifiable(new OPEN_HASH_MAP KEY_VALUE_GENERIC_DIAMOND(keys, vals, 0.75f));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this creates the keys / values array unnecessarily. I think the code should be like

if (number of entries is small)
  create keys and vals as above (with duplicate checking)
  return array map with keys and vales
else
  create appropriately sized hash map
  for each entry:
    if map.put(entry.key, entry.value) != null then throw exception
  return hash map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Map.ofEntries equivalent for fastutil maps
2 participants