diff Util/ArrayUtil.cs @ 1:28dc7d535036

Small improvements, introduced PacketStream
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 07 Jan 2013 16:43:28 +0100
parents 3ab940a0c7a0
children 9533a87363f3
line wrap: on
line diff
--- a/Util/ArrayUtil.cs	Tue Sep 11 16:28:53 2012 +0200
+++ b/Util/ArrayUtil.cs	Mon Jan 07 16:43:28 2013 +0100
@@ -84,5 +84,23 @@
 			for (int i = 0; i < a.Length; i++) if (a[i] != b[i]) return false;
 			return true;
 		}
+		public static int GetHashCode<T>(T[] array) {
+			int h = 0;
+			foreach (T v in array) h ^= v.GetHashCode();
+			return h;
+		}
+		public static void Add<T>(ref T[] array, T item) {
+			if (array == null) {
+				array = new T[] { item };
+			} else {
+				int index = array.Length;
+				Array.Resize(ref array, index + 1);
+				array[index] = item;
+			}
+		}
+		public static void AddUnique<T>(ref T[] array, T item) {
+			if (Array.IndexOf(array, item) != -1) return;
+			Add(ref array, item);
+		}
 	}
 }