Skip to content

Commit

Permalink
Count inserted items from both sets
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Aug 13, 2024
1 parent 5a55984 commit 5575d88
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ EnsoHashMap doEnsoHashMaps(
@Cached EqualsNode equalsNode) {
assert maxItems > 0;
var selfSize = self.getHashSize();
if (selfSize >= maxItems) {
return self;
}
var otherSize = other.getHashSize();
if (otherSize == 0) {
return self;
Expand All @@ -53,13 +56,17 @@ EnsoHashMap doEnsoHashMaps(

var selfMapBuilder = self.getMapBuilder(frame, true, hashCodeNode, equalsNode);
var selfEntriesIt = selfMapBuilder.getEntriesIterator(selfMapBuilder.generation());
var itemsInserted = 0;
while (selfEntriesIt.hasNext()) {
if (itemsInserted >= maxItems) {
break;
}
var selfEntry = selfEntriesIt.next();
mapBuilder.put(frame, selfEntry.key(), selfEntry.value(), hashCodeNode, equalsNode);
itemsInserted++;
}
var otherMapBuilder = other.getMapBuilder(frame, true, hashCodeNode, equalsNode);
var otherEntriesIt = otherMapBuilder.getEntriesIterator(otherMapBuilder.generation());
var itemsInserted = 0;
while (otherEntriesIt.hasNext()) {
if (itemsInserted >= maxItems) {
break;
Expand Down

0 comments on commit 5575d88

Please sign in to comment.