修复garray排序数组Add可变参数问题

This commit is contained in:
john
2018-09-30 16:32:12 +08:00
parent bd0df135c8
commit 0be5cd590b
4 changed files with 12 additions and 8 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

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