Coder Social home page Coder Social logo

hoi4-quicksort's Introduction

HoI4 Quicksort

This is an implementation of an iterative randomized 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 mod makes use of this algorithm, albeit in a modified version.

hoi4-quicksort's People

Contributors

yard1 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

macbethstalk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.