using System; namespace NW4RTools { public static class Misc { public static int AlignUp(int val, int to) { return (val + (to - 1)) & ~(to - 1); } public static uint AlignUp(uint val, uint to) { return (val + (to - 1)) & ~(to - 1); } public static int AlignDown(int val, int to) { return val & ~(to - 1); } 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[] 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[] arr) { if (arr == null) return 0xEA7BEEF; int hash = 0; for (int i = 0; i < arr.Length; i++) hash ^= arr[i].GetHashCode(); return hash; } } }