ExtraArg: "",
DataType: "[]E",
Funcs: template.FuncMap{
- "GreaterOrEqual": func(name, i, j string) string {
- return fmt.Sprintf("(%s[%s] >= %s[%s])", name, i, name, j)
- },
"Less": func(name, i, j string) string {
return fmt.Sprintf("(%s[%s] < %s[%s])", name, i, name, j)
},
ExtraArg: ", less",
DataType: "[]E",
Funcs: template.FuncMap{
- "GreaterOrEqual": func(name, i, j string) string {
- return fmt.Sprintf("!less(%s[%s], %s[%s])", name, i, name, j)
- },
"Less": func(name, i, j string) string {
return fmt.Sprintf("less(%s[%s], %s[%s])", name, i, name, j)
},
ExtraArg: "",
DataType: "Interface",
Funcs: template.FuncMap{
- "GreaterOrEqual": func(name, i, j string) string {
- return fmt.Sprintf("!%s.Less(%s, %s)", name, i, j)
- },
"Less": func(name, i, j string) string {
return fmt.Sprintf("%s.Less(%s, %s)", name, i, j)
},
ExtraArg: "",
DataType: "lessSwap",
Funcs: template.FuncMap{
- "GreaterOrEqual": func(name, i, j string) string {
- return fmt.Sprintf("!%s.Less(%s, %s)", name, i, j)
- },
"Less": func(name, i, j string) string {
return fmt.Sprintf("%s.Less(%s, %s)", name, i, j)
},
if child+1 < hi && {{Less "data" "first+child" "first+child+1"}} {
child++
}
- if {{GreaterOrEqual "data" "first+root" "first+child"}} {
+ if !{{Less "data" "first+root" "first+child"}} {
return
}
{{Swap "data" "first+root" "first+child"}}
// Probably the slice contains many duplicate elements, partition the slice into
// elements equal to and elements greater than the pivot.
- if a > 0 && {{GreaterOrEqual "data" "a-1" "pivot"}} {
+ if a > 0 && !{{Less "data" "a-1" "pivot"}} {
mid := partitionEqual{{.FuncSuffix}}(data, a, b, pivot {{.ExtraArg}})
a = mid
continue
for i <= j && {{Less "data" "i" "a"}} {
i++
}
- for i <= j && {{GreaterOrEqual "data" "j" "a"}} {
+ for i <= j && !{{Less "data" "j" "a"}} {
j--
}
if i > j {
for i <= j && {{Less "data" "i" "a"}} {
i++
}
- for i <= j && {{GreaterOrEqual "data" "j" "a"}} {
+ for i <= j && !{{Less "data" "j" "a"}} {
j--
}
if i > j {
i, j := a+1, b-1 // i and j are inclusive of the elements remaining to be partitioned
for {
- for i <= j && {{GreaterOrEqual "data" "a" "i"}} {
+ for i <= j && !{{Less "data" "a" "i"}} {
i++
}
for i <= j && {{Less "data" "a" "j"}} {
)
i := a + 1
for j := 0; j < maxSteps; j++ {
- for i < b && {{GreaterOrEqual "data" "i" "i-1"}} {
+ for i < b && !{{Less "data" "i" "i-1"}} {
i++
}
// Shift the smaller one to the left.
if i-a >= 2 {
for j := i - 1; j >= 1; j-- {
- if {{GreaterOrEqual "data" "j" "j-1"}} {
+ if !{{Less "data" "j" "j-1"}} {
break
}
{{Swap "data" "j" "j-1"}}
// Shift the greater one to the right.
if b-i >= 2 {
for j := i + 1; j < b; j++ {
- if {{GreaterOrEqual "data" "j" "j-1"}} {
+ if !{{Less "data" "j" "j-1"}} {
break
}
{{Swap "data" "j" "j-1"}}
j := m
for i < j {
h := int(uint(i+j) >> 1)
- if {{GreaterOrEqual "data" "m" "h"}} {
+ if !{{Less "data" "m" "h"}} {
i = h + 1
} else {
j = h
for start < r {
c := int(uint(start+r) >> 1)
- if {{GreaterOrEqual "data" "p-c" "c"}} {
+ if !{{Less "data" "p-c" "c"}} {
start = c + 1
} else {
r = c