Merge pull request #1361 from jroam/fixbug-garray

This commit is contained in:
John Guo 2021-08-05 13:09:31 +08:00 committed by GitHub
commit f22aa1b5d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 13 deletions

View File

@ -36,7 +36,7 @@ func New(safe ...bool) *Array {
return NewArraySize(0, 0, safe...)
}
// See New.
// NewArray is alias of New, please see New.
func NewArray(safe ...bool) *Array {
return NewArraySize(0, 0, safe...)
}
@ -422,7 +422,7 @@ func (a *Array) SubSlice(offset int, length ...int) []interface{} {
}
}
// See PushRight.
// Append is alias of PushRight, please See PushRight.
func (a *Array) Append(value ...interface{}) *Array {
a.PushRight(value...)
return a

View File

@ -149,10 +149,7 @@ func (a *IntArray) Sort(reverse ...bool) *IntArray {
defer a.mu.Unlock()
if len(reverse) > 0 && reverse[0] {
sort.Slice(a.array, func(i, j int) bool {
if a.array[i] < a.array[j] {
return false
}
return true
return a.array[i] >= a.array[j]
})
} else {
sort.Ints(a.array)
@ -427,7 +424,7 @@ func (a *IntArray) SubSlice(offset int, length ...int) []int {
}
}
// See PushRight.
// Append is alias of PushRight,please See PushRight.
func (a *IntArray) Append(value ...int) *IntArray {
a.mu.Lock()
a.array = append(a.array, value...)

View File

@ -136,10 +136,7 @@ func (a *StrArray) Sort(reverse ...bool) *StrArray {
defer a.mu.Unlock()
if len(reverse) > 0 && reverse[0] {
sort.Slice(a.array, func(i, j int) bool {
if strings.Compare(a.array[i], a.array[j]) < 0 {
return false
}
return true
return strings.Compare(a.array[i], a.array[j]) >= 0
})
} else {
sort.Strings(a.array)
@ -414,7 +411,7 @@ func (a *StrArray) SubSlice(offset int, length ...int) []string {
}
}
// See PushRight.
// Append is alias of PushRight,please See PushRight.
func (a *StrArray) Append(value ...string) *StrArray {
a.mu.Lock()
a.array = append(a.array, value...)

View File

@ -453,7 +453,7 @@ func (a *SortedArray) binSearch(value interface{}, lock bool) (index int, result
mid := 0
cmp := -2
for min <= max {
mid = min + int((max-min)/2)
mid = min + (max-min)/2
cmp = a.getComparator()(value, a.array[mid])
switch {
case cmp < 0: