Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
7cf057ae
Commit
7cf057ae
authored
Apr 06, 2014
by
Paul Sokolovsky
Browse files
objdict: Implement equality operator.
Sure, it's O(n^2).
parent
5fedd0c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
py/objdict.c
View file @
7cf057ae
...
...
@@ -86,6 +86,28 @@ STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_map_elem_t
*
elem
=
mp_map_lookup
(
&
o
->
map
,
rhs_in
,
MP_MAP_LOOKUP
);
return
MP_BOOL
(
elem
!=
NULL
);
}
case
MP_BINARY_OP_EQUAL
:
{
// TODO: Support equality to other object types
if
(
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_dict
))
{
mp_obj_dict_t
*
rhs
=
rhs_in
;
if
(
o
->
map
.
used
!=
rhs
->
map
.
used
)
{
return
mp_const_false
;
}
machine_uint_t
size
=
o
->
map
.
alloc
;
mp_map_t
*
map
=
&
o
->
map
;
for
(
machine_uint_t
i
=
0
;
i
<
size
;
i
++
)
{
if
(
MP_MAP_SLOT_IS_FILLED
(
map
,
i
))
{
mp_map_elem_t
*
elem
=
mp_map_lookup
(
&
rhs
->
map
,
map
->
table
[
i
].
key
,
MP_MAP_LOOKUP
);
if
(
elem
==
NULL
||
!
mp_obj_equal
(
map
->
table
[
i
].
value
,
elem
->
value
))
{
return
mp_const_false
;
}
}
}
return
mp_const_true
;
}
}
default:
// op not supported
return
NULL
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment