github.com/chain5j/chain5j-pkg@v1.0.7/collection/maps/treemap/v2/examples_test.go (about) 1 package treemap 2 3 import ( 4 "fmt" 5 ) 6 7 func ExampleTreeMap_Set() { 8 tr := New[int, string]() 9 tr.Set(0, "hello") 10 v, _ := tr.Get(0) 11 fmt.Println(v) 12 // Output: 13 // hello 14 } 15 16 func ExampleTreeMap_Del() { 17 tr := New[int, string]() 18 tr.Set(0, "hello") 19 tr.Del(0) 20 fmt.Println(tr.Contains(0)) 21 // Output: 22 // false 23 } 24 25 func ExampleTreeMap_Get() { 26 tr := New[int, string]() 27 tr.Set(0, "hello") 28 v, _ := tr.Get(0) 29 fmt.Println(v) 30 // Output: 31 // hello 32 } 33 34 func ExampleTreeMap_Contains() { 35 tr := New[int, string]() 36 tr.Set(0, "hello") 37 fmt.Println(tr.Contains(0)) 38 // Output: 39 // true 40 } 41 42 func ExampleTreeMap_Len() { 43 tr := New[int, string]() 44 tr.Set(0, "hello") 45 tr.Set(1, "world") 46 fmt.Println(tr.Len()) 47 // Output: 48 // 2 49 } 50 51 func ExampleTreeMap_Clear() { 52 tr := New[int, string]() 53 tr.Set(0, "hello") 54 tr.Set(1, "world") 55 tr.Clear() 56 fmt.Println(tr.Len()) 57 // Output: 58 // 0 59 } 60 61 func ExampleTreeMap_Iterator() { 62 tr := New[int, string]() 63 tr.Set(1, "one") 64 tr.Set(2, "two") 65 tr.Set(3, "three") 66 for it := tr.Iterator(); it.Valid(); it.Next() { 67 fmt.Println(it.Key(), "-", it.Value()) 68 } 69 // Output: 70 // 1 - one 71 // 2 - two 72 // 3 - three 73 } 74 75 func ExampleTreeMap_Reverse() { 76 tr := New[int, string]() 77 tr.Set(1, "one") 78 tr.Set(2, "two") 79 tr.Set(3, "three") 80 for it := tr.Reverse(); it.Valid(); it.Next() { 81 fmt.Println(it.Key(), "-", it.Value()) 82 } 83 // Output: 84 // 3 - three 85 // 2 - two 86 // 1 - one 87 } 88 89 func ExampleTreeMap_Range() { 90 tr := New[int, string]() 91 tr.Set(1, "one") 92 tr.Set(2, "two") 93 tr.Set(3, "three") 94 for it, end := tr.Range(1, 2); it != end; it.Next() { 95 fmt.Println(it.Key(), "-", it.Value()) 96 } 97 // Output: 98 // 1 - one 99 // 2 - two 100 }