CI / test (pull_request) Waiting to run
- gofmt main.go to fix tab indentation in main() body - stats.go ComputeSummary: return nil when Answers and ByType are empty - dns/types.go: remove duplicate ParseQueryType (dead code) - formatter.go: log hook errors to stderr when Debug > 0; add Debug to Config - text.go referralID: remove redundant depth==0 branch - text.go writeServers: remove version lookup placeholder string Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: multica-agent <github@multica.ai>
59 lines
878 B
Go
59 lines
878 B
Go
package traverse
|
|
|
|
const DefaultMaxDepth = 20
|
|
|
|
type Stack struct {
|
|
items []*Referral
|
|
maxDepth int
|
|
}
|
|
|
|
func NewStack(maxDepth int) *Stack {
|
|
if maxDepth <= 0 {
|
|
maxDepth = DefaultMaxDepth
|
|
}
|
|
return &Stack{
|
|
items: make([]*Referral, 0),
|
|
maxDepth: maxDepth,
|
|
}
|
|
}
|
|
|
|
func (s *Stack) Push(r *Referral) bool {
|
|
if r == nil {
|
|
return false
|
|
}
|
|
if r.Depth >= s.maxDepth {
|
|
return false
|
|
}
|
|
s.items = append(s.items, r)
|
|
return true
|
|
}
|
|
|
|
func (s *Stack) Pop() *Referral {
|
|
if len(s.items) == 0 {
|
|
return nil
|
|
}
|
|
idx := len(s.items) - 1
|
|
item := s.items[idx]
|
|
s.items = s.items[:idx]
|
|
return item
|
|
}
|
|
|
|
func (s *Stack) Peek() *Referral {
|
|
if len(s.items) == 0 {
|
|
return nil
|
|
}
|
|
return s.items[len(s.items)-1]
|
|
}
|
|
|
|
func (s *Stack) Len() int {
|
|
return len(s.items)
|
|
}
|
|
|
|
func (s *Stack) MaxDepth() int {
|
|
return s.maxDepth
|
|
}
|
|
|
|
func (s *Stack) IsEmpty() bool {
|
|
return len(s.items) == 0
|
|
}
|