shawnsmithdev / zermelo

A radix sorting library for Go (golang)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sorted slice detection is incorrect

opened this issue · comments

The sorted variable will never become true:

sorted := false
prev := uint32(0)
for _, elem := range from {
// For each elem to sort, fetch the byte at current radix
key := uint8(elem >> keyOffset)
// inc count of bytes of this type
offset[key]++
if sorted { // Detect sorted
sorted = elem >= prev
prev = elem
}
}
if sorted { // Short-circuit sorted
if (keyOffset/radix)%2 == 1 {
copy(to, from)
}
return
}

hmmm... maybe it got lost in a copy/paste. I think the sort test is only against uint64...

  • Confirmed this was only in uint32 code
  • Confirmed this caused the "sorted shortcut" code to not work at all
  • Fixed in bugfix release v1.0.4

Thanks for catching this!