https://github.com/yard1/hoi4-quicksort
https://github.com/yard1/hoi4-quicksort
hearts-of-iron-4 hearts-of-iron-iv heartsofiron4 modding modding-resources paradox-interactive paradoxgame quicksort
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/yard1/hoi4-quicksort
- Owner: Yard1
- Created: 2019-04-08T01:22:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-08T20:41:15.000Z (about 6 years ago)
- Last Synced: 2025-01-19T07:23:52.927Z (5 months ago)
- Topics: hearts-of-iron-4, hearts-of-iron-iv, heartsofiron4, modding, modding-resources, paradox-interactive, paradoxgame, quicksort
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HoI4 Quicksort
This is an implementation of an iterative randomized [quicksort](https://en.wikipedia.org/wiki/Quicksort) algorithm for HoI 4 script arrays. The algorithm allows for very fast sorting of large arrays, compared to naive algorithms such as selection or insertion sort.
Measured on my machine with Script Profiler, sorting a random 1000-element array takes 87 ms. Worst case (sorted array) requires about 270 ms (since the pivot is random, both times may fluctuate slightly). That's about 19.6 times better performance than selection sort, and 22 times better performance than insertion sort.
In order to use the quicksort scripted effect, arguments first need to be set up beforehand (saved as non-temporary variables). They are:
arr = array to sort
low = starting index (you probably want 0)
high = ending index (you probably want arr^num - 1)
Example:
```
# arr set up beforehand
# Set arguments
set_variable = { high = arr^num }
subtract_from_variable = { high = 1 }set_variable = { low = 0 }
# Arguments: arr, high, low
quicksort = yes # arr set up beforehand
```Included in the file are: the quicksort scripted effects (`quicksort` and `quicksort_partition`), selection sort (`naive_sorting`), insertion sort (`insertion_sort`), scripted effect to measure performance (`sorting_test` - call it with an event while running the profiler), scripted effects to test the sorting effects and an effect to create the test array (
`set_up_array`).Feel free to use in your mods, but give credits to Yard1 (both in code, with comments; and on your download page).
My [Ledger](https://github.com/Yard1/HoI4-Ledger) mod makes use of this algorithm, albeit in a modified version.