diff options
author | Valery Piashchynski <[email protected]> | 2021-06-05 13:21:35 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-05 13:21:35 +0300 |
commit | d0ec24066b5fbb4e3accc9c45f72f7c638b35dba (patch) | |
tree | 7e6ec1a320f596b31f205caee5d5753eaa42f4ff /pkg/bst | |
parent | 0323e070103cc2c30d2cdfb12719d753acafe151 (diff) |
- Websockets bug fixing and polishing
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'pkg/bst')
-rw-r--r-- | pkg/bst/bst.go | 16 | ||||
-rw-r--r-- | pkg/bst/interface.go | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/pkg/bst/bst.go b/pkg/bst/bst.go index 664937ba..f8426b12 100644 --- a/pkg/bst/bst.go +++ b/pkg/bst/bst.go @@ -52,6 +52,22 @@ func (b *BST) Insert(uuid string, topic string) { } } +func (b *BST) Contains(topic string) bool { + curr := b + for curr != nil { + switch { + case topic < curr.topic: + curr = curr.left + case topic > curr.topic: + curr = curr.right + case topic == curr.topic: + return true + } + } + + return false +} + func (b *BST) Get(topic string) map[string]struct{} { curr := b for curr != nil { diff --git a/pkg/bst/interface.go b/pkg/bst/interface.go index ecf40414..95b03e11 100644 --- a/pkg/bst/interface.go +++ b/pkg/bst/interface.go @@ -8,4 +8,6 @@ type Storage interface { Remove(uuid, topic string) // Get will return all connections associated with the topic Get(topic string) map[string]struct{} + // Contains checks if the BST contains a topic + Contains(topic string) bool } |