/
map.go
48 lines (41 loc) · 1 KB
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2019 Alexey Krivonogov. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.
package vm
import (
"fmt"
"github.com/gentee/gentee/core"
)
// boolºMap converts map to bool
func boolºMap(pmap *core.Map) int64 {
if len(pmap.Data) == 0 {
return 0
}
return 1
}
// DelºMapStr deletes key and value from the map
func DelºMapStr(pmap *core.Map, key string) *core.Map {
delete(pmap.Data, key)
for i, ikey := range pmap.Keys {
if ikey == key {
pmap.Keys = append(pmap.Keys[:i], pmap.Keys[i+1:]...)
break
}
}
return pmap
}
// IsKeyºMapStr returns true if there is the key in the map
func IsKeyºMapStr(pmap *core.Map, key string) int64 {
_, ok := pmap.Data[key]
if ok {
return 1
}
return 0
}
// KeyºMapInt returns the key by the index
func KeyºMapInt(pmap *core.Map, index int64) (string, error) {
if index >= int64(len(pmap.Keys)) {
return ``, fmt.Errorf(ErrorText(ErrIndexOut))
}
return pmap.Keys[index], nil
}