From 0be5cd590bc6b69ba526dd970f4e128eef9b5171 Mon Sep 17 00:00:00 2001 From: john Date: Sun, 30 Sep 2018 16:32:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgarray=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E6=95=B0=E7=BB=84Add=E5=8F=AF=E5=8F=98=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/container/garray/garray_sorted_int.go | 4 ++-- g/container/garray/garray_sorted_interface.go | 4 ++-- g/container/garray/garray_sorted_string.go | 4 ++-- geg/other/test.go | 8 ++++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/g/container/garray/garray_sorted_int.go b/g/container/garray/garray_sorted_int.go index fcbbee9f9..36bdaf147 100644 --- a/g/container/garray/garray_sorted_int.go +++ b/g/container/garray/garray_sorted_int.go @@ -54,13 +54,13 @@ func (a *SortedIntArray) Add(values...int) { for _, value := range values { index, cmp := a.Search(value) if a.unique.Val() && cmp == 0 { - return + continue } a.mu.Lock() if index < 0 { a.array = append(a.array, value) a.mu.Unlock() - return + continue } // 加到指定索引后面 if cmp > 0 { diff --git a/g/container/garray/garray_sorted_interface.go b/g/container/garray/garray_sorted_interface.go index d923bf034..3599e63ce 100644 --- a/g/container/garray/garray_sorted_interface.go +++ b/g/container/garray/garray_sorted_interface.go @@ -38,13 +38,13 @@ func (a *SortedArray) Add(values...interface{}) { for _, value := range values { index, cmp := a.Search(value) if a.unique.Val() && cmp == 0 { - return + continue } a.mu.Lock() if index < 0 { a.array = append(a.array, value) a.mu.Unlock() - return + continue } // 加到指定索引后面 if cmp > 0 { diff --git a/g/container/garray/garray_sorted_string.go b/g/container/garray/garray_sorted_string.go index c35743839..b5b546414 100644 --- a/g/container/garray/garray_sorted_string.go +++ b/g/container/garray/garray_sorted_string.go @@ -46,13 +46,13 @@ func (a *SortedStringArray) Add(values...string) { for _, value := range values { index, cmp := a.Search(value) if a.unique.Val() && cmp == 0 { - return + continue } a.mu.Lock() if index < 0 { a.array = append(a.array, value) a.mu.Unlock() - return + continue } // 加到指定索引后面 if cmp > 0 { diff --git a/geg/other/test.go b/geg/other/test.go index 8dc34cff3..3e7a07cfb 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -1,6 +1,9 @@ package main -import "gitee.com/johng/gf/g/container/garray" +import ( + "gitee.com/johng/gf/g/container/garray" + "fmt" +) type S struct { @@ -9,7 +12,8 @@ type S struct { func main() { var source = []string{"59705a2c1fd50736a4c768a1", "597a95ff1fd5073e48bb2272", "597a960f1fd5073e48bb2274"} var CacheChannelKeys *garray.SortedStringArray - CacheChannelKeys = garray.NewSortedStringArray(9999, 9999) + CacheChannelKeys = garray.NewSortedStringArray(0, 0) CacheChannelKeys.Add(source...) + fmt.Println(CacheChannelKeys.Slice()) }