Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkwork committed Dec 1, 2024
1 parent 4370bf2 commit 6b6185b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mylog/safeStream_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"unicode/utf8"

"github.com/dc0d/caseconv"

"github.com/rivo/uniseg"
"mvdan.cc/gofumpt/format"
)
Expand Down
7 changes: 7 additions & 0 deletions safemap/safemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ func (s *M[K, V]) Has(key K) (exists bool) {
return exists
}

func (s *M[K, V]) GetMust(key K) (value V) {
get, exist := s.Get(key)
if !exist {
panic("key not found")
}
return get
}
func (s *M[K, V]) Get(key K) (value V, exist bool) {
s.RLock()
defer s.RUnlock()
Expand Down
8 changes: 4 additions & 4 deletions safemap/safemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestSafeMap_StoreAndLoad(t *testing.T) {
sm := New[int, string]()
sm.Update(1, "one")

value, ok := sm.Get(1)
value, ok := sm.GetMust(1)

Check failure on line 45 in safemap/safemap_test.go

View workflow job for this annotation

GitHub Actions / Test on multiple OS (ubuntu-latest)

assignment mismatch: 2 variables but sm.GetMust returns 1 value

Check failure on line 45 in safemap/safemap_test.go

View workflow job for this annotation

GitHub Actions / Test on multiple OS (macos-latest)

assignment mismatch: 2 variables but sm.GetMust returns 1 value
if !ok || value != "one" {
t.Errorf("expected 'one', got '%v'", value)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestSafeMap_StoreAndLoad_Ordered(t *testing.T) {
sm := New[int, string](Ordered)
sm.Update(1, "one")

value, ok := sm.Get(1)
value, ok := sm.GetMust(1)

Check failure on line 131 in safemap/safemap_test.go

View workflow job for this annotation

GitHub Actions / Test on multiple OS (ubuntu-latest)

assignment mismatch: 2 variables but sm.GetMust returns 1 value

Check failure on line 131 in safemap/safemap_test.go

View workflow job for this annotation

GitHub Actions / Test on multiple OS (macos-latest)

assignment mismatch: 2 variables but sm.GetMust returns 1 value
if !ok || value != "one" {
t.Errorf("expected 'one', got '%v'", value)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func BenchmarkSafeMap_Load(b *testing.B) {
sm.Update(1, "value")
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.Get(1)
sm.GetMust(1)
}
}

Expand All @@ -257,7 +257,7 @@ func BenchmarkSafeMap_Ordered_Load(b *testing.B) {
sm.Update(1, "value")
b.ResetTimer()
for i := 0; i < b.N; i++ {
sm.Get(1)
sm.GetMust(1)
}
}

Expand Down

0 comments on commit 6b6185b

Please sign in to comment.