-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
25 changed files
with
384 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package backend; | ||
|
||
class ArrayUtil { | ||
/** | ||
* 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 | ||
*/ | ||
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) | ||
if (getVal(array[0]) > val) return 0; // in case its the minimum | ||
if (getVal(array[array.length - 1]) < val) return array.length; // in case its the maximum | ||
|
||
// binary search | ||
var iMin:Int = 0; | ||
var iMax:Int = array.length - 1; | ||
|
||
var i:Int = 0; | ||
var mid:Float; | ||
while(iMin <= iMax) { | ||
i = Math.floor((iMin + iMax) / 2); | ||
mid = getVal(array[i]); | ||
if (mid < val) iMin = i + 1 | ||
else if (mid > val) iMax = i - 1; | ||
else { | ||
iMin = i; | ||
break; | ||
} | ||
} | ||
return iMin; | ||
} | ||
|
||
/** | ||
* Adds to a sorted array, using binary search. | ||
* @param array Array to add to | ||
* @param val Value to add | ||
* @param getVal Function that returns the value that needs to be sorted | ||
*/ | ||
public static inline function addSorted<T>(array:Array<T>, val:T, getVal:T->Float) { | ||
if (val != null) array.insert(binarySearch(array, getVal(val), getVal), val); | ||
} | ||
|
||
inline public static function dynamicArray<T>(v:T, len:Int):Array<T> return [for (_ in 0...len) v]; | ||
|
||
public static function sortByAlphabet(arr:Array<String>):Array<String> { | ||
arr.sort((a:String, b:String) -> { | ||
a = a.toUpperCase(); | ||
b = b.toUpperCase(); | ||
|
||
if (a < b) return -1; | ||
else if (a > b) return 1; | ||
else return 0; | ||
}); | ||
return arr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package backend.system; | ||
|
||
class SystemUtil { | ||
public static function getSysPath(path:String = ""):String { | ||
return Sys.getEnv(switch (path.toLowerCase()) { | ||
case "username": #if windows "USERNAME" #else "USER" #end; | ||
case "userpath": #if windows "USERPROFILE" #else "HOME" #end; | ||
case "temppath" | _: #if windows "TEMP" #else "HOME" #end; | ||
}); | ||
} | ||
|
||
public static function executableFileName() { | ||
var programPath = Sys.programPath().split(#if windows "\\" #else "/" #end); | ||
return programPath[programPath.length - 1]; | ||
} | ||
public static function generateTextFile(fileContent:String, fileName:String) { | ||
#if desktop | ||
var path = '${getSysPath()}/$fileName.txt'; | ||
File.saveContent(path, fileContent); | ||
Sys.command(#if windows "start " #elseif linux "xdg-open " #else "open " #end + path); | ||
#end | ||
} | ||
} |
Oops, something went wrong.