@@ -13,14 +13,14 @@ import (
1313// The zero value is an empty set matrix ready to use.
1414//
1515// SetMatrix values are safe for concurrent use.
16- type SetMatrix [T comparable ] struct {
17- matrix map [string ]mapset.Set [T ]
16+ type SetMatrix [K , V comparable ] struct {
17+ matrix map [K ]mapset.Set [V ]
1818
1919 mu sync.Mutex
2020}
2121
2222// Get returns the members of the set for a specific key as a slice.
23- func (s * SetMatrix [T ]) Get (key string ) ([]T , bool ) {
23+ func (s * SetMatrix [K , V ]) Get (key K ) ([]V , bool ) {
2424 s .mu .Lock ()
2525 defer s .mu .Unlock ()
2626 set , ok := s .matrix [key ]
@@ -31,7 +31,7 @@ func (s *SetMatrix[T]) Get(key string) ([]T, bool) {
3131}
3232
3333// Contains is used to verify if an element is in a set for a specific key.
34- func (s * SetMatrix [T ]) Contains (key string , value T ) (containsElement , setExists bool ) {
34+ func (s * SetMatrix [K , V ]) Contains (key K , value V ) (containsElement , setExists bool ) {
3535 s .mu .Lock ()
3636 defer s .mu .Unlock ()
3737 set , ok := s .matrix [key ]
@@ -43,13 +43,13 @@ func (s *SetMatrix[T]) Contains(key string, value T) (containsElement, setExists
4343
4444// Insert inserts the value in the set of a key and returns whether the value is
4545// inserted (was not already in the set) and the number of elements in the set.
46- func (s * SetMatrix [T ]) Insert (key string , value T ) (inserted bool , cardinality int ) {
46+ func (s * SetMatrix [K , V ]) Insert (key K , value V ) (inserted bool , cardinality int ) {
4747 s .mu .Lock ()
4848 defer s .mu .Unlock ()
4949 set , ok := s .matrix [key ]
5050 if ! ok {
5151 if s .matrix == nil {
52- s .matrix = make (map [string ]mapset.Set [T ])
52+ s .matrix = make (map [K ]mapset.Set [V ])
5353 }
5454 s .matrix [key ] = mapset .NewThreadUnsafeSet (value )
5555 return true , 1
@@ -59,7 +59,7 @@ func (s *SetMatrix[T]) Insert(key string, value T) (inserted bool, cardinality i
5959}
6060
6161// Remove removes the value in the set for a specific key.
62- func (s * SetMatrix [T ]) Remove (key string , value T ) (removed bool , cardinality int ) {
62+ func (s * SetMatrix [K , V ]) Remove (key K , value V ) (removed bool , cardinality int ) {
6363 s .mu .Lock ()
6464 defer s .mu .Unlock ()
6565 set , ok := s .matrix [key ]
@@ -80,7 +80,7 @@ func (s *SetMatrix[T]) Remove(key string, value T) (removed bool, cardinality in
8080}
8181
8282// Cardinality returns the number of elements in the set for a key.
83- func (s * SetMatrix [T ]) Cardinality (key string ) (cardinality int , ok bool ) {
83+ func (s * SetMatrix [K , V ]) Cardinality (key K ) (cardinality int , ok bool ) {
8484 s .mu .Lock ()
8585 defer s .mu .Unlock ()
8686 set , ok := s .matrix [key ]
@@ -93,7 +93,7 @@ func (s *SetMatrix[T]) Cardinality(key string) (cardinality int, ok bool) {
9393
9494// String returns the string version of the set.
9595// The empty string is returned if there is no set for key.
96- func (s * SetMatrix [T ]) String (key string ) (v string , ok bool ) {
96+ func (s * SetMatrix [K , V ]) String (key K ) (v string , ok bool ) {
9797 s .mu .Lock ()
9898 defer s .mu .Unlock ()
9999 set , ok := s .matrix [key ]
@@ -104,10 +104,10 @@ func (s *SetMatrix[T]) String(key string) (v string, ok bool) {
104104}
105105
106106// Keys returns all the keys in the map.
107- func (s * SetMatrix [T ]) Keys () []string {
107+ func (s * SetMatrix [K , V ]) Keys () []K {
108108 s .mu .Lock ()
109109 defer s .mu .Unlock ()
110- keys := make ([]string , 0 , len (s .matrix ))
110+ keys := make ([]K , 0 , len (s .matrix ))
111111 for k := range s .matrix {
112112 keys = append (keys , k )
113113 }
0 commit comments