private bool EqualsWorker(deque otherDeque, IEqualityComparer comparer) { Assert.NotNull(otherDeque); if (otherDeque._itemCnt != _itemCnt) { // number of items is different, deques can't be equal return(false); } else if (otherDeque._itemCnt == 0) { // two empty deques are equal return(true); } if (CompareUtil.Check(this)) { return(true); } CompareUtil.Push(this); try { for (int otherIndex = otherDeque._head, ourIndex = _head; ourIndex != _tail;) { bool result; var ourData = _data[ourIndex]; var otherData = otherDeque._data[otherIndex]; if (comparer == null) { result = PythonOps.IsOrEqualsRetBool(ourData, otherData); } else { result = ReferenceEquals(ourData, otherData) || comparer.Equals(ourData, otherData); } if (!result) { return(false); } // advance both indices otherIndex++; if (otherIndex == otherDeque._data.Length) { otherIndex = 0; } ourIndex++; if (ourIndex == _data.Length) { ourIndex = 0; } } // same # of items, all items are equal return(true); } finally { CompareUtil.Pop(this); } }
private object CompareToWorker(CodeContext context, deque other, PythonOperationKind op) { if (_itemCnt == 0 || other._itemCnt == 0) { return(PythonOps.RichCompare(context, _itemCnt, other._itemCnt, op)); } if (CompareUtil.Check(this)) { return(0); } CompareUtil.Push(this); try { int otherIndex = other._head, ourIndex = _head; for (; ;) { var ourData = _data[ourIndex]; var otherData = other._data[otherIndex]; if (!PythonOps.IsOrEqualsRetBool(context, ourData, otherData)) { return(PythonOps.RichCompare(context, ourData, otherData, op)); } // advance both indexes otherIndex++; if (otherIndex == other._data.Length) { otherIndex = 0; } if (otherIndex == other._tail) { break; } ourIndex++; if (ourIndex == _data.Length) { ourIndex = 0; } if (ourIndex == _tail) { break; } } // all items are equal, but # of items may be different. return(PythonOps.RichCompare(context, _itemCnt, other._itemCnt, op)); } finally { CompareUtil.Pop(this); } }
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) { if (CompareUtil.Check(this)) { return(0); } int res; CompareUtil.Push(this); try { res = ((IStructuralEquatable) new PythonTuple(this)).GetHashCode(comparer); } finally { CompareUtil.Pop(this); } return(res); }
private int CompareToWorker(deque otherDeque, IComparer comparer) { Assert.NotNull(otherDeque); if (otherDeque._itemCnt == 0 && _itemCnt == 0) { // comparing two empty deques return(0); } if (CompareUtil.Check(this)) { return(0); } CompareUtil.Push(this); try { int otherIndex = otherDeque._head, ourIndex = _head; for (; ;) { int result; if (comparer == null) { result = PythonOps.Compare(_data[ourIndex], otherDeque._data[otherIndex]); } else { result = comparer.Compare(_data[ourIndex], otherDeque._data[otherIndex]); } if (result != 0) { return(result); } // advance both indexes otherIndex++; if (otherIndex == otherDeque._data.Length) { otherIndex = 0; } if (otherIndex == otherDeque._tail) { break; } ourIndex++; if (ourIndex == _data.Length) { ourIndex = 0; } if (ourIndex == _tail) { break; } } // all items are equal, but # of items may be different. if (otherDeque._itemCnt == _itemCnt) { // same # of items, all items are equal return(0); } return(_itemCnt > otherDeque._itemCnt ? 1 : -1); } finally { CompareUtil.Pop(this); } }