There are three types of visualisations:
- Ones that use a single array and display each element based on it's value.
- Ones that use a single array and display each element based on it's disparity, a.k.a how far away the element is from where it's supposed to be. These will usually have "disparity" in the name.
- Ones that use multiple arrays. I will mark ones that use multiple arrays with an (M).
You can switch between visualisations while sorting IF you are switching to a visualisation of the same array type (single or multi). More visualisations are to come in the future. :)
Displays array in a circle:
Displays array as a doughnut (pretty much just circle).
Displays array as a row of bars:
Coloring:
Element | Colour |
---|---|
Active | Blue |
Secondary Active (used when comparing elements) | Blue |
Pivot (Quicksort) | Purple |
Colours may change in the future.
With Lomuto partitioning quicksort (default quicksort implemented), the two active elements show the area where the elements are collecting that are bigger than the pivot. Once it reaches the end of the partition it moves the pivot to before that area.
Displays the array as a row of bars through the middle of the screen, where the height is the difference between where the element is and where it is supposed to be.
Looks good with cocktail shaker sort. Here it is while doing a cocktail shaker sort:
Displays array as circular loop made up of segments, where each segment's distance from the centre of the circle is determined by it's disparity; the distance from where it is supposed to be.
Displays array as dots (looks good with quick sort):
Exact same colouring as the bar visualisation.
Displays array as a vertical pyramid:
The same colouring as the bar visualisation.
Displays multiple arrays, spanning from the left to the right of the window. Each row of pixels is a seperate array.
Does not display active elements etc because it would be a bit too cluttered.
Key | Sort |
---|---|
1 | Bubble Sort. |
2 | Cocktail Shaker Sort. |
3 | Insertion Sort. |
4 | Selection Sort. |
5 | Shell Sort. |
6 | Quicksort:
|
7 | Merge Sort:
|
8 | Radix LSD Sort (Base 10). |
Ones with multiple options can be changed easily in the config.yaml
file.
You can do multiple sorts at once but be careful since this can ruin the array (however you can reset by pressing R).
Quicktimsort is a home-made sort and is a hybrid of Quicksort and Insertion sort inspired by TimSort. It is regular Quicksort until the array is small enough that Insertion sort is effective, since Insertion sort is quite speedy for small arrays.
NOTE: Due to Quicksort's Lomuto partitioning scheme, sorting the sorted or reversed array is incredibly slow, and is a key problem with this partitioning scheme, since it uses the last element as the pivot, rather than the middle.
Key | Sort |
---|---|
S | Shuffle. |
R | Reset array. |
I | Invert/reverse array. |
Q | Cancel current sort. |
Shift + L | Reload config file. |
Resetting the array regenerates all of the elements in the array, so if you ever have any problems with the array, for example duplicate array elements due to running multiple sorts, then reset the array and you should be good to go.
NOTE: Reloading the config file does not reload audio settings, for that you need to restart the program.
Key | Sort |
---|---|
C | Circle. |
O | Doughnut. |
B | Bars. |
L | Disparity Line. |
K | Disparity Loop. |
Y | Pyramid |
D | Dots. |
P | Pixels. |
Shift + S | Spiral. |
All configuration is done through the config.yaml
file in the root folder of the project.
Sleep times for each sort can be changed, along with sound settings and array settings (such as the length of the arrays generated).
Install rust (rustup + cargo), then change directory to this folder, and run:
cargo build --release
Then you will find the executable in target/release/sort_visualiser
.
If you have a problem with linking, so shaderc-sys
cannot compile, then build it with the --features=shaderc_fix
flag.
Install pulseaudio-alsa
to fix ALSA lib pcm_dmix.c:1089: (snd_pcm_dmix_open) unable to open slave
error.