public int CompareTo(FdbKeyRange other) { int c = m_begin.CompareTo(other.m_begin); if (c == 0) { c = m_end.CompareTo(other.m_end); } return(c); }
/// <summary>Test if <paramref name="key"/> is contained inside the range</summary> /// <param name="key">Key that will be compared with the the range's bounds</param> /// <param name="endIncluded">If true, the End bound is inclusive, otherwise it is exclusive</param> /// <returns>-1 if key is less than the lower bound of the range (<paramref name="key"/> < Begin), +1 if the key is greater or equal to the higher bound of the range (<paramref name="key"/> >= End) or 0 if it is inside the range (Begin <= <paramref name="key"/> < End)</returns> public int Test(Slice key, bool endIncluded = false) { // note: if the range is empty (Begin = End = Slice.Empty) then it should return 0 if (m_begin.IsPresent && key.CompareTo(m_begin) < 0) { return(-1); } if (m_end.IsPresent && key.CompareTo(m_end) >= (endIncluded ? 1 : 0)) { return(+1); } return(0); }
public void TestCompareTo() { Slice slice = new byte[] { 0x01, 0x02 }; sliceTest = new byte[] { 0x01, 0x02 }; int result = sliceTest.CompareTo(slice); Assert.AreEqual(0, result); sliceTest = new byte[] { 0x01 }; result = sliceTest.CompareTo(slice); Assert.AreEqual(-1, result); sliceTest = new byte[] { 0x01, 0x02, 0x03 }; result = sliceTest.CompareTo(slice); Assert.AreEqual(1, result); sliceTest = new byte[] { 0x01, 0x03 }; result = sliceTest.CompareTo(slice); Assert.AreEqual(1, result); sliceTest = new byte[] { 0x01, 0x01 }; result = sliceTest.CompareTo(slice); Assert.AreEqual(-1, result); }
/// <summary>Returns true, if the key is contained in the range</summary> /// <param name="key"></param> /// <returns></returns> public bool Contains(Slice key) { return(key.CompareTo(m_begin) >= 0 && key.CompareTo(m_end) < 0); }