Files
ExploreDNS/internal/traverse/stack.go
T
8e7beacc22
CI / test (pull_request) Waiting to run
fix: address code review issues on PR #9
- 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>
2026-06-08 02:32:58 +10:00

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
}