|
60 | 60 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.GetItemNodeGen;
|
61 | 61 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.InitNodeGen;
|
62 | 62 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.KeysEqualsNodeGen;
|
| 63 | +import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.KeysIsSubsetNodeGen; |
63 | 64 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.SetItemNodeGen;
|
64 | 65 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.UnionNodeGen;
|
65 | 66 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
@@ -1386,6 +1387,48 @@ public static ExclusiveOrNode create() {
|
1386 | 1387 | }
|
1387 | 1388 | }
|
1388 | 1389 |
|
| 1390 | + public abstract static class KeysIsSubsetNode extends DictStorageBaseNode { |
| 1391 | + |
| 1392 | + public abstract boolean execute(HashingStorage left, HashingStorage right); |
| 1393 | + |
| 1394 | + @Specialization |
| 1395 | + public boolean isSubset(HashingStorage left, HashingStorage right, |
| 1396 | + @Cached("create()") ContainsKeyNode containsKeyNode, |
| 1397 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 1398 | + if (sizeProfile.profile(left.length() > right.length())) { |
| 1399 | + return false; |
| 1400 | + } |
| 1401 | + |
| 1402 | + for (Object leftKey : left.keys()) { |
| 1403 | + if (!containsKeyNode.execute(right, leftKey)) { |
| 1404 | + return false; |
| 1405 | + } |
| 1406 | + } |
| 1407 | + return true; |
| 1408 | + } |
| 1409 | + |
| 1410 | + public static KeysIsSubsetNode create() { |
| 1411 | + return KeysIsSubsetNodeGen.create(); |
| 1412 | + } |
| 1413 | + } |
| 1414 | + |
| 1415 | + public static class KeysIsSupersetNode extends Node { |
| 1416 | + @Child KeysIsSubsetNode isSubsetNode; |
| 1417 | + |
| 1418 | + public boolean execute(HashingStorage left, HashingStorage right) { |
| 1419 | + if (isSubsetNode == null) { |
| 1420 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 1421 | + isSubsetNode = insert(KeysIsSubsetNode.create()); |
| 1422 | + } |
| 1423 | + |
| 1424 | + return isSubsetNode.execute(right, left); |
| 1425 | + } |
| 1426 | + |
| 1427 | + public static KeysIsSupersetNode create() { |
| 1428 | + return new KeysIsSupersetNode(); |
| 1429 | + } |
| 1430 | + } |
| 1431 | + |
1389 | 1432 | public abstract static class DiffNode extends DictStorageBaseNode {
|
1390 | 1433 |
|
1391 | 1434 | public abstract HashingStorage execute(HashingStorage left, HashingStorage right);
|
|
0 commit comments