-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.go
More file actions
54 lines (45 loc) · 782 Bytes
/
table.go
File metadata and controls
54 lines (45 loc) · 782 Bytes
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
49
50
51
52
53
54
package dev
import "sync"
//路由表
type table struct {
mu sync.RWMutex
data map[string]string
}
func newTable() *table {
return &table{
data: make(map[string]string),
}
}
//设置数据
func (t *table) Set(key string, val string) {
t.mu.Lock()
t.data[key] = val
t.mu.Unlock()
}
//获取数据
func (t *table) Get(key string) string {
t.mu.RLock()
defer t.mu.RUnlock()
return t.data[key]
}
//获取数据
func (t *table) GetAll() map[string]string {
t.mu.RLock()
defer t.mu.RUnlock()
return t.data
}
//删除
func (t *table) DelAll() {
t.mu.Lock()
t.data = make(map[string]string)
t.mu.Unlock()
}
//长度
func (t *table) Len() int {
return len(t.data)
}
//Key是否存在
func (t *table) Exists(key string) bool {
_, ok := t.data[key]
return ok
}