Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
treevalue
提交
abf91b85
T
treevalue
项目概览
OpenDILab开源决策智能平台
/
treevalue
10 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
abf91b85
编写于
12月 04, 2022
作者:
HansBug
😆
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dev(hansbug): optimize the performance
上级
4f5c11b3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
31 deletion
+39
-31
treevalue/tree/tree/constraint.pxd
treevalue/tree/tree/constraint.pxd
+5
-3
treevalue/tree/tree/constraint.pyx
treevalue/tree/tree/constraint.pyx
+32
-26
treevalue/tree/tree/tree.pyx
treevalue/tree/tree/tree.pyx
+2
-2
未找到文件。
treevalue/tree/tree/constraint.pxd
浏览文件 @
abf91b85
...
...
@@ -19,12 +19,14 @@ cdef class Constraint:
cpdef
tuple
check
(
self
,
object
instance
)
cpdef
bool
equiv
(
self
,
object
other
)
cdef
Constraint
_r_parse_cons
(
object
obj
)
cpdef
Constraint
to_constraint
(
object
obj
)
cdef
class
EmptyConstraint
(
Constraint
):
pass
cdef
EmptyConstraint
_EMPTY_CONSTRAINT
cdef
Constraint
_r_parse_cons
(
object
obj
)
cpdef
Constraint
to_constraint
(
object
obj
)
cdef
class
ValueConstraint
(
Constraint
):
pass
...
...
treevalue/tree/tree/constraint.pyx
浏览文件 @
abf91b85
...
...
@@ -118,23 +118,6 @@ cdef class Constraint:
def
__repr__
(
self
):
return
f
'<
{
type
(
self
).
__name__
}
{
self
.
_features
()
!
r
}
>'
cdef
inline
Constraint
_r_parse_cons
(
object
obj
):
if
isinstance
(
obj
,
Constraint
):
return
obj
elif
obj
is
None
:
return
EmptyConstraint
()
elif
isinstance
(
obj
,
type
):
return
TypeConstraint
(
obj
)
elif
isinstance
(
obj
,
(
list
,
tuple
)):
return
CompositeConstraint
([
_r_parse_cons
(
c
)
for
c
in
obj
])
elif
isinstance
(
obj
,
dict
):
return
TreeConstraint
({
key
:
_r_parse_cons
(
value
)
for
key
,
value
in
obj
.
items
()})
else
:
raise
TypeError
(
f
'Invalid constraint -
{
obj
!
r
}
.'
)
cpdef
inline
Constraint
to_constraint
(
object
obj
):
return
_s_simplify
(
_r_parse_cons
(
obj
))
cdef
class
EmptyConstraint
(
Constraint
):
cpdef
void
_validate_node
(
self
,
object
instance
)
except
*
:
pass
...
...
@@ -157,6 +140,25 @@ cdef class EmptyConstraint(Constraint):
def
__repr__
(
self
):
return
f
'<
{
type
(
self
).
__name__
}
>'
_EMPTY_CONSTRAINT
=
EmptyConstraint
()
cdef
inline
Constraint
_r_parse_cons
(
object
obj
):
if
isinstance
(
obj
,
Constraint
):
return
obj
elif
obj
is
None
:
return
_EMPTY_CONSTRAINT
elif
isinstance
(
obj
,
type
):
return
TypeConstraint
(
obj
)
elif
isinstance
(
obj
,
(
list
,
tuple
)):
return
CompositeConstraint
([
_r_parse_cons
(
c
)
for
c
in
obj
])
elif
isinstance
(
obj
,
dict
):
return
TreeConstraint
({
key
:
_r_parse_cons
(
value
)
for
key
,
value
in
obj
.
items
()})
else
:
raise
TypeError
(
f
'Invalid constraint -
{
obj
!
r
}
.'
)
cpdef
inline
Constraint
to_constraint
(
object
obj
):
return
_s_simplify
(
_r_parse_cons
(
obj
))
cdef
class
ValueConstraint
(
Constraint
):
cpdef
void
_validate_node
(
self
,
object
instance
)
except
*
:
pass
...
...
@@ -169,7 +171,7 @@ cdef class NodeConstraint(Constraint):
raise
TypeError
(
f
'TreeValue node expected, but value
{
instance
!
r
}
found.'
)
cpdef
Constraint
_transaction
(
self
,
str
key
):
return
EmptyConstraint
()
return
_EMPTY_CONSTRAINT
cdef
class
TypeConstraint
(
ValueConstraint
):
def
__cinit__
(
self
,
type
type_
):
...
...
@@ -232,7 +234,7 @@ cdef class LeafConstraint(Constraint):
return
isinstance
(
other
,
LeafConstraint
)
cpdef
Constraint
_transaction
(
self
,
str
key
):
return
EmptyConstraint
()
return
_EMPTY_CONSTRAINT
def
__repr__
(
self
):
return
f
'<
{
type
(
self
).
__name__
}
>'
...
...
@@ -305,7 +307,7 @@ cdef class TreeConstraint(Constraint):
if
key
in
self
.
_constraints
:
return
self
.
_constraints
[
key
]
else
:
return
EmptyConstraint
()
return
_EMPTY_CONSTRAINT
cdef
inline
Constraint
_s_tree_merge
(
list
constraints
):
cdef
dict
cmap
=
{}
...
...
@@ -329,7 +331,7 @@ cdef inline Constraint _s_tree_merge(list constraints):
if
fmap
:
return
TreeConstraint
(
fmap
)
else
:
return
EmptyConstraint
()
return
_EMPTY_CONSTRAINT
cdef
inline
Constraint
_s_tree
(
TreeConstraint
constraint
):
cdef
dict
dcons
=
{}
...
...
@@ -344,7 +346,7 @@ cdef inline Constraint _s_tree(TreeConstraint constraint):
if
dcons
:
return
TreeConstraint
(
dcons
)
else
:
return
EmptyConstraint
()
return
_EMPTY_CONSTRAINT
cdef
class
CompositeConstraint
(
Constraint
):
def
__cinit__
(
self
,
list
constraints
):
...
...
@@ -428,7 +430,7 @@ cdef inline Constraint _s_generic_merge(list constraints):
sins
.
append
(
tree
)
if
not
sins
:
return
EmptyConstraint
()
return
_EMPTY_CONSTRAINT
cdef
int
i
,
j
cdef
set
_child_ids
=
set
()
...
...
@@ -465,6 +467,10 @@ cdef inline Constraint _s_simplify(Constraint constraint):
return
constraint
cpdef
inline
Constraint
transact
(
object
cons
,
str
key
):
cdef
Constraint
constraint
=
to_constraint
(
cons
)
# noinspection PyProtectedMember
return
_s_simplify
(
constraint
.
_transaction
(
key
))
cdef
Constraint
constraint
if
isinstance
(
cons
,
EmptyConstraint
):
return
_EMPTY_CONSTRAINT
else
:
constraint
=
to_constraint
(
cons
)
# noinspection PyProtectedMember
return
_s_simplify
(
constraint
.
_transaction
(
key
))
treevalue/tree/tree/tree.pyx
浏览文件 @
abf91b85
...
...
@@ -8,7 +8,7 @@ from operator import itemgetter
import
cython
from
hbutils.design
import
SingletonMark
from
.constraint
cimport
Constraint
,
to_constraint
,
EmptyConstraint
,
transact
from
.constraint
cimport
Constraint
,
to_constraint
,
transact
,
_EMPTY_CONSTRAINT
from
..common.delay
cimport
undelay
,
_c_delayed_partial
,
DelayedProxy
from
..common.storage
cimport
TreeStorage
,
create_storage
,
_c_undelay_data
from
...utils
import
format_tree
...
...
@@ -71,7 +71,7 @@ cdef class TreeValue:
def
__cinit__
(
self
,
object
data
,
object
constraint
=
None
):
self
.
_st
=
_DEFAULT_STORAGE
self
.
constraint
=
EmptyConstraint
()
self
.
constraint
=
_EMPTY_CONSTRAINT
self
.
_type
=
type
(
self
)
@
cython
.
binding
(
True
)
...
...
HansBug
😆
@HansBug
mentioned in commit
63ad1620
·
12月 05, 2022
mentioned in commit
63ad1620
mentioned in commit 63ad1620e0d3373325a3b9cd9617986146127b78
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录