Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
3eb532e9
Commit
3eb532e9
authored
Aug 02, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/modbtree: Implement __contains__ operation.
parent
8766bc02
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
0 deletions
+25
-0
extmod/modbtree.c
extmod/modbtree.c
+20
-0
tests/extmod/btree1.py
tests/extmod/btree1.py
+3
-0
tests/extmod/btree1.py.exp
tests/extmod/btree1.py.exp
+2
-0
No files found.
extmod/modbtree.c
View file @
3eb532e9
...
...
@@ -31,6 +31,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/runtime0.h"
#include "py/stream.h"
#if MICROPY_PY_BTREE
...
...
@@ -292,6 +293,24 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
}
}
STATIC
mp_obj_t
btree_binary_op
(
mp_uint_t
op
,
mp_obj_t
lhs_in
,
mp_obj_t
rhs_in
)
{
mp_obj_btree_t
*
self
=
MP_OBJ_TO_PTR
(
lhs_in
);
switch
(
op
)
{
case
MP_BINARY_OP_IN
:
{
mp_uint_t
v
;
DBT
key
,
val
;
key
.
data
=
(
void
*
)
mp_obj_str_get_data
(
rhs_in
,
&
v
);
key
.
size
=
v
;
int
res
=
__bt_get
(
self
->
db
,
&
key
,
&
val
,
0
);
CHECK_ERROR
(
res
);
return
mp_obj_new_bool
(
res
!=
RET_SPECIAL
);
}
default:
// op not supported
return
MP_OBJ_NULL
;
}
}
STATIC
const
mp_rom_map_elem_t
btree_locals_dict_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR_close
),
MP_ROM_PTR
(
&
btree_close_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_get
),
MP_ROM_PTR
(
&
btree_get_obj
)
},
...
...
@@ -311,6 +330,7 @@ STATIC const mp_obj_type_t btree_type = {
.
print
=
btree_print
,
.
getiter
=
btree_getiter
,
.
iternext
=
btree_iternext
,
.
binary_op
=
btree_binary_op
,
.
subscr
=
btree_subscr
,
.
locals_dict
=
(
void
*
)
&
btree_locals_dict
,
};
...
...
tests/extmod/btree1.py
View file @
3eb532e9
...
...
@@ -62,5 +62,8 @@ print(list(db.values()))
for
k
in
db
:
print
(
k
)
print
(
"foo1"
,
"foo1"
in
db
)
print
(
"foo2"
,
"foo2"
in
db
)
db
.
close
()
f
.
close
()
tests/extmod/btree1.py.exp
View file @
3eb532e9
...
...
@@ -30,3 +30,5 @@ KeyError
b'bar1'
b'foo1'
b'foo3'
foo1 True
foo2 False
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