Skip to content

Commit

Permalink
add Group.GetElements() method
Browse files Browse the repository at this point in the history
add Group.GetElements() method
  • Loading branch information
werbenhu committed Apr 6, 2023
1 parent 936e907 commit 1412bf7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,15 @@ func (b *Group) Match(key string) (string, []byte, error) {
}
return "", nil, ErrNoResultMatched
}

func (b *Group) GetElements() []*Element {
b.RLock()
defer b.RUnlock()

els := make([]*Element, 0)
for _, e := range b.Elements {
els = append(els, e)
}

return els
}
18 changes: 18 additions & 0 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ func TestGroupAll(t *testing.T) {
}
}

func TestGroupGetElements(t *testing.T) {
group := NewGroup("test", 10000)
group.Insert("192.168.1.100:1883", []byte("werbenhu100"))
group.Insert("192.168.1.101:1883", []byte("werbenhu101"))

els := group.GetElements()
assert.Equal(t, []*Element{
{
Key: "192.168.1.100:1883",
Payload: []byte("werbenhu100"),
},
{
Key: "192.168.1.101:1883",
Payload: []byte("werbenhu101"),
},
}, els)
}

func BenchmarkGroupHash(b *testing.B) {
b.ResetTimer()
key := "192.168.1.100:1883"
Expand Down

0 comments on commit 1412bf7

Please sign in to comment.