Merge branch 'main' into new-editors

This commit is contained in:
Ne_Eo
2025-01-09 20:05:06 +01:00
123 changed files with 1211 additions and 417 deletions
+15 -2
View File
@@ -1,14 +1,16 @@
package funkin.backend.utils;
/**
* All types of utils only usable in a sorted array.
* Tools to work with sorted arrays, in a more efficient way.
*
* DISCLAIMER: All types of utils only usable in a sorted array.
*/
final class SortedArrayUtil {
/**
* Gets the index of a possible new element of an Array of T using an efficient algorithm.
* @param array Array of T to check in
* @param getVal Function that returns the position value of T
* @return Index
* @return The index of the element
*/
public static inline function binarySearch<T>(array:Array<T>, val:Float, getVal:T->Float):Int {
if (array.length <= 0) return 0; // if the array is empty, it should be equal to zero (the beginning)
@@ -46,4 +48,15 @@ final class SortedArrayUtil {
if (val != null)
array.insert(binarySearch(array, getVal(val), getVal), val);
}
/**
* Removes from a sorted array, using binary search.
* @param array Array to remove from
* @param val Value to remove
* @param getVal Function that returns the value that needs to be sorted
*/
public static inline function removeSorted<T>(array:Array<T>, val:T, getVal:T->Float) {
if (val != null)
array.splice(binarySearch(array, getVal(val), getVal), 1);
}
}