@@ -33,40 +33,39 @@ import (
3333 " github.com/gravitton/x/container/heap"
3434)
3535
36-
3736type priorityItem struct {
38- value string
39- priority int
40- index int
37+ value string
38+ priority int
39+ index int
4140}
4241
4342func (i *priorityItem ) Compare (item *priorityItem ) int {
44- return cmp.Compare (i.priority , item.priority )
43+ return cmp.Compare (i.priority , item.priority )
4544}
4645
4746func (i *priorityItem ) setIndex (index int ) {
48- i.index = index
47+ i.index = index
4948}
5049
5150func main () {
52- pq := heap.NewComparable [priorityItem]()
53- pq.SetIndex ((*priorityItem).setIndex )
54-
55- pq.Push (&priorityItem{value: " banana" , priority: 3 })
56- pq.Push (&priorityItem{value: " apple" , priority: 2 })
57- pq.Push (&priorityItem{value: " pear" , priority: 4 })
58-
59- orange := &priorityItem{value: " orange" , priority: 1 }
60- pq.Push (orange)
61- orange.priority = 5
62- pq.Fix (orange.index )
63-
64- for pq.Len () > 0 {
65- item := pq.Pop ()
66- fmt.Printf (" %.2d :%s \n " , item.priority , item.value )
67- }
68-
69- // 02:apple 03:banana 04:pear 05:orange
51+ pq := heap.NewComparable [priorityItem]()
52+ pq.SetIndex ((*priorityItem).setIndex )
53+
54+ pq.Push (&priorityItem{value: " banana" , priority: 3 })
55+ pq.Push (&priorityItem{value: " apple" , priority: 2 })
56+ pq.Push (&priorityItem{value: " pear" , priority: 4 })
57+
58+ orange := &priorityItem{value: " orange" , priority: 1 }
59+ pq.Push (orange)
60+ orange.priority = 5
61+ pq.Fix (orange.index )
62+
63+ for pq.Len () > 0 {
64+ item := pq.Pop ()
65+ fmt.Printf (" %.2d :%s \n " , item.priority , item.value )
66+ }
67+
68+ // 02:apple 03:banana 04:pear 05:orange
7069}
7170```
7271
@@ -84,17 +83,17 @@ import (
8483)
8584
8685func main () {
87- q := queue.New [int ]()
88- q.Push (2 )
89- q.Push (3 )
90- q.Push (1 )
86+ q := queue.New [int ]()
87+ q.Push (2 )
88+ q.Push (3 )
89+ q.Push (1 )
9190
92- for q.Len () > 0 {
93- val := q.Pop ()
94- fmt.Println (val)
95- }
91+ for q.Len () > 0 {
92+ val := q.Pop ()
93+ fmt.Println (val)
94+ }
9695
97- // 2 3 1
96+ // 2 3 1
9897}
9998```
10099
@@ -113,13 +112,13 @@ import (
113112)
114113
115114func main () {
116- sf := slices.Map ([]float64 {1.1 , 2.6 , 3.4 }, math.Round )
117- si := slices.Map (sf, func (x float64 ) int {
118- return 10 + int (x)
119- })
115+ sf := slices.Map ([]float64 {1.1 , 2.6 , 3.4 }, math.Round )
116+ si := slices.Map (sf, func (x float64 ) int {
117+ return 10 + int (x)
118+ })
120119
121- fmt.Println (si)
122- // [11, 13, 13]
120+ fmt.Println (si)
121+ // [11, 13, 13]
123122}
124123```
125124## Credits
0 commit comments