2019-09-05 06:09:56 +02:00
|
|
|
package jsn
|
|
|
|
|
|
|
|
type skipInfo struct {
|
|
|
|
ss, se int
|
|
|
|
}
|
|
|
|
|
2020-04-10 08:27:43 +02:00
|
|
|
type stack struct {
|
2019-09-05 06:09:56 +02:00
|
|
|
stA [20]skipInfo
|
|
|
|
st []skipInfo
|
|
|
|
top int
|
|
|
|
}
|
|
|
|
|
2020-04-10 08:27:43 +02:00
|
|
|
// Create a new stack
|
|
|
|
func newStack() *stack {
|
|
|
|
s := &stack{top: -1}
|
2019-09-05 06:09:56 +02:00
|
|
|
s.st = s.stA[:0]
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2020-04-10 08:27:43 +02:00
|
|
|
// Return the number of items in the stack
|
|
|
|
func (s *stack) Len() int {
|
2019-09-05 06:09:56 +02:00
|
|
|
return (s.top + 1)
|
|
|
|
}
|
|
|
|
|
2020-04-10 08:27:43 +02:00
|
|
|
// View the top item on the stack
|
|
|
|
func (s *stack) Peek() *skipInfo {
|
2019-09-05 06:09:56 +02:00
|
|
|
if s.top == -1 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &s.st[s.top]
|
|
|
|
}
|
|
|
|
|
2020-04-10 08:27:43 +02:00
|
|
|
// Pop the top item of the stack and return it
|
|
|
|
func (s *stack) Pop() *skipInfo {
|
2019-09-05 06:09:56 +02:00
|
|
|
if s.top == -1 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
s.top--
|
|
|
|
return &s.st[(s.top + 1)]
|
|
|
|
}
|
|
|
|
|
2020-04-10 08:27:43 +02:00
|
|
|
// Push a value onto the top of the stack
|
|
|
|
func (s *stack) Push(value skipInfo) {
|
2019-09-05 06:09:56 +02:00
|
|
|
s.top++
|
|
|
|
if len(s.st) <= s.top {
|
|
|
|
s.st = append(s.st, value)
|
|
|
|
} else {
|
|
|
|
s.st[s.top] = value
|
|
|
|
}
|
|
|
|
}
|