Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
aaad00e6
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
aaad00e6
编写于
7月 20, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: remove unused code
上级
d51e2762
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
83 deletion
+20
-83
pkg/application/arch/tequila/incl_viz.go
pkg/application/arch/tequila/incl_viz.go
+4
-5
pkg/application/arch/tequila/incl_viz_test.go
pkg/application/arch/tequila/incl_viz_test.go
+1
-2
pkg/application/arch/tequila/path_trie.go
pkg/application/arch/tequila/path_trie.go
+15
-23
pkg/application/arch/tequila/trie/common.go
pkg/application/arch/tequila/trie/common.go
+0
-53
未找到文件。
pkg/application/arch/tequila/incl_viz.go
浏览文件 @
aaad00e6
...
...
@@ -2,7 +2,6 @@ package tequila
import
(
"github.com/awalterschulze/gographviz"
"github.com/phodal/coca/pkg/application/arch/tequila/trie"
"sort"
"strconv"
"strings"
...
...
@@ -159,7 +158,7 @@ func (fullGraph *FullGraph) ToMapDot(include func(string) bool) *gographviz.Grap
return
dot
}
func
(
fullGraph
*
FullGraph
)
MapToGraph
(
trie
*
trie
.
PathTrie
)
*
gographviz
.
Graph
{
func
(
fullGraph
*
FullGraph
)
MapToGraph
(
trie
*
PathTrie
)
*
gographviz
.
Graph
{
graph
:=
gographviz
.
NewGraph
()
_
=
graph
.
SetName
(
"G"
)
...
...
@@ -187,7 +186,7 @@ func (fullGraph *FullGraph) MapToGraph(trie *trie.PathTrie) *gographviz.Graph {
return
graph
}
func
(
fullGraph
*
FullGraph
)
buildGraphNode
(
subgraph
string
,
current
*
trie
.
PathTrie
,
graph
*
gographviz
.
Graph
,
nodes
map
[
string
]
string
,
s
string
)
{
func
(
fullGraph
*
FullGraph
)
buildGraphNode
(
subgraph
string
,
current
*
PathTrie
,
graph
*
gographviz
.
Graph
,
nodes
map
[
string
]
string
,
s
string
)
{
if
s
!=
""
{
s
=
s
+
"."
+
current
.
Value
}
else
{
...
...
@@ -209,8 +208,8 @@ func (fullGraph *FullGraph) buildGraphNode(subgraph string, current *trie.PathTr
}
}
func
(
fullGraph
*
FullGraph
)
BuildMapTree
(
include
func
(
key
string
)
bool
)
*
trie
.
PathTrie
{
pkgTrie
:=
trie
.
NewPathTrie
()
func
(
fullGraph
*
FullGraph
)
BuildMapTree
(
include
func
(
key
string
)
bool
)
*
PathTrie
{
pkgTrie
:=
NewPathTrie
()
for
nodeKey
:=
range
fullGraph
.
NodeList
{
if
include
(
nodeKey
)
||
include
(
fullGraph
.
NodeList
[
nodeKey
])
{
pkgTrie
.
Put
(
strings
.
ReplaceAll
(
nodeKey
,
"."
,
"/"
))
...
...
pkg/application/arch/tequila/incl_viz_test.go
浏览文件 @
aaad00e6
...
...
@@ -3,11 +3,10 @@ package tequila
import
(
.
"github.com/onsi/gomega"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/pkg/application/arch/tequila/trie"
"testing"
)
func
createBasicMap
()
(
*
trie
.
PathTrie
,
*
FullGraph
)
{
func
createBasicMap
()
(
*
PathTrie
,
*
FullGraph
)
{
fullGraph
,
nodeFilter
:=
createGraph
()
node
:=
fullGraph
.
BuildMapTree
(
nodeFilter
)
...
...
pkg/application/arch/tequila/
trie/
path_trie.go
→
pkg/application/arch/tequila/path_trie.go
浏览文件 @
aaad00e6
...
...
@@ -21,40 +21,35 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
package
t
rie
package
t
equila
import
"strings"
type
StringSegmenter
func
(
key
string
,
start
int
)
(
segment
string
,
nextIndex
int
)
func
PathSegmenter
(
path
string
,
start
int
)
(
segment
string
,
next
int
)
{
if
len
(
path
)
==
0
||
start
<
0
||
start
>
len
(
path
)
-
1
{
return
""
,
-
1
}
end
:=
strings
.
IndexRune
(
path
[
start
+
1
:
],
'/'
)
// next '/' after 0th rune
if
end
==
-
1
{
return
path
[
start
:
],
-
1
}
return
path
[
start
:
start
+
end
+
1
],
start
+
end
+
1
}
type
PathTrie
struct
{
segmenter
StringSegmenter
// key segmenter, must not cause heap allocs
segmenter
StringSegmenter
Value
string
Children
map
[
string
]
*
PathTrie
}
// PathTrieConfig for building a path trie with different segmenter
type
PathTrieConfig
struct
{
Segmenter
StringSegmenter
}
// NewPathTrie allocates and returns a new *PathTrie.
func
NewPathTrie
()
*
PathTrie
{
return
&
PathTrie
{
segmenter
:
PathSegmenter
,
}
}
// NewPathTrieWithConfig allocates and returns a new *PathTrie with the given *PathTrieConfig
func
NewPathTrieWithConfig
(
config
*
PathTrieConfig
)
*
PathTrie
{
segmenter
:=
PathSegmenter
if
config
!=
nil
&&
config
.
Segmenter
!=
nil
{
segmenter
=
config
.
Segmenter
}
return
&
PathTrie
{
segmenter
:
segmenter
,
}
}
func
(
trie
*
PathTrie
)
Put
(
key
string
)
{
node
:=
trie
for
part
,
i
:=
trie
.
segmenter
(
key
,
0
);
part
!=
""
;
part
,
i
=
trie
.
segmenter
(
key
,
i
)
{
...
...
@@ -70,7 +65,4 @@ func (trie *PathTrie) Put(key string) {
child
.
Value
=
strings
.
ReplaceAll
(
part
,
"/"
,
""
)
node
=
child
}
// does node have an existing Value?
//isNewVal := node.Value == nil
//return isNewVal
}
pkg/application/arch/tequila/trie/common.go
已删除
100644 → 0
浏览文件 @
d51e2762
// https://github.com/dghubble/trie
//The MIT License (MIT)
//
//Copyright (c) 2014 Dalton Hubble
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
package
trie
import
(
"strings"
)
// WalkFunc defines some action to take on the given key and Value during
// a Trie Walk. Returning a non-nil error will terminate the Walk.
type
WalkFunc
func
(
key
string
,
value
interface
{})
error
// StringSegmenter takes a string key with a starting index and returns
// the first segment after the start and the ending index. When the end is
// reached, the returned nextIndex should be -1.
// Implementations should NOT allocate heap memory as Trie Segmenters are
// called upon Gets. See PathSegmenter.
type
StringSegmenter
func
(
key
string
,
start
int
)
(
segment
string
,
nextIndex
int
)
// PathSegmenter segments string key paths by slash separators. For example,
// "/a/b/c" -> ("/a", 2), ("/b", 4), ("/c", -1) in successive calls. It does
// not allocate any heap memory.
func
PathSegmenter
(
path
string
,
start
int
)
(
segment
string
,
next
int
)
{
if
len
(
path
)
==
0
||
start
<
0
||
start
>
len
(
path
)
-
1
{
return
""
,
-
1
}
end
:=
strings
.
IndexRune
(
path
[
start
+
1
:
],
'/'
)
// next '/' after 0th rune
if
end
==
-
1
{
return
path
[
start
:
],
-
1
}
return
path
[
start
:
start
+
end
+
1
],
start
+
end
+
1
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录