pass tests including pretty tree
This commit is contained in:
@@ -21,8 +21,8 @@ type Branch struct {
|
||||
}
|
||||
|
||||
type Pretty struct {
|
||||
Children map[string]*Pretty
|
||||
Title string
|
||||
Children map[string]Pretty
|
||||
}
|
||||
|
||||
func NewTree(path string) *Tree {
|
||||
@@ -31,15 +31,46 @@ func NewTree(path string) *Tree {
|
||||
}
|
||||
}
|
||||
|
||||
func (tree *Tree) GetPretty() (map[string]Pretty, error) {
|
||||
func (tree *Tree) GetPretty() (map[string]*Pretty, error) {
|
||||
branches, err := tree.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = branches
|
||||
pretty := map[string]Pretty{}
|
||||
// TODO: rm del
|
||||
return pretty, errors.New("not impl")
|
||||
realpretty := map[string]*Pretty{}
|
||||
lookuppretty := map[string]*Pretty{}
|
||||
timesZero := 0
|
||||
for len(branches) > 0 && timesZero < 3 {
|
||||
topop := []string{}
|
||||
for id, branch := range branches {
|
||||
if branch.Deleted {
|
||||
} else if branch.PID == "" {
|
||||
realpretty[id] = &Pretty{
|
||||
Title: branch.Title,
|
||||
Children: map[string]*Pretty{},
|
||||
}
|
||||
lookuppretty[id] = realpretty[id]
|
||||
} else if ptr, ok := lookuppretty[branch.PID]; ok {
|
||||
ptr.Children[id] = &Pretty{
|
||||
Title: branch.Title,
|
||||
Children: map[string]*Pretty{},
|
||||
}
|
||||
lookuppretty[id] = ptr.Children[id]
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
topop = append(topop, id)
|
||||
}
|
||||
for _, id := range topop {
|
||||
delete(branches, id)
|
||||
}
|
||||
if len(topop) == 0 {
|
||||
timesZero++
|
||||
} else {
|
||||
timesZero = 0
|
||||
}
|
||||
}
|
||||
return realpretty, nil
|
||||
}
|
||||
|
||||
func (tree *Tree) Get() (map[string]Branch, error) {
|
||||
|
||||
Reference in New Issue
Block a user