refactor: remove unused code

上级 d51e2762
......@@ -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, ".", "/"))
......
......@@ -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)
......
......@@ -21,40 +21,35 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
package trie
package tequila
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
}
// 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.
先完成此消息的编辑!
想要评论请 注册