Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
treevalue
提交
a144b910
T
treevalue
项目概览
OpenDILab开源决策智能平台
/
treevalue
大约 1 年 前同步成功
通知
3
Star
213
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
treevalue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a144b910
编写于
7月 06, 2022
作者:
HansBug
😆
提交者:
GitHub
7月 06, 2022
1
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #52 from opendilab/dev/mutablemapping
dev(hansbug): add popitem method for TreeValue
上级
17cdc03f
5c6ea4df
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
76 addition
and
1 deletion
+76
-1
docs/source/api_doc/tree/tree.rst
docs/source/api_doc/tree/tree.rst
+1
-1
test/tree/common/test_storage.py
test/tree/common/test_storage.py
+27
-0
test/tree/tree/test_tree.py
test/tree/tree/test_tree.py
+19
-0
treevalue/tree/common/storage.pxd
treevalue/tree/common/storage.pxd
+1
-0
treevalue/tree/common/storage.pyx
treevalue/tree/common/storage.pyx
+6
-0
treevalue/tree/tree/tree.pxd
treevalue/tree/tree/tree.pxd
+1
-0
treevalue/tree/tree/tree.pyx
treevalue/tree/tree/tree.pyx
+21
-0
未找到文件。
docs/source/api_doc/tree/tree.rst
浏览文件 @
a144b910
...
@@ -9,7 +9,7 @@ TreeValue
...
@@ -9,7 +9,7 @@ TreeValue
---------------
---------------
.. autoclass:: TreeValue
.. autoclass:: TreeValue
:members: __init__, __getattribute__, __setattr__, __delattr__, __contains__, __repr__, __iter__, __hash__, __eq__, _attr_extern, __len__, __bool__, __str__, __getstate__, __setstate__, get, pop, keys, values, items, __getitem__, __setitem__, __delitem__, _getitem_extern, _setitem_extern, _delitem_extern
:members: __init__, __getattribute__, __setattr__, __delattr__, __contains__, __repr__, __iter__, __hash__, __eq__, _attr_extern, __len__, __bool__, __str__, __getstate__, __setstate__, get, pop, keys, values, items, __getitem__, __setitem__, __delitem__, _getitem_extern, _setitem_extern, _delitem_extern
, popitem
.. _apidoc_tree_tree_delayed:
.. _apidoc_tree_tree_delayed:
...
...
test/tree/common/test_storage.py
浏览文件 @
a144b910
...
@@ -208,6 +208,33 @@ class TestTreeStorage:
...
@@ -208,6 +208,33 @@ class TestTreeStorage:
assert
t1
.
pop_or_default
(
'fff'
,
delayed_partial
(
lambda
:
2345
))
==
2345
assert
t1
.
pop_or_default
(
'fff'
,
delayed_partial
(
lambda
:
2345
))
==
2345
assert
not
t1
.
contains
(
'fff'
)
assert
not
t1
.
contains
(
'fff'
)
def
test_popitem
(
self
):
t
=
create_storage
({})
with
pytest
.
raises
(
KeyError
):
t
.
popitem
()
t1
=
create_storage
({
'a'
:
1
,
'b'
:
2
,
'c'
:
{
'x'
:
2
}})
assert
sorted
([
t1
.
popitem
()
for
_
in
range
(
t1
.
size
())])
==
[
(
'a'
,
1
),
(
'b'
,
2
),
(
'c'
,
create_storage
({
'x'
:
2
}))
]
t2
=
create_storage
({
'a'
:
delayed_partial
(
lambda
:
1
),
'b'
:
delayed_partial
(
lambda
:
2
),
})
assert
sorted
([
t2
.
popitem
()
for
_
in
range
(
t2
.
size
())])
==
[
(
'a'
,
1
),
(
'b'
,
2
)
]
d1
=
delayed_partial
(
lambda
:
1
)
d2
=
delayed_partial
(
lambda
x
:
x
+
1
,
d1
)
t3
=
create_storage
({
'a'
:
d1
,
'b'
:
d2
,
'c'
:
d1
,
})
assert
sorted
([
t3
.
popitem
()
for
_
in
range
(
t3
.
size
())])
==
[
(
'a'
,
1
),
(
'b'
,
2
),
(
'c'
,
1
)
]
def
test_set
(
self
):
def
test_set
(
self
):
t
=
create_storage
({})
t
=
create_storage
({})
t
.
set
(
'a'
,
1
)
t
.
set
(
'a'
,
1
)
...
...
test/tree/tree/test_tree.py
浏览文件 @
a144b910
...
@@ -336,6 +336,25 @@ class TestTreeTreeTree:
...
@@ -336,6 +336,25 @@ class TestTreeTreeTree:
assert
tv3
.
pop
(
'b'
,
345
)
==
345
assert
tv3
.
pop
(
'b'
,
345
)
==
345
assert
tv3
.
pop
(
'c'
,
345
)
==
345
assert
tv3
.
pop
(
'c'
,
345
)
==
345
def
test_popitem
(
self
):
tv1
=
TreeValue
({
'a'
:
1
,
'b'
:
2
,
'c'
:
{
'x'
:
2
,
'y'
:
3
},
'd'
:
raw
({
'x'
:
2
,
'y'
:
3
})})
assert
sorted
([
tv1
.
popitem
()
for
_
in
range
(
len
(
tv1
))])
==
[
(
'a'
,
1
),
(
'b'
,
2
),
(
'c'
,
TreeValue
({
'x'
:
2
,
'y'
:
3
})),
(
'd'
,
{
'x'
:
2
,
'y'
:
3
}),
]
with
pytest
.
raises
(
KeyError
):
tv1
.
popitem
()
d1
=
delayed
(
lambda
:
1
)
d2
=
delayed
(
lambda
x
:
x
+
1
,
d1
)
tv2
=
TreeValue
({
'a'
:
d1
,
'b'
:
d2
,
'c'
:
d1
,
'd'
:
100
})
assert
sorted
([
tv2
.
popitem
()
for
_
in
range
(
len
(
tv2
))])
==
[
(
'a'
,
1
),
(
'b'
,
2
),
(
'c'
,
1
),
(
'd'
,
100
),
]
with
pytest
.
raises
(
KeyError
):
tv2
.
popitem
()
def
test_keys
(
self
):
def
test_keys
(
self
):
tv1
=
TreeValue
({
'a'
:
1
,
'b'
:
2
,
'c'
:
{
'x'
:
2
,
'y'
:
3
},
'd'
:
raw
({
'x'
:
2
,
'y'
:
3
})})
tv1
=
TreeValue
({
'a'
:
1
,
'b'
:
2
,
'c'
:
{
'x'
:
2
,
'y'
:
3
},
'd'
:
raw
({
'x'
:
2
,
'y'
:
3
})})
assert
len
(
tv1
.
keys
())
==
4
assert
len
(
tv1
.
keys
())
==
4
...
...
treevalue/tree/common/storage.pxd
浏览文件 @
a144b910
...
@@ -14,6 +14,7 @@ cdef class TreeStorage:
...
@@ -14,6 +14,7 @@ cdef class TreeStorage:
cpdef
public
object
get_or_default
(
self
,
str
key
,
object
default
)
cpdef
public
object
get_or_default
(
self
,
str
key
,
object
default
)
cpdef
public
object
pop
(
self
,
str
key
)
cpdef
public
object
pop
(
self
,
str
key
)
cpdef
public
object
pop_or_default
(
self
,
str
key
,
object
default
)
cpdef
public
object
pop_or_default
(
self
,
str
key
,
object
default
)
cpdef
public
tuple
popitem
(
self
)
cpdef
public
void
del_
(
self
,
str
key
)
except
*
cpdef
public
void
del_
(
self
,
str
key
)
except
*
cpdef
public
boolean
contains
(
self
,
str
key
)
cpdef
public
boolean
contains
(
self
,
str
key
)
cpdef
public
uint
size
(
self
)
cpdef
public
uint
size
(
self
)
...
...
treevalue/tree/common/storage.pyx
浏览文件 @
a144b910
...
@@ -55,6 +55,12 @@ cdef class TreeStorage:
...
@@ -55,6 +55,12 @@ cdef class TreeStorage:
del
self
.
map
[
key
]
del
self
.
map
[
key
]
return
res
return
res
cpdef
public
tuple
popitem
(
self
):
cdef
str
k
cdef
object
v
k
,
v
=
self
.
map
.
popitem
()
return
k
,
undelay
(
v
)
cpdef
public
void
del_
(
self
,
str
key
)
except
*
:
cpdef
public
void
del_
(
self
,
str
key
)
except
*
:
try
:
try
:
del
self
.
map
[
key
]
del
self
.
map
[
key
]
...
...
treevalue/tree/tree/tree.pxd
浏览文件 @
a144b910
...
@@ -22,6 +22,7 @@ cdef class TreeValue:
...
@@ -22,6 +22,7 @@ cdef class TreeValue:
cpdef
_delitem_extern
(
self
,
object
key
)
cpdef
_delitem_extern
(
self
,
object
key
)
cpdef
get
(
self
,
str
key
,
object
default
=
*
)
cpdef
get
(
self
,
str
key
,
object
default
=
*
)
cpdef
pop
(
self
,
str
key
,
object
default
=
*
)
cpdef
pop
(
self
,
str
key
,
object
default
=
*
)
cpdef
popitem
(
self
)
cpdef
treevalue_keys
keys
(
self
)
cpdef
treevalue_keys
keys
(
self
)
cpdef
treevalue_values
values
(
self
)
cpdef
treevalue_values
values
(
self
)
...
...
treevalue/tree/tree/tree.pyx
浏览文件 @
a144b910
...
@@ -140,6 +140,27 @@ cdef class TreeValue:
...
@@ -140,6 +140,27 @@ cdef class TreeValue:
return
self
.
_unraw
(
value
)
return
self
.
_unraw
(
value
)
@
cython
.
binding
(
True
)
cpdef
popitem
(
self
):
"""
Overview:
Pop item (with a key and its value) from the tree node.
:return: Popped item.
:raise KeyError: When current treevalue is empty.
.. note::
The method :meth:`popitem` will raise ``KeyError`` when empty, like the behaviour in
\
`dict.popitem <https://docs.python.org/3/library/stdtypes.html#dict.popitem>`_.
"""
cdef
str
k
cdef
object
v
try
:
k
,
v
=
self
.
_st
.
popitem
()
return
k
,
self
.
_unraw
(
v
)
except
KeyError
:
raise
KeyError
(
f
'popitem():
{
self
.
_type
.
__name__
}
is empty.'
)
@
cython
.
binding
(
True
)
@
cython
.
binding
(
True
)
cpdef
_attr_extern
(
self
,
str
key
):
cpdef
_attr_extern
(
self
,
str
key
):
r
"""
r
"""
...
...
HansBug
😆
@HansBug
mentioned in commit
f98c95f0
·
7月 14, 2022
mentioned in commit
f98c95f0
mentioned in commit f98c95f046f7c3f4f7893bccf0841d605327b1c2
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录