mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 05:22:04 -07:00
new: pushed new graph experimental module
This commit is contained in:
parent
ca2e257fbb
commit
826f13e47a
11 changed files with 1480 additions and 0 deletions
47
modules/graph/stack.go
Normal file
47
modules/graph/stack.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package graph
|
||||
|
||||
import "sync"
|
||||
|
||||
type entry struct {
|
||||
data interface{}
|
||||
next *entry
|
||||
}
|
||||
|
||||
type Stack struct {
|
||||
lock *sync.Mutex
|
||||
head *entry
|
||||
Size int
|
||||
}
|
||||
|
||||
func (stk *Stack) Push(data interface{}) {
|
||||
stk.lock.Lock()
|
||||
|
||||
element := new(entry)
|
||||
element.data = data
|
||||
temp := stk.head
|
||||
element.next = temp
|
||||
stk.head = element
|
||||
stk.Size++
|
||||
|
||||
stk.lock.Unlock()
|
||||
}
|
||||
|
||||
func (stk *Stack) Pop() interface{} {
|
||||
if stk.head == nil {
|
||||
return nil
|
||||
}
|
||||
stk.lock.Lock()
|
||||
r := stk.head.data
|
||||
stk.head = stk.head.next
|
||||
stk.Size--
|
||||
|
||||
stk.lock.Unlock()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func NewStack() *Stack {
|
||||
stk := new(Stack)
|
||||
stk.lock = &sync.Mutex{}
|
||||
return stk
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue