fix issue in gqueue.Size

This commit is contained in:
John 2019-06-15 18:30:09 +08:00
parent d5d6b8c303
commit c02f502bd8
3 changed files with 18 additions and 30 deletions

View File

@ -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()
} }

View File

@ -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()
}

View File

@ -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))
} }