public static LinkedList1 <T> GetInstance(T first, LinkedList1 <T> restOrNull) { LinkedList1 <T> linkedList1 = new LinkedList1 <T>(); linkedList1.First = first; linkedList1.RestOrNull = restOrNull; linkedList1.HashCode = LinkedList1StringHashCode ^ first.GetHashCode(); if (null != restOrNull) { linkedList1.HashCode ^= SpecialFunctions.WrapAroundLeftShift(restOrNull.GetHashCode(), 1); } return(linkedList1); }
public int CompareTo(LinkedList1 <T> other) { //If we are the same object in memory, we are equal if ((object)this == (object)other) { return(0); } //I'm an object, so if they other guy is null, so sort me after him if (null == other) { return(1); } //If our hash codes are different, sort on it (this will be fast because hashcode are pre-computed int hashCodeComp = GetHashCode().CompareTo(other.GetHashCode()); if (0 != hashCodeComp) { return(hashCodeComp); } //We are IComparable<T>. Sort on our first items if they are different. int compFirst = ((IComparable <T>)First).CompareTo(other.First); if (compFirst != 0) { return(compFirst); } //If your first items are equal, compare our Rest's if (RestOrNull == null) { if (other.RestOrNull == null) { return(0); } else { return(-1); } } return(RestOrNull.CompareTo(other.RestOrNull)); }