|
28 | 28 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__AND__;
|
29 | 29 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__CONTAINS__;
|
30 | 30 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
|
| 31 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__GE__; |
| 32 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__GT__; |
31 | 33 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
|
32 | 34 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__LEN__;
|
33 | 35 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__LE__;
|
| 36 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__LT__; |
34 | 37 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__SUB__;
|
35 | 38 |
|
36 | 39 | import java.util.List;
|
@@ -287,6 +290,115 @@ PBaseSet doIterable(PBaseSet container, HashingStorage dictStorage, Object itera
|
287 | 290 | public static BinaryUnionNode create() {
|
288 | 291 | return BinaryUnionNodeGen.create();
|
289 | 292 | }
|
| 293 | + } |
| 294 | + |
| 295 | + @Builtin(name = "issubset", fixedNumOfArguments = 2) |
| 296 | + @GenerateNodeFactory |
| 297 | + abstract static class IsSubsetNode extends PythonBinaryBuiltinNode { |
| 298 | + @Specialization |
| 299 | + boolean isSubSet(PBaseSet self, PBaseSet other, |
| 300 | + @Cached("create()") HashingStorageNodes.KeysIsSubsetNode isSubsetNode) { |
| 301 | + return isSubsetNode.execute(self.getDictStorage(), other.getDictStorage()); |
| 302 | + } |
| 303 | + |
| 304 | + @Specialization |
| 305 | + boolean isSubSet(PBaseSet self, String other, |
| 306 | + @Cached("create()") SetNodes.ConstructSetNode constructSetNode, |
| 307 | + @Cached("create()") HashingStorageNodes.KeysIsSubsetNode isSubsetNode) { |
| 308 | + PSet otherSet = constructSetNode.executeWith(other); |
| 309 | + return isSubsetNode.execute(self.getDictStorage(), otherSet.getDictStorage()); |
| 310 | + } |
| 311 | + } |
| 312 | + |
| 313 | + @Builtin(name = "issuperset", fixedNumOfArguments = 2) |
| 314 | + @GenerateNodeFactory |
| 315 | + abstract static class IsSupersetNode extends PythonBinaryBuiltinNode { |
| 316 | + @Specialization |
| 317 | + boolean isSuperSet(PBaseSet self, PBaseSet other, |
| 318 | + @Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode) { |
| 319 | + return isSupersetNode.execute(self.getDictStorage(), other.getDictStorage()); |
| 320 | + } |
| 321 | + |
| 322 | + @Specialization |
| 323 | + boolean isSuperSet(PBaseSet self, String other, |
| 324 | + @Cached("create()") SetNodes.ConstructSetNode constructSetNode, |
| 325 | + @Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode) { |
| 326 | + PSet otherSet = constructSetNode.executeWith(other); |
| 327 | + return isSupersetNode.execute(self.getDictStorage(), otherSet.getDictStorage()); |
| 328 | + } |
| 329 | + } |
| 330 | + |
| 331 | + @Builtin(name = __LE__, fixedNumOfArguments = 2) |
| 332 | + @GenerateNodeFactory |
| 333 | + abstract static class LessEqualNode extends IsSubsetNode { |
| 334 | + } |
| 335 | + |
| 336 | + @Builtin(name = __GE__, fixedNumOfArguments = 2) |
| 337 | + @GenerateNodeFactory |
| 338 | + abstract static class GreaterEqualNode extends IsSupersetNode { |
| 339 | + } |
| 340 | + |
| 341 | + @Builtin(name = __LT__, fixedNumOfArguments = 2) |
| 342 | + @GenerateNodeFactory |
| 343 | + abstract static class LessThanNode extends PythonBinaryBuiltinNode { |
| 344 | + @Child LessEqualNode lessEqualNode; |
| 345 | + |
| 346 | + private LessEqualNode getLessEqualNode() { |
| 347 | + if (lessEqualNode == null) { |
| 348 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 349 | + lessEqualNode = insert(FrozenSetBuiltinsFactory.LessEqualNodeFactory.create()); |
| 350 | + } |
| 351 | + return lessEqualNode; |
| 352 | + } |
| 353 | + |
| 354 | + @Specialization |
| 355 | + boolean isLessThan(PBaseSet self, PBaseSet other, |
| 356 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 357 | + if (sizeProfile.profile(self.size() >= other.size())) { |
| 358 | + return false; |
| 359 | + } |
| 360 | + return (Boolean) getLessEqualNode().execute(self, other); |
| 361 | + } |
| 362 | + |
| 363 | + @Specialization |
| 364 | + boolean isLessThan(PBaseSet self, String other, |
| 365 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 366 | + if (sizeProfile.profile(self.size() >= other.length())) { |
| 367 | + return false; |
| 368 | + } |
| 369 | + return (Boolean) getLessEqualNode().execute(self, other); |
| 370 | + } |
| 371 | + } |
| 372 | + |
| 373 | + @Builtin(name = __GT__, fixedNumOfArguments = 2) |
| 374 | + @GenerateNodeFactory |
| 375 | + abstract static class GreaterThanNode extends PythonBinaryBuiltinNode { |
| 376 | + @Child GreaterEqualNode greaterEqualNode; |
| 377 | + |
| 378 | + private GreaterEqualNode getGreaterEqualNode() { |
| 379 | + if (greaterEqualNode == null) { |
| 380 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 381 | + greaterEqualNode = insert(FrozenSetBuiltinsFactory.GreaterEqualNodeFactory.create()); |
| 382 | + } |
| 383 | + return greaterEqualNode; |
| 384 | + } |
| 385 | + |
| 386 | + @Specialization |
| 387 | + boolean isGreaterThan(PBaseSet self, PBaseSet other, |
| 388 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 389 | + if (sizeProfile.profile(self.size() <= other.size())) { |
| 390 | + return false; |
| 391 | + } |
| 392 | + return (Boolean) getGreaterEqualNode().execute(self, other); |
| 393 | + } |
290 | 394 |
|
| 395 | + @Specialization |
| 396 | + boolean isGreaterThan(PBaseSet self, String other, |
| 397 | + @Cached("createBinaryProfile()") ConditionProfile sizeProfile) { |
| 398 | + if (sizeProfile.profile(self.size() <= other.length())) { |
| 399 | + return false; |
| 400 | + } |
| 401 | + return (Boolean) getGreaterEqualNode().execute(self, other); |
| 402 | + } |
291 | 403 | }
|
292 | 404 | }
|
0 commit comments