mirror of
https://gitee.com/johng/gf.git
synced 2024-12-01 11:48:09 +08:00
fix issue in gqueue.Size
This commit is contained in:
parent
d5d6b8c303
commit
c02f502bd8
@ -209,7 +209,7 @@ func (l *List) Len() (length int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alias of Len.
|
// Size is alias of Len.
|
||||||
func (l *List) Size() int {
|
func (l *List) Size() int {
|
||||||
return l.Len()
|
return l.Len()
|
||||||
}
|
}
|
||||||
|
@ -110,9 +110,16 @@ func (q *Queue) Close() {
|
|||||||
close(q.closed)
|
close(q.closed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size returns the length of the queue.
|
// Len returns the length of the queue.
|
||||||
func (q *Queue) Size() int {
|
func (q *Queue) Len() (length int) {
|
||||||
return len(q.C) + q.list.Len()
|
if q.list != nil {
|
||||||
|
length += q.list.Len()
|
||||||
|
}
|
||||||
|
length += len(q.C)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size is alias of Len.
|
||||||
|
func (q *Queue) Size() int {
|
||||||
|
return q.Len()
|
||||||
|
}
|
||||||
|
@ -1,33 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/gogf/gf/g/container/gqueue"
|
||||||
"github.com/gogf/gf/g/container/gtree"
|
"github.com/gogf/gf/g/test/gtest"
|
||||||
"github.com/gogf/gf/g/util/gutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
expect := map[interface{}]interface{}{
|
q1 := gqueue.New(2)
|
||||||
20: "val20",
|
q1.Push(1)
|
||||||
6: "val6",
|
q1.Push(2)
|
||||||
10: "val10",
|
gtest.Assert(q1.Size(),2)
|
||||||
12: "val12",
|
|
||||||
1: "val1",
|
|
||||||
15: "val15",
|
|
||||||
19: "val19",
|
|
||||||
8: "val8",
|
|
||||||
4: "val4"}
|
|
||||||
m := gtree.NewAVLTreeFrom(gutil.ComparatorInt, expect)
|
|
||||||
m.Print()
|
|
||||||
|
|
||||||
//m := avltree.NewWithIntComparator()
|
|
||||||
//m.Remove()
|
|
||||||
fmt.Println(1, m.Remove(1))// 应该输出val1,但输出nil
|
|
||||||
fmt.Println(2, m.Remove(1))
|
|
||||||
fmt.Println(3, m.Get(1))
|
|
||||||
|
|
||||||
fmt.Println(4, m.Remove(20))// 应该输出val20,但输出nil
|
|
||||||
fmt.Println(5, m.Remove(20))
|
|
||||||
fmt.Println(6, m.Get(20))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user