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
|
||||
}
|
||||
|
||||
// Alias of Len.
|
||||
// Size is alias of Len.
|
||||
func (l *List) Size() int {
|
||||
return l.Len()
|
||||
}
|
||||
|
@ -110,9 +110,16 @@ func (q *Queue) Close() {
|
||||
close(q.closed)
|
||||
}
|
||||
|
||||
// Size returns the length of the queue.
|
||||
func (q *Queue) Size() int {
|
||||
return len(q.C) + q.list.Len()
|
||||
// Len returns the length of the queue.
|
||||
func (q *Queue) Len() (length int) {
|
||||
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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/g/container/gtree"
|
||||
"github.com/gogf/gf/g/util/gutil"
|
||||
"github.com/gogf/gf/g/container/gqueue"
|
||||
"github.com/gogf/gf/g/test/gtest"
|
||||
)
|
||||
|
||||
func main() {
|
||||
expect := map[interface{}]interface{}{
|
||||
20: "val20",
|
||||
6: "val6",
|
||||
10: "val10",
|
||||
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))
|
||||
q1 := gqueue.New(2)
|
||||
q1.Push(1)
|
||||
q1.Push(2)
|
||||
gtest.Assert(q1.Size(),2)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user