Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
3eb532e9
Commit
3eb532e9
authored
8 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
extmod/modbtree: Implement __contains__ operation.
parent
8766bc02
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
extmod/modbtree.c
+20
-0
20 additions, 0 deletions
extmod/modbtree.c
tests/extmod/btree1.py
+3
-0
3 additions, 0 deletions
tests/extmod/btree1.py
tests/extmod/btree1.py.exp
+2
-0
2 additions, 0 deletions
tests/extmod/btree1.py.exp
with
25 additions
and
0 deletions
extmod/modbtree.c
+
20
−
0
View file @
3eb532e9
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include
"py/nlr.h"
#include
"py/nlr.h"
#include
"py/runtime.h"
#include
"py/runtime.h"
#include
"py/runtime0.h"
#include
"py/stream.h"
#include
"py/stream.h"
#if MICROPY_PY_BTREE
#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) {
...
@@ -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
[]
=
{
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_close
),
MP_ROM_PTR
(
&
btree_close_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_get
),
MP_ROM_PTR
(
&
btree_get_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 = {
...
@@ -311,6 +330,7 @@ STATIC const mp_obj_type_t btree_type = {
.
print
=
btree_print
,
.
print
=
btree_print
,
.
getiter
=
btree_getiter
,
.
getiter
=
btree_getiter
,
.
iternext
=
btree_iternext
,
.
iternext
=
btree_iternext
,
.
binary_op
=
btree_binary_op
,
.
subscr
=
btree_subscr
,
.
subscr
=
btree_subscr
,
.
locals_dict
=
(
void
*
)
&
btree_locals_dict
,
.
locals_dict
=
(
void
*
)
&
btree_locals_dict
,
};
};
...
...
This diff is collapsed.
Click to expand it.
tests/extmod/btree1.py
+
3
−
0
View file @
3eb532e9
...
@@ -62,5 +62,8 @@ print(list(db.values()))
...
@@ -62,5 +62,8 @@ print(list(db.values()))
for
k
in
db
:
for
k
in
db
:
print
(
k
)
print
(
k
)
print
(
"
foo1
"
,
"
foo1
"
in
db
)
print
(
"
foo2
"
,
"
foo2
"
in
db
)
db
.
close
()
db
.
close
()
f
.
close
()
f
.
close
()
This diff is collapsed.
Click to expand it.
tests/extmod/btree1.py.exp
+
2
−
0
View file @
3eb532e9
...
@@ -30,3 +30,5 @@ KeyError
...
@@ -30,3 +30,5 @@ KeyError
b'bar1'
b'bar1'
b'foo1'
b'foo1'
b'foo3'
b'foo3'
foo1 True
foo2 False
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment