blob: ac256be2536a0fc780ed2029897c2e20803b4b2c (
plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
package storage
import (
"sync"
"github.com/spiral/roadrunner/v2/pkg/bst"
)
type Storage struct {
sync.RWMutex
BST bst.Storage
}
func NewStorage() *Storage {
return &Storage{
BST: bst.NewBST(),
}
}
func (s *Storage) InsertMany(connID string, topics []string) {
s.Lock()
defer s.Unlock()
for i := 0; i < len(topics); i++ {
s.BST.Insert(connID, topics[i])
}
}
func (s *Storage) Insert(connID string, topic string) {
s.Lock()
defer s.Unlock()
s.BST.Insert(connID, topic)
}
func (s *Storage) RemoveMany(connID string, topics []string) {
s.Lock()
defer s.Unlock()
for i := 0; i < len(topics); i++ {
s.BST.Remove(connID, topics[i])
}
}
func (s *Storage) Remove(connID string, topic string) {
s.Lock()
defer s.Unlock()
s.BST.Remove(connID, topic)
}
// GetByPtrTS Thread safe get
func (s *Storage) GetByPtrTS(topics []string, res map[string]struct{}) {
s.Lock()
defer s.Unlock()
for i := 0; i < len(topics); i++ {
d := s.BST.Get(topics[i])
if len(d) > 0 {
for ii := range d {
res[ii] = struct{}{}
}
}
}
}
func (s *Storage) GetByPtr(topics []string, res map[string]struct{}) {
s.RLock()
defer s.RUnlock()
for i := 0; i < len(topics); i++ {
d := s.BST.Get(topics[i])
if len(d) > 0 {
for ii := range d {
res[ii] = struct{}{}
}
}
}
}
|