private int CompareToWorker(List l) { // we need to lock both objects (or copy all of one's data w/ it's lock held, and // then compare, which is bad). Therefore we have a strong order for locking on // the lists int result; if (this.GetHashCode() < l.GetHashCode()) { lock (this) lock (l) result = Ops.CompareArrays(data, size, l.data, l.size); } else if (this.GetHashCode() != l.GetHashCode()) { lock (l) lock (this) result = Ops.CompareArrays(data, size, l.data, l.size); } else { // rare, but possible. We need a second opinion if (IdDispenser.GetId(this) < IdDispenser.GetId(l)) { lock (this) lock (l) result = Ops.CompareArrays(data, size, l.data, l.size); } else { lock (l) lock (this) result = Ops.CompareArrays(data, size, l.data, l.size); } } return(result); }
public int CompareTo(object other) { Slice s = other as Slice; if (s == null) { throw new ArgumentException("expected slice"); } return(Ops.CompareArrays(new object[] { start, stop, step }, 3, new object[] { s.start, s.stop, s.step }, 3)); }
public int CompareTo(object other) { //!!! how to handle different type Tuple l = other as Tuple; if (l == null) { throw new ArgumentException("expected list"); } return(Ops.CompareArrays(data, data.Length, l.data, l.data.Length)); }