-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimized the fine-grained lock and fixed some bugs
- Loading branch information
1 parent
2ce9d33
commit 071a912
Showing
2 changed files
with
85 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package orderMap_test | ||
|
||
import ( | ||
orderMap "github.com/RealFax/order-map" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
var ( | ||
testMap = orderMap.New[string, string]() | ||
) | ||
|
||
func init() { | ||
testMap.Store("hello", "bonjour") | ||
} | ||
|
||
func TestMap_Store(t *testing.T) { | ||
testMap.Store("hello1", "bonjour") | ||
} | ||
|
||
func TestMap_Load(t *testing.T) { | ||
val, ok := testMap.Load("hello") | ||
t.Log("State:", ok, ", Value:", val) | ||
} | ||
|
||
func TestMap_Delete(t *testing.T) { | ||
testMap.Store("hello1", "bonjour") | ||
val, ok := testMap.Load("hello1") | ||
t.Log("State:", ok, ", Value:", val) | ||
|
||
testMap.Delete("hello1") | ||
val, ok = testMap.Load("hello1") | ||
t.Log("State:", ok, ", Value:", val) | ||
} | ||
|
||
func TestMap_Range(t *testing.T) { | ||
for i := 0; i < 5; i++ { | ||
testMap.Store("test"+strconv.Itoa(i), "range!") | ||
} | ||
|
||
testMap.Range(func(key string, value string) bool { | ||
t.Log("Key:", key, ", Value:", value) | ||
return true | ||
}) | ||
} | ||
|
||
func TestMap_DisorderedRange(t *testing.T) { | ||
for i := 0; i < 5; i++ { | ||
testMap.Store("_test"+strconv.Itoa(i), "disordered_range!") | ||
} | ||
|
||
testMap.DisorderedRange(func(key string, value string) bool { | ||
t.Log("Key:", key, ", Value:", value) | ||
return true | ||
}) | ||
} | ||
|
||
func BenchmarkMap_Store(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
testMap.Store("key", "value") | ||
} | ||
} | ||
|
||
func BenchmarkMap_Load(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
testMap.Load("hello") | ||
} | ||
} |