diff --git a/g/container/glist/glist.go b/g/container/glist/glist.go index cef9b7c01..fa0361702 100644 --- a/g/container/glist/glist.go +++ b/g/container/glist/glist.go @@ -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() } diff --git a/g/container/gqueue/gqueue.go b/g/container/gqueue/gqueue.go index 9ec7b12c7..eb4b2a340 100644 --- a/g/container/gqueue/gqueue.go +++ b/g/container/gqueue/gqueue.go @@ -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() +} diff --git a/geg/other/test.go b/geg/other/test.go index 57f880c51..49c122b37 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -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) }