Skip to content

Conversation

@viciscat
Copy link
Contributor

@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

drv/Map.drv Outdated
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are quite right, let me do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would using contains instead of the return value of #put be better? For the edge case where the previous value is null

@vigna vigna merged commit ea8b792 into vigna:master Jun 21, 2025
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

3 participants