novemberborn/ksuid

Simple example - doesn't seem ordered

theogravity opened this issue · 1 comments

I'm getting results that are out of order:

const TIMESTAMP = Date.now();

const data = [
  TIMESTAMP, // 1quOkfPXJlP8398OOPw3ZAdU1Ud
  TIMESTAMP + 1, // 1quOkbqQvXWaG1jRZJ8gT7SR5TS
  TIMESTAMP + 2 // 1quOkgOFUU6rEapMcojkPREdr7v
].map((timestamp) =>  KSUSID.randomSync(timestamp).string) ;

The sort order looks like this:

1quOkbqQvXWaG1jRZJ8gT7SR5TS <-- TIMESTAMP + 1
1quOkfPXJlP8398OOPw3ZAdU1Ud <-- TIMESTAMP
1quOkgOFUU6rEapMcojkPREdr7v <-- TIMESTAMP + 2

(1, 0, 2)

vs 0, 1, 2 or 2, 1 , 0

Am I doing something wrong here?

Realized that k-sorting doesn't necessarily mean complete ordering.

This helped my understanding a bit

https://medium.com/@masandnikita/sorting-a-k-sorted-array-1142e0ed14b5#:~:text=What%20does%20k%20sorted%20mean,%2C5%2C2%2C6%7D