Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -98,6 +98,7 @@ public void economicMapStorageSet() {

dict.setItem(ts("key1"), 42);
assertEquals(2, length(dict));
assertTrue(dict.getDictStorage() instanceof EconomicMapStorage);

assertEquals(42, dict.getItem(ts("key1")));
}
Expand All @@ -113,9 +114,20 @@ public void economicMapStorageDel() {

delItem(dict, ts("key2"));
assertEquals(2, length(dict));
assertTrue(dict.getDictStorage() instanceof EconomicMapStorage);

assertEquals(42, dict.getItem(ts("key1")));

assertNull(dict.getItem(ts("key2")));
}

@Test
public void economicMapStorageEightEntries() {
PDict dict = PFactory.createDict(PythonLanguage.get(null));
for (int i = 0; i < 8; i++) {
dict.setItem(i, i);
}
assertTrue(dict.getDictStorage() instanceof EconomicMapStorage);
assertEquals(8, length(dict));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -173,7 +173,7 @@ public void testLongHashMapStressTest() {
// Basic tests of other methods
Object[] oldKeys = keysToArray(map);

ObjectHashMap copy = map.copy();
ObjectHashMap copy = copyMap(map);
assertEquals(map.size(), copy.size());
for (Object key : oldKeys) {
assertEquals(key.toString(), //
Expand Down Expand Up @@ -315,7 +315,7 @@ static <T> void assertEqual(String message, LinkedHashMap<T, Object> expected, O
Collections.reverse(keysValuesReversed);
assertArrayEquals(message, keysValuesReversed.toArray(), reverseKeysToArray(actual));

EconomicMapStorage storage = new EconomicMapStorage(actual, false);
EconomicMapStorage storage = toEconomicMapStorage(actual);
int[] size = new int[]{0};
HashingStorageForEach.executeUncached(storage, new HashingStorageForEachCallback<>() {
@Override
Expand All @@ -330,12 +330,12 @@ public Object execute(Frame frame, Node inliningTarget, HashingStorage s, Hashin
}

private static Object[] keysToArray(ObjectHashMap m) {
EconomicMapStorage s = new EconomicMapStorage(m, false);
EconomicMapStorage s = toEconomicMapStorage(m);
return iteratorToArray(s, HashingStorageGetIterator.executeUncached(s));
}

private static Object[] reverseKeysToArray(ObjectHashMap m) {
EconomicMapStorage s = new EconomicMapStorage(m, false);
EconomicMapStorage s = toEconomicMapStorage(m);
return iteratorToArray(s, HashingStorageGetReverseIterator.executeUncached(s));
}

Expand All @@ -349,6 +349,24 @@ private static Object[] iteratorToArray(HashingStorage s, HashingStorageIterator

private static int valueCounter = 0;

private static ObjectHashMap copyMap(ObjectHashMap original) {
EconomicMapStorage copy = EconomicMapStorage.create(original.size());
MapCursor cursor = original.getEntries();
while (cursor.advance()) {
put(copy, cursor.getKey().getValue(), cursor.getKey().getPythonHash(), cursor.getValue());
}
return copy;
}

private static EconomicMapStorage toEconomicMapStorage(ObjectHashMap map) {
EconomicMapStorage storage = EconomicMapStorage.create(map.size());
MapCursor cursor = map.getEntries();
while (cursor.advance()) {
put(storage, cursor.getKey().getValue(), cursor.getKey().getPythonHash(), cursor.getValue());
}
return storage;
}

public static Object newValue() {
return "Val: " + (valueCounter++);
}
Expand Down
Loading
Loading