Merge branch 'rewrite/master' into feature/chart-editor-context-menus

This commit is contained in:
Cameron Taylor
2024-01-05 20:11:38 -05:00
32 changed files with 840 additions and 627 deletions
+16
View File
@@ -77,6 +77,22 @@ class ArrayTools
array.pop();
}
/**
* Create a new array with all elements of the given array, to prevent modifying the original.
*/
public static function clone<T>(array:Array<T>):Array<T>
{
return [for (element in array) element];
}
/**
* Create a new array with clones of all elements of the given array, to prevent modifying the original.
*/
public static function deepClone<T, U:ICloneable<T>>(array:Array<U>):Array<T>
{
return [for (element in array) element.clone()];
}
/**
* Return true only if both arrays contain the same elements (possibly in a different order).
* @param a The first array to compare.
+10
View File
@@ -0,0 +1,10 @@
package funkin.util.tools;
/**
* Implement this on a class to enable `Array<T>.deepClone()` to work on it.
* NOTE: T should be the type of the class that implements this interface.
*/
interface ICloneable<T>
{
public function clone():T;
}
+27
View File
@@ -25,6 +25,33 @@ class MapTools
return [for (i in map.iterator()) i];
}
/**
* Create a new array with all elements of the given array, to prevent modifying the original.
*/
public static function clone<K, T>(map:Map<K, T>):Map<K, T>
{
return map.copy();
}
/**
* Create a new array with clones of all elements of the given array, to prevent modifying the original.
*/
public static function deepClone<K, T, U:ICloneable<T>>(map:Map<K, U>):Map<K, T>
{
// TODO: This function does NOT work.
throw "Not implemented";
/*
var newMap:Map<K, T> = [];
// Replace each value with a clone of itself.
for (key in newMap.keys())
{
newMap.set(key, newMap.get(key).clone());
}
return newMap;
*/
}
/**
* Return a list of keys from the map (as an array, rather than an iterator).
* TODO: Rename this?