TC39 A CLOCK SORT (BUILT-IN) PRIMITIVE v2
A program execution session includes a built-in clock, so why not use it as a defacto-sort!
By assigning each element into a hash map, the algorithm could sort the entire array in O(N), where N is the number of integers to sort
This example implementation substitutes a while-loop
let myUnsortedArray = [0,4,0,9]
let NN = myUnsortedArray._FastNSort()
Step 1. All internal NN Comparisons are compiled in Parallel
0:[e + 0 + 0 + 0] = NN[0] = 0
4:[1 + e + 1 + 0] = NN[2] = 4
0:[e + 0 + 0 + 0] = NN[0] = 0
9:[1 + 1 + 1 + e] = NN[3] = 9
Step 2.
let I = myUnsortedArray.length
let clk = 0
let mySortedArray = []
let lastCLK = NN[0]
while(clk<I){
NN[clk] && (lastCLK=NN[clk])
mySortedArray.push(lastCLK)
clk++
}
mySortedArray // [0,0,0,4,9]
So, here's some questions I have:
- I'm still not entirely sure what you mean by the computer's "clock". I'm having difficulty picturing how its clock would fit into this sorting algorithm. Are you referring to the CPU clock, that ensures instructions run on a set interval, or are you referring to the literal internal clock that keeps track of time? In either scenario, how can the clock be used to help with sorting, could you expound on this (the CPU's clock is an implementation detail that can't really be touched, and a sorting algorithm that relies on a real, ticking clock sounds like it would take a long time to execute, why would you want to slow down an algorithm to sync it up to physical time)?
- What's the
e
variable in your example? In general, I'm having difficulty understanding your step 1. You're using a lot of unexplained, non-standard syntax to convey your point, and I'm having trouble figuring out what you intended this syntax to mean.
1 Like