|
|
@ -2,6 +2,35 @@ package starmap
|
|
|
|
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (stack *StarStack) Count() int {
|
|
|
|
|
|
|
|
stack.kvPushmu.Lock()
|
|
|
|
|
|
|
|
defer stack.kvPushmu.Unlock()
|
|
|
|
|
|
|
|
return len(stack.kvStack)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (stack *StarStack) Push(val interface{}) error {
|
|
|
|
|
|
|
|
stack.kvPushmu.Lock()
|
|
|
|
|
|
|
|
defer stack.kvPushmu.Unlock()
|
|
|
|
|
|
|
|
stack.kvStack = append(stack.kvStack, val)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (stack *StarStack) Pop() (interface{}, error) {
|
|
|
|
|
|
|
|
stack.kvPushmu.Lock()
|
|
|
|
|
|
|
|
defer stack.kvPushmu.Unlock()
|
|
|
|
|
|
|
|
if len(stack.kvStack) == 0 {
|
|
|
|
|
|
|
|
return nil, errors.New("Empty Stacks")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
val := stack.kvStack[0]
|
|
|
|
|
|
|
|
stack.kvStack = stack.kvStack[1:]
|
|
|
|
|
|
|
|
return val, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (stack *StarStack) MustPop() interface{} {
|
|
|
|
|
|
|
|
val, _ := stack.Pop()
|
|
|
|
|
|
|
|
return val
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Get(key string) (interface{}, error) {
|
|
|
|
func Get(key string) (interface{}, error) {
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
kvmu.RLock()
|
|
|
|
kvmu.RLock()
|
|
|
@ -13,6 +42,11 @@ func Get(key string) (interface{}, error) {
|
|
|
|
return data, err
|
|
|
|
return data, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func MustGet(key string) interface{} {
|
|
|
|
|
|
|
|
result, _ := Get(key)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Store(key string, value interface{}) error {
|
|
|
|
func Store(key string, value interface{}) error {
|
|
|
|
kvmu.Lock()
|
|
|
|
kvmu.Lock()
|
|
|
|
defer kvmu.Unlock()
|
|
|
|
defer kvmu.Unlock()
|
|
|
|