Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
treevalue
提交
888f5890
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,发现更多精彩内容 >>
提交
888f5890
编写于
1月 09, 2022
作者:
HansBug
😆
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dev(hansbug): add keys, values and items for TreeValue class
上级
472c0213
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
77 addition
and
2 deletion
+77
-2
docs/source/api_doc/tree/general.rst
docs/source/api_doc/tree/general.rst
+1
-1
docs/source/api_doc/tree/tree.rst
docs/source/api_doc/tree/tree.rst
+1
-1
test/tree/tree/test_tree.py
test/tree/tree/test_tree.py
+31
-0
treevalue/tree/tree/tree.pyx
treevalue/tree/tree/tree.pyx
+44
-0
未找到文件。
docs/source/api_doc/tree/general.rst
浏览文件 @
888f5890
...
...
@@ -7,7 +7,7 @@ FastTreeValue
-------------------
.. autoclass:: treevalue.tree.general.FastTreeValue
:members: _attr_extern, json, clone, __add__, __radd__, __sub__, __rsub__, __mul__, __rmul__, __matmul__, __rmatmul__, __truediv__, __rtruediv__, __floordiv__, __rfloordiv__, __mod__, __rmod__, __pow__, __rpow__, __and__, __rand__, __or__, __ror__, __xor__, __rxor__, __lshift__, __rlshift__, __rshift__, __rrshift__, __pos__, __neg__, __invert__, __getitem__, __setitem__, __delitem__, __call__, __getattribute__, __setattr__, __delattr__, __repr__, __iter__, __hash__, __eq__, map, type, mask, filter, __str__, reduce, rise, union, subside, __getstate__, __setstate__, __iadd__, __isub__, __imul__, __imatmul__, __ifloordiv__, __itruediv__, __ipow__, __imod__, __iand__, __ior__, __ixor__, __ilshift__, __irshift__, graph, graphics, func
:members: _attr_extern, json, clone, __add__, __radd__, __sub__, __rsub__, __mul__, __rmul__, __matmul__, __rmatmul__, __truediv__, __rtruediv__, __floordiv__, __rfloordiv__, __mod__, __rmod__, __pow__, __rpow__, __and__, __rand__, __or__, __ror__, __xor__, __rxor__, __lshift__, __rlshift__, __rshift__, __rrshift__, __pos__, __neg__, __invert__, __getitem__, __setitem__, __delitem__, __call__, __getattribute__, __setattr__, __delattr__, __repr__, __iter__, __hash__, __eq__, map, type, mask, filter, __str__, reduce, rise, union, subside, __getstate__, __setstate__, __iadd__, __isub__, __imul__, __imatmul__, __ifloordiv__, __itruediv__, __ipow__, __imod__, __iand__, __ior__, __ixor__, __ilshift__, __irshift__, graph, graphics, func
, keys, values, items
.. _apidoc_tree_general_generaltreevalue:
...
...
docs/source/api_doc/tree/tree.rst
浏览文件 @
888f5890
...
...
@@ -9,7 +9,7 @@ TreeValue
---------------
.. autoclass:: TreeValue
:members: __init__, __getattribute__, __setattr__, __delattr__, __contains__, __repr__, __iter__, __hash__, __eq__, _attr_extern, __len__, __bool__, __str__, __getstate__, __setstate__, get
:members: __init__, __getattribute__, __setattr__, __delattr__, __contains__, __repr__, __iter__, __hash__, __eq__, _attr_extern, __len__, __bool__, __str__, __getstate__, __setstate__, get
, keys, values, items
.. _apidoc_tree_tree_delayed:
...
...
test/tree/tree/test_tree.py
浏览文件 @
888f5890
...
...
@@ -204,3 +204,34 @@ class TestTreeTreeTree:
with
pytest
.
raises
(
KeyError
):
_
=
tv1
.
get
(
'e'
)
assert
tv1
.
get
(
'e'
,
233
)
==
233
def
test_keys
(
self
):
tv1
=
TreeValue
({
'a'
:
1
,
'b'
:
2
,
'c'
:
{
'x'
:
2
,
'y'
:
3
},
'd'
:
raw
({
'x'
:
2
,
'y'
:
3
})})
assert
set
(
tv1
.
keys
())
==
{
'a'
,
'b'
,
'c'
,
'd'
}
def
test_values
(
self
):
tv1
=
TreeValue
({
'a'
:
1
,
'b'
:
2
,
'c'
:
{
'x'
:
2
,
'y'
:
3
}})
assert
set
(
tv1
.
c
.
values
())
==
{
2
,
3
}
assert
len
(
list
(
tv1
.
values
()))
==
3
assert
1
in
tv1
.
values
()
assert
2
in
tv1
.
values
()
def
test_items
(
self
):
tv1
=
TreeValue
({
'a'
:
1
,
'b'
:
2
,
'c'
:
{
'x'
:
2
,
'y'
:
3
},
'd'
:
raw
({
'x'
:
2
,
'y'
:
3
})})
assert
sorted
(
tv1
.
items
())
==
[
(
'a'
,
1
),
(
'b'
,
2
),
(
'c'
,
TreeValue
({
'x'
:
2
,
'y'
:
3
})),
(
'd'
,
{
'x'
:
2
,
'y'
:
3
}),
]
class
MyTreeValue
(
TreeValue
):
pass
tv2
=
MyTreeValue
({
'a'
:
1
,
'b'
:
2
,
'c'
:
{
'x'
:
2
,
'y'
:
3
},
'd'
:
raw
({
'x'
:
2
,
'y'
:
3
})})
assert
sorted
(
tv2
.
items
())
==
[
(
'a'
,
1
),
(
'b'
,
2
),
(
'c'
,
MyTreeValue
({
'x'
:
2
,
'y'
:
3
})),
(
'd'
,
{
'x'
:
2
,
'y'
:
3
}),
]
treevalue/tree/tree/tree.pyx
浏览文件 @
888f5890
...
...
@@ -370,6 +370,50 @@ cdef class TreeValue:
"""
return
self
.
_st
@
cython
.
binding
(
True
)
def
keys
(
self
):
"""
Overview:
Get keys of this treevalue object, like the :class:`dict`.
Returns:
- keys: A generator of all the keys.
"""
return
self
.
_st
.
keys
()
@
cython
.
binding
(
True
)
def
values
(
self
):
"""
Overview:
Get value of this treevalue object, like the :class:`dict`.
Returns:
- values: A generator of all the values
"""
cdef
object
v
for
v
in
self
.
_st
.
values
():
if
isinstance
(
v
,
TreeStorage
):
yield
self
.
_type
(
v
)
else
:
yield
v
@
cython
.
binding
(
True
)
def
items
(
self
):
"""
Overview:
Get pairs of keys and values of this treevalue object, like the :class:`items`.
Returns:
- items: A generator of pairs of keys and values.
"""
cdef
str
k
cdef
object
v
for
k
,
v
in
self
.
_st
.
items
():
if
isinstance
(
v
,
TreeStorage
):
yield
k
,
self
.
_type
(
v
)
else
:
yield
k
,
v
cdef
str
_prefix_fix
(
object
text
,
object
prefix
):
cdef
list
lines
=
[]
cdef
int
i
...
...
HansBug
😆
@HansBug
mentioned in commit
f622e171
·
1月 10, 2022
mentioned in commit
f622e171
mentioned in commit f622e1719f02eaf050c7f471ab26589d691a0677
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录