mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
8595d6c2e9
1.Add Network rule, match network type(TCP/UDP) 2.Add logic rules(NOT,OR,AND) -AND,((DOMAIN,baidu.com),(NETWORK,UDP)),REJECT (cherry picked from commit d7092e2e37f2c48282c878edea1b2ebc2912b09a)
57 lines
941 B
Go
57 lines
941 B
Go
package collections
|
|
|
|
import "sync"
|
|
|
|
type (
|
|
stack struct {
|
|
top *node
|
|
length int
|
|
lock *sync.RWMutex
|
|
}
|
|
|
|
node struct {
|
|
value interface{}
|
|
prev *node
|
|
}
|
|
)
|
|
|
|
// NewStack Create a new stack
|
|
func NewStack() *stack {
|
|
return &stack{nil, 0, &sync.RWMutex{}}
|
|
}
|
|
|
|
// Len Return the number of items in the stack
|
|
func (this *stack) Len() int {
|
|
return this.length
|
|
}
|
|
|
|
// Peek View the top item on the stack
|
|
func (this *stack) Peek() interface{} {
|
|
if this.length == 0 {
|
|
return nil
|
|
}
|
|
return this.top.value
|
|
}
|
|
|
|
// Pop the top item of the stack and return it
|
|
func (this *stack) Pop() interface{} {
|
|
this.lock.Lock()
|
|
defer this.lock.Unlock()
|
|
if this.length == 0 {
|
|
return nil
|
|
}
|
|
n := this.top
|
|
this.top = n.prev
|
|
this.length--
|
|
return n.value
|
|
}
|
|
|
|
// Push a value onto the top of the stack
|
|
func (this *stack) Push(value interface{}) {
|
|
this.lock.Lock()
|
|
defer this.lock.Unlock()
|
|
n := &node{value, this.top}
|
|
this.top = n
|
|
this.length++
|
|
}
|