-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e851c8
commit f64aecd
Showing
7 changed files
with
62 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,36 @@ | ||
package structx | ||
|
||
import ( | ||
"github.com/xgzlucario/rotom/dict" | ||
"github.com/cockroachdb/swiss" | ||
) | ||
|
||
type Map struct { | ||
m *dict.Dict | ||
m *swiss.Map[string, []byte] | ||
} | ||
|
||
func defaultOptions() dict.Options { | ||
options := dict.DefaultOptions | ||
options.ShardCount = 1 | ||
options.IndexSize = 8 | ||
options.BufferSize = 32 | ||
return options | ||
func NewMap() *Map { | ||
return &Map{m: swiss.New[string, []byte](8)} | ||
} | ||
|
||
func NewMap() (s *Map) { | ||
return &Map{m: dict.New(defaultOptions())} | ||
} | ||
|
||
func (m *Map) Get(key string) ([]byte, int64, bool) { | ||
func (m *Map) Get(key string) ([]byte, bool) { | ||
return m.m.Get(key) | ||
} | ||
|
||
func (m *Map) Set(key string, val []byte) (newField bool) { | ||
return m.m.Set(key, val) | ||
func (m *Map) Set(key string, val []byte) bool { | ||
_, ok := m.m.Get(key) | ||
m.m.Put(key, val) | ||
return !ok | ||
} | ||
|
||
func (m *Map) Remove(key string) bool { | ||
return m.m.Remove(key) | ||
_, ok := m.m.Get(key) | ||
m.m.Delete(key) | ||
return ok | ||
} | ||
|
||
func (m *Map) Scan(fn func(key string, value []byte)) { | ||
m.m.Scan(func(key string, val []byte, _ int64) (next bool) { | ||
m.m.All(func(key string, val []byte) (next bool) { | ||
fn(key, val) | ||
return true | ||
}) | ||
} | ||
|
||
func (m *Map) Len() (n int) { | ||
return m.m.GetStats().Len | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,19 @@ | ||
package structx | ||
|
||
import ( | ||
mapset "github.com/deckarep/golang-set/v2" | ||
) | ||
import "github.com/cockroachdb/swiss" | ||
|
||
// Set | ||
type Set struct { | ||
mapset.Set[string] | ||
m *swiss.Map[string, struct{}] | ||
} | ||
|
||
// NewSet | ||
func NewSet() *Set { | ||
return &Set{mapset.NewSet[string]()} | ||
return &Set{m: swiss.New[string, struct{}](8)} | ||
} | ||
|
||
// Clone | ||
func (s *Set) Clone() *Set { | ||
return &Set{s.Set.Clone()} | ||
} | ||
|
||
// Union | ||
func (s *Set) Union(other *Set) { | ||
s.Set = s.Set.Union(other.Set) | ||
} | ||
|
||
// Intersect | ||
func (s *Set) Intersect(other *Set) { | ||
s.Set = s.Set.Intersect(other.Set) | ||
} | ||
|
||
// Difference | ||
func (s *Set) Difference(other *Set) { | ||
s.Set = s.Set.SymmetricDifference(other.Set) | ||
func (s *Set) Add(key string) bool { | ||
if _, ok := s.m.Get(key); ok { | ||
return false | ||
} | ||
s.m.Put(key, struct{}{}) | ||
return true | ||
} |