package sort
func ( lessSwap, , int) {
for := + 1; < ; ++ {
for := ; > && .Less(, -1); -- {
.Swap(, -1)
}
}
}
func ( lessSwap, , , int) {
:=
for {
:= 2* + 1
if >= {
break
}
if +1 < && .Less(+, ++1) {
++
}
if !.Less(+, +) {
return
}
.Swap(+, +)
=
}
}
func ( lessSwap, , int) {
:=
:= 0
:= -
for := ( - 1) / 2; >= 0; -- {
siftDown_func(, , , )
}
for := - 1; >= 0; -- {
.Swap(, +)
siftDown_func(, , , )
}
}
func ( lessSwap, , , int) {
if .Less(, ) {
.Swap(, )
}
if .Less(, ) {
.Swap(, )
if .Less(, ) {
.Swap(, )
}
}
}
func ( lessSwap, , , int) {
for := 0; < ; ++ {
.Swap(+, +)
}
}
func ( lessSwap, , int) (, int) {
:= int(uint(+) >> 1)
if - > 40 {
:= ( - ) / 8
medianOfThree_func(, , +, +2*)
medianOfThree_func(, , -, +)
medianOfThree_func(, -1, -1-, -1-2*)
}
medianOfThree_func(, , , -1)
:=
, := +1, -1
for ; < && .Less(, ); ++ {
}
:=
for {
for ; < && !.Less(, ); ++ {
}
for ; < && .Less(, -1); -- {
}
if >= {
break
}
.Swap(, -1)
++
--
}
:= - < 5
if ! && - < (-)/4 {
:= 0
if !.Less(, -1) {
.Swap(, -1)
++
++
}
if !.Less(-1, ) {
--
++
}
if !.Less(, ) {
.Swap(, -1)
--
++
}
= > 1
}
if {
for {
for ; < && !.Less(-1, ); -- {
}
for ; < && .Less(, ); ++ {
}
if >= {
break
}
.Swap(, -1)
++
--
}
}
.Swap(, -1)
return - 1,
}
func ( lessSwap, , , int) {
for - > 12 {
if == 0 {
heapSort_func(, , )
return
}
--
, := doPivot_func(, , )
if - < - {
(, , , )
=
} else {
(, , , )
=
}
}
if - > 1 {
for := + 6; < ; ++ {
if .Less(, -6) {
.Swap(, -6)
}
}
insertionSort_func(, , )
}
}
func ( lessSwap, int) {
:= 20
, := 0,
for <= {
insertionSort_func(, , )
=
+=
}
insertionSort_func(, , )
for < {
, = 0, 2*
for <= {
symMerge_func(, , +, )
=
+= 2 *
}
if := + ; < {
symMerge_func(, , , )
}
*= 2
}
}
func ( lessSwap, , , int) {
if - == 1 {
:=
:=
for < {
:= int(uint(+) >> 1)
if .Less(, ) {
= + 1
} else {
=
}
}
for := ; < -1; ++ {
.Swap(, +1)
}
return
}
if - == 1 {
:=
:=
for < {
:= int(uint(+) >> 1)
if !.Less(, ) {
= + 1
} else {
=
}
}
for := ; > ; -- {
.Swap(, -1)
}
return
}
:= int(uint(+) >> 1)
:= +
var , int
if > {
= -
=
} else {
=
=
}
:= - 1
for < {
:= int(uint(+) >> 1)
if !.Less(-, ) {
= + 1
} else {
=
}
}
:= -
if < && < {
rotate_func(, , , )
}
if < && < {
(, , , )
}
if < && < {
(, , , )
}
}
func ( lessSwap, , , int) {
:= -
:= -
for != {
if > {
swapRange_func(, -, , )
-=
} else {
swapRange_func(, -, +-, )
-=
}
}
swapRange_func(, -, , )
}