diff options
Diffstat (limited to '')
-rw-r--r-- | NW4RTools/Misc.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/NW4RTools/Misc.cs b/NW4RTools/Misc.cs index c42b185..118f164 100644 --- a/NW4RTools/Misc.cs +++ b/NW4RTools/Misc.cs @@ -16,6 +16,46 @@ namespace NW4RTools { public static uint AlignDown(uint val, uint to) { return val & ~(to - 1); } + + + public static void Assert(bool condition) { + if (!condition) + throw new Exception("Assert failed"); + } + public static void Assert(bool condition, string format, params object[] args) { + if (!condition) + throw new Exception(String.Format(format, args)); + } + + + public static bool ArrayCompare<T>(T[] one, T[] two) { + if (one == two) + return true; + if (one == null || two == null) + return false; + if (one.Length != two.Length) + return false; + + for (int i = 0; i < one.Length; i++) { + if (!one[i].Equals(two[i])) + return false; + } + + return true; + } + + + public static int ArrayHash<T>(T[] arr) { + if (arr == null) + return 0xEA7BEEF; + + int hash = 0; + + for (int i = 0; i < arr.Length; i++) + hash ^= arr[i].GetHashCode(); + + return hash; + } } } |