Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
0adb2bf8
Commit
0adb2bf8
authored
Mar 19, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set.issubset and issuperset
parent
7b75f912
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
src/runtime/set.cpp
src/runtime/set.cpp
+26
-0
test/tests/set.py
test/tests/set.py
+5
-0
No files found.
src/runtime/set.cpp
View file @
0adb2bf8
...
...
@@ -273,6 +273,30 @@ static BoxedSet* setIntersection2(BoxedSet* self, Box* container) {
return
rtn
;
}
static
Box
*
setIssubset
(
BoxedSet
*
self
,
Box
*
container
)
{
assert
(
self
->
cls
==
set_cls
);
RELEASE_ASSERT
(
container
->
cls
==
set_cls
,
""
);
BoxedSet
*
rhs
=
static_cast
<
BoxedSet
*>
(
container
);
for
(
auto
e
:
self
->
s
)
{
if
(
rhs
->
s
.
find
(
e
)
==
rhs
->
s
.
end
())
return
False
;
}
return
True
;
}
static
Box
*
setIssuperset
(
BoxedSet
*
self
,
Box
*
container
)
{
assert
(
self
->
cls
==
set_cls
);
RELEASE_ASSERT
(
container
->
cls
==
set_cls
,
""
);
BoxedSet
*
rhs
=
static_cast
<
BoxedSet
*>
(
container
);
for
(
auto
e
:
rhs
->
s
)
{
if
(
self
->
s
.
find
(
e
)
==
self
->
s
.
end
())
return
False
;
}
return
True
;
}
Box
*
setIntersection
(
BoxedSet
*
self
,
BoxedTuple
*
args
)
{
if
(
!
isSubclass
(
self
->
cls
,
set_cls
))
raiseExcHelper
(
TypeError
,
"descriptor 'intersection' requires a 'set' object but received a '%s'"
,
...
...
@@ -406,6 +430,8 @@ void setupSet() {
set_cls
->
giveAttr
(
"union"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setUnion
,
UNKNOWN
,
1
,
0
,
true
,
false
)));
set_cls
->
giveAttr
(
"intersection"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setIntersection
,
UNKNOWN
,
1
,
0
,
true
,
false
)));
set_cls
->
giveAttr
(
"issubset"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setIssubset
,
UNKNOWN
,
2
)));
set_cls
->
giveAttr
(
"issuperset"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setIssuperset
,
UNKNOWN
,
2
)));
set_cls
->
giveAttr
(
"copy"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setCopy
,
UNKNOWN
,
1
)));
set_cls
->
giveAttr
(
"pop"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setPop
,
UNKNOWN
,
1
)));
...
...
test/tests/set.py
View file @
0adb2bf8
...
...
@@ -98,3 +98,8 @@ s.discard(1)
print
s
s
.
discard
(
1
)
print
s
s
=
set
(
range
(
5
))
for
i
in
xrange
(
10
):
s2
=
set
(
range
(
i
))
print
s
.
issubset
(
s2
),
s
.
issuperset
(
s2
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment