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
c577cf0c
Commit
c577cf0c
authored
Jul 24, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set.__contains__
parent
224e1ea7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
src/runtime/set.cpp
src/runtime/set.cpp
+9
-1
test/tests/set.py
test/tests/set.py
+4
-0
No files found.
src/runtime/set.cpp
View file @
c577cf0c
...
...
@@ -205,11 +205,16 @@ Box* setLen(BoxedSet* self) {
}
Box
*
setAdd
(
BoxedSet
*
self
,
Box
*
v
)
{
assert
(
self
->
cls
==
set_cls
||
self
->
cls
==
frozenset_cls
);
assert
(
self
->
cls
==
set_cls
);
self
->
s
.
insert
(
v
);
return
None
;
}
Box
*
setContains
(
BoxedSet
*
self
,
Box
*
v
)
{
assert
(
self
->
cls
==
set_cls
||
self
->
cls
==
frozenset_cls
);
return
boxBool
(
self
->
s
.
count
(
v
)
!=
0
);
}
}
// namespace set
...
...
@@ -275,6 +280,9 @@ void setupSet() {
set_cls
->
giveAttr
(
"__len__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setLen
,
BOXED_INT
,
1
)));
frozenset_cls
->
giveAttr
(
"__len__"
,
set_cls
->
getattr
(
"__len__"
));
set_cls
->
giveAttr
(
"__contains__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setContains
,
BOXED_BOOL
,
2
)));
frozenset_cls
->
giveAttr
(
"__contains__"
,
set_cls
->
getattr
(
"__contains__"
));
set_cls
->
giveAttr
(
"add"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
setAdd
,
NONE
,
2
)));
set_cls
->
freeze
();
...
...
test/tests/set.py
View file @
c577cf0c
...
...
@@ -48,3 +48,7 @@ print frozenset() | frozenset()
print
set
()
|
frozenset
()
print
frozenset
()
|
set
()
print
set
()
|
set
()
for
i
in
xrange
(
8
):
print
i
,
i
in
set
(
range
(
2
,
5
))
print
i
,
i
in
frozenset
(
range
(
2
,
5
))
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