/// <summary> /// Compares this abbreviation to a full object id. /// </summary> /// <param name="other">the other object id.</param> /// <returns> /// Return <0 if this abbreviation names an object that is less than /// <code>other</code>; 0 if this abbreviation exactly matches the /// first <see cref="Length"/> digits of <code>other.name()</code>; /// >0 if this abbreviation names an object that is after /// <code>other</code>. /// </returns> public int prefixCompare(AnyObjectId other) { if (other == null) { throw new ArgumentNullException("other"); } int cmp = NB.CompareUInt32(_w1, mask(1, other.W1)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(_w2, mask(2, other.W2)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(_w3, mask(3, other.W3)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(_w4, mask(4, other.W4)); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(_w5, mask(5, other.W5))); }
/// <summary>Compare this abbreviation to a network-byte-order ObjectId.</summary> /// <remarks>Compare this abbreviation to a network-byte-order ObjectId.</remarks> /// <param name="bs">array containing the other ObjectId in network byte order.</param> /// <param name="p"> /// position within /// <code>bs</code> /// to start the compare at. At least 5 /// ints, starting at this position are required. /// </param> /// <returns> /// <0 if this abbreviation names an object that is less than /// <code>other</code>; 0 if this abbreviation exactly matches the /// first /// <see cref="Length()">Length()</see> /// digits of <code>other.name()</code>; /// >0 if this abbreviation names an object that is after /// <code>other</code>. /// </returns> public int PrefixCompare(int[] bs, int p) { int cmp; cmp = NB.CompareUInt32(w1, Mask(1, bs[p])); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w2, Mask(2, bs[p + 1])); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w3, Mask(3, bs[p + 2])); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w4, Mask(4, bs[p + 3])); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(w5, Mask(5, bs[p + 4]))); }
/// <summary>Compares this abbreviation to a full object id.</summary> /// <remarks>Compares this abbreviation to a full object id.</remarks> /// <param name="other">the other object id.</param> /// <returns> /// <0 if this abbreviation names an object that is less than /// <code>other</code>; 0 if this abbreviation exactly matches the /// first /// <see cref="Length()">Length()</see> /// digits of <code>other.name()</code>; /// >0 if this abbreviation names an object that is after /// <code>other</code>. /// </returns> public int PrefixCompare(AnyObjectId other) { int cmp; cmp = NB.CompareUInt32(w1, Mask(1, other.w1)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w2, Mask(2, other.w2)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w3, Mask(3, other.w3)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w4, Mask(4, other.w4)); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(w5, Mask(5, other.w5))); }
/// <summary>Compare this abbreviation to a network-byte-order ObjectId.</summary> /// <remarks>Compare this abbreviation to a network-byte-order ObjectId.</remarks> /// <param name="bs">array containing the other ObjectId in network byte order.</param> /// <param name="p"> /// position within /// <code>bs</code> /// to start the compare at. At least /// 20 bytes, starting at this position are required. /// </param> /// <returns> /// <0 if this abbreviation names an object that is less than /// <code>other</code>; 0 if this abbreviation exactly matches the /// first /// <see cref="Length()">Length()</see> /// digits of <code>other.name()</code>; /// >0 if this abbreviation names an object that is after /// <code>other</code>. /// </returns> public int PrefixCompare(byte[] bs, int p) { int cmp; cmp = NB.CompareUInt32(w1, Mask(1, NB.DecodeInt32(bs, p))); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w2, Mask(2, NB.DecodeInt32(bs, p + 4))); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w3, Mask(3, NB.DecodeInt32(bs, p + 8))); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w4, Mask(4, NB.DecodeInt32(bs, p + 12))); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(w5, Mask(5, NB.DecodeInt32(bs, p + 16)))); }
/// <summary>Compare this ObjectId to a network-byte-order ObjectId.</summary> /// <remarks>Compare this ObjectId to a network-byte-order ObjectId.</remarks> /// <param name="bs">array containing the other ObjectId in network byte order.</param> /// <param name="p"> /// position within /// <code>bs</code> /// to start the compare at. At least 5 /// integers, starting at this position are required. /// </param> /// <returns> /// a negative integer, zero, or a positive integer as this object is /// less than, equal to, or greater than the specified object. /// </returns> public int CompareTo(int[] bs, int p) { int cmp; cmp = NB.CompareUInt32(w1, bs[p]); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w2, bs[p + 1]); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w3, bs[p + 2]); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w4, bs[p + 3]); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(w5, bs[p + 4])); }
/// <summary>Compare this ObjectId to a network-byte-order ObjectId.</summary> /// <remarks>Compare this ObjectId to a network-byte-order ObjectId.</remarks> /// <param name="bs">array containing the other ObjectId in network byte order.</param> /// <param name="p"> /// position within /// <code>bs</code> /// to start the compare at. At least /// 20 bytes, starting at this position are required. /// </param> /// <returns> /// a negative integer, zero, or a positive integer as this object is /// less than, equal to, or greater than the specified object. /// </returns> public int CompareTo(byte[] bs, int p) { int cmp; cmp = NB.CompareUInt32(w1, NB.DecodeInt32(bs, p)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w2, NB.DecodeInt32(bs, p + 4)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w3, NB.DecodeInt32(bs, p + 8)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w4, NB.DecodeInt32(bs, p + 12)); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(w5, NB.DecodeInt32(bs, p + 16))); }
/// <summary>Compare this ObjectId to another and obtain a sort ordering.</summary> /// <remarks>Compare this ObjectId to another and obtain a sort ordering.</remarks> /// <param name="other">the other id to compare to. Must not be null.</param> /// <returns> /// < 0 if this id comes before other; 0 if this id is equal to /// other; > 0 if this id comes after other. /// </returns> public int CompareTo(AnyObjectId other) { if (this == other) { return(0); } int cmp; cmp = NB.CompareUInt32(w1, other.w1); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w2, other.w2); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w3, other.w3); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(w4, other.w4); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(w5, other.w5)); }
/// <summary> /// Compare this ObjectId to another and obtain a sort ordering. /// </summary> /// <param name="other">the other id to compare to. Must not be null.</param> /// <returns> /// < 0 if this id comes before other; 0 if this id is equal to /// other; > 0 if this id comes after other. /// </returns> public int CompareTo(ObjectId other) { if (this == other) { return(0); } int cmp = NB.CompareUInt32(W1, other.W1); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(W2, other.W2); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(W3, other.W3); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(W4, other.W4); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(W5, other.W5)); }
/// <summary> /// Compares this abbreviation to a full object id. /// </summary> /// <param name="other">the other object id.</param> /// <returns> /// Return <0 if this abbreviation names an object that is less than /// <code>other</code>; 0 if this abbreviation exactly matches the /// first <see cref="Length"/> digits of <code>other.name()</code>; /// >0 if this abbreviation names an object that is after /// <code>other</code>. /// </returns> public int prefixCompare(AnyObjectId other) { int cmp = NB.CompareUInt32(_w1, mask(1, other.W1)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(_w2, mask(2, other.W2)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(_w3, mask(3, other.W3)); if (cmp != 0) { return(cmp); } cmp = NB.CompareUInt32(_w4, mask(4, other.W4)); if (cmp != 0) { return(cmp); } return(NB.CompareUInt32(_w5, mask(5, other.W5))); }
public void testCompareUInt32() { Assert.IsTrue(NB.CompareUInt32(0, 0) == 0); Assert.IsTrue(NB.CompareUInt32(1, 0) > 0); Assert.IsTrue(NB.CompareUInt32(0, 1) < 0); Assert.IsTrue(NB.CompareUInt32(-1, 0) > 0); Assert.IsTrue(NB.CompareUInt32(0, -1) < 0); Assert.IsTrue(NB.CompareUInt32(-1, 1) > 0); Assert.IsTrue(NB.CompareUInt32(1, -1) < 0); }