mirror of
https://github.com/cowardmrx/maps.git
synced 2025-04-21 00:00:41 +08:00
Compare commits
No commits in common. "master" and "v1.0.0" have entirely different histories.
14
README.md
14
README.md
@ -28,20 +28,8 @@ maps.Values()
|
|||||||
// GetMapsOriginMap get this maps origin data return a map[string]interface
|
// GetMapsOriginMap get this maps origin data return a map[string]interface
|
||||||
maps.OriginMap()
|
maps.OriginMap()
|
||||||
|
|
||||||
// SortKey sort this maps by keys asc
|
// SortKey sort this maps by keys
|
||||||
maps.SortKey()
|
maps.SortKey()
|
||||||
|
|
||||||
// other sort
|
|
||||||
// sort by desc
|
|
||||||
sort.Slice(maps.Keys,func (i,j int) bool {
|
|
||||||
return maps.Keys()[i] > maps.Keys()[j]
|
|
||||||
})
|
|
||||||
|
|
||||||
// sort by asc
|
|
||||||
sort.Slice(maps.Keys,func (i,j int) bool {
|
|
||||||
return maps.Keys()[i] < maps.Keys()[j]
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// other example ./maps_test.go
|
// other example ./maps_test.go
|
||||||
```
|
```
|
7
maps.go
7
maps.go
@ -5,6 +5,13 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// SortAsc sort by asc
|
||||||
|
SortAsc = "asc"
|
||||||
|
// SortDesc sort by desc
|
||||||
|
SortDesc = "desc"
|
||||||
|
)
|
||||||
|
|
||||||
type maps struct {
|
type maps struct {
|
||||||
rw sync.RWMutex
|
rw sync.RWMutex
|
||||||
Key []string
|
Key []string
|
||||||
|
14
maps_test.go
14
maps_test.go
@ -62,17 +62,3 @@ func TestSortKey(t *testing.T) {
|
|||||||
|
|
||||||
fmt.Println(a)
|
fmt.Println(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSort(t *testing.T) {
|
|
||||||
maps := NewMaps()
|
|
||||||
|
|
||||||
a := maps.Set("key3", "value1").Set("key4", "value 2").Set("key1", "value 3")
|
|
||||||
|
|
||||||
sort.Slice(a.Keys(), func(i, j int) bool {
|
|
||||||
return a.Keys()[i] > a.Keys()[j]
|
|
||||||
})
|
|
||||||
|
|
||||||
fmt.Println(a.Keys())
|
|
||||||
fmt.Println(a.Values())
|
|
||||||
fmt.Println(a.OriginMap())
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user