Implemented TreeMap Example

This commit is contained in:
huangqian 2021-11-21 12:44:59 +08:00
parent 8ea4b71e7a
commit b58c5311d0
2 changed files with 29 additions and 1 deletions

View File

@ -8,6 +8,7 @@ package gmap_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/util/gutil"
"github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gmap"
) )
@ -280,3 +281,31 @@ func ExampleNewListMapFrom() {
// {"key1":"var1","key2":"var2"} // {"key1":"var1","key2":"var2"}
// {"key1":"var1","key2":"var2"} // {"key1":"var1","key2":"var2"}
} }
func ExampleNewTreeMap() {
m := gmap.NewTreeMap(gutil.ComparatorString)
m.Set("key2", "var2")
m.Set("key1", "var1")
fmt.Println(m.Map())
// Output:
// map[key1:var1 key2:var2]
}
func ExampleNewTreeMapFrom() {
m := gmap.NewTreeMap(gutil.ComparatorString)
m.Set("key2", "var2")
m.Set("key1", "var1")
fmt.Println(m.Map())
n := gmap.NewListMapFrom(m.Map(), true)
fmt.Println(n.Map())
// Output:
// map[key1:var1 key2:var2]
// map[key1:var1 key2:var2]
}

View File

@ -1 +0,0 @@
package gmap