123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package UI
- import (
- "sync"
- )
- type FolderStack struct {
- lock *sync.Mutex
- head *element
- Size int
- RootPath string
- }
- func (stk *FolderStack) Push(data interface{}) {
- stk.lock.Lock()
- element := new(element)
- element.data = data
- temp := stk.head
- element.next = temp
- stk.head = element
- stk.Size++
- stk.lock.Unlock()
- }
- func (stk *FolderStack) 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 (stk *FolderStack) SetRootPath(path string) {
- stk.RootPath = path
- }
- func (stk *FolderStack) Length() int {
- return stk.Size
- }
- func (stk *FolderStack) Last() string {
- idx := stk.Length() - 1
- if idx < 0 {
- return stk.RootPath
- } else {
- return stk.head.data.(string)
- }
- }
- func (stk *FolderStack) Clear() {
- for stk.Length() > 0 {
- stk.Pop()
- }
- }
- func NewFolderStack() *FolderStack {
- stk := new(FolderStack)
- stk.lock = &sync.Mutex{}
- return stk
- }
|