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