• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nats-io / nsc / 14765656943

30 Apr 2025 10:34PM UTC coverage: 69.949% (-4.2%) from 74.148%
14765656943

Pull #691

github

web-flow
Merge b4ee16f94 into a9c0df586
Pull Request #691: Generate docs

1 of 1 new or added line in 1 file covered. (100.0%)

3680 existing lines in 93 files now uncovered.

12325 of 17620 relevant lines covered (69.95%)

1.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/cmd/store/node.go
1
// Copyright 2018 The NATS Authors
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13

14
package store
15

16
import "errors"
17

18
type Node struct {
19
        Parent   *Node
20
        Data     interface{}
21
        Children []*Node
22
}
23

24
func NewNode(data interface{}) *Node {
25
        return &Node{Data: data}
26
}
2✔
27

2✔
28
func (n *Node) Add(cn *Node) *Node {
2✔
29
        cn.Parent = n
30
        n.Children = append(n.Children, cn)
2✔
31
        return cn
2✔
32
}
2✔
33

2✔
34
func (n *Node) Delete() {
2✔
35
        if n.Parent != nil {
36
                for i, c := range n.Parent.Children {
2✔
37
                        if c == n {
4✔
38
                                l := n.Parent.Children[:i]
4✔
39
                                r := n.Parent.Children[i+1:]
4✔
40
                                n.Parent.Children = append(l, r...)
2✔
41
                        }
2✔
42
                }
2✔
43
        }
2✔
44
}
45

46
var ErrSkipChildren = errors.New("skip node")
47
var ErrStopWalking = errors.New("found node")
48

49
type WalkFunc func(*Node) error
50

51
func Walk(root *Node, walkFn WalkFunc) error {
52
        err := walkFn(root)
53
        if err == nil {
2✔
54
                err = walk(root, walkFn)
2✔
55
        }
4✔
56
        if err == ErrSkipChildren || err == ErrStopWalking {
2✔
57
                return nil
2✔
58
        }
4✔
59
        return err
2✔
60
}
2✔
61

2✔
62
func walk(n *Node, walkFn WalkFunc) error {
63
        for _, c := range n.Children {
64
                err := walkFn(c)
2✔
65
                if err != nil {
4✔
66
                        if err == ErrSkipChildren {
2✔
67
                                continue
4✔
68
                        } else if err == ErrStopWalking {
4✔
69
                                return err
2✔
70
                        } else {
4✔
71
                                return err
2✔
72
                        }
2✔
UNCOV
73
                } else {
×
UNCOV
74
                        err = walk(c, walkFn)
×
75
                        if err != nil {
2✔
76
                                return err
2✔
77
                        }
2✔
UNCOV
78
                }
×
UNCOV
79
        }
×
80
        return nil
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc