예제 #1
0
 static int CompareUint(IByteBuffer bufferA, IByteBuffer bufferB, int aIndex, int bIndex, int uintCountIncrement)
 {
     for (int aEnd = aIndex + uintCountIncrement; aIndex < aEnd; aIndex += 4, bIndex += 4)
     {
         long va = bufferA.GetUnsignedInt(aIndex);
         long vb = bufferB.GetUnsignedInt(bIndex);
         if (va > vb)
         {
             return(1);
         }
         if (va < vb)
         {
             return(-1);
         }
     }
     return(0);
 }
예제 #2
0
        /// <summary>
        /// Compares the two specified buffers as described in {@link ByteBuf#compareTo(ByteBuf)}.
        /// This method is useful when implementing a new buffer type.
        /// </summary>
        public static int Compare(IByteBuffer bufferA, IByteBuffer bufferB)
        {
            int aLen = bufferA.ReadableBytes;
            int bLen = bufferB.ReadableBytes;
            int minLength = Math.Min(aLen, bLen);
            int uintCount = (int)((uint)minLength >> 2);
            int byteCount = minLength & 3;

            int aIndex = bufferA.ReaderIndex;
            int bIndex = bufferB.ReaderIndex;

            if (bufferA.Order == bufferB.Order)
            {
                for (int i = uintCount; i > 0; i--)
                {
                    long va = bufferA.GetUnsignedInt(aIndex);
                    long vb = bufferB.GetUnsignedInt(bIndex);
                    if (va > vb)
                    {
                        return 1;
                    }
                    if (va < vb)
                    {
                        return -1;
                    }
                    aIndex += 4;
                    bIndex += 4;
                }
            }
            else
            {
                for (int i = uintCount; i > 0; i--)
                {
                    long va = bufferA.GetUnsignedInt(aIndex);
                    long vb = SwapInt(bufferB.GetInt(bIndex)) & 0xFFFFFFFFL;
                    if (va > vb)
                    {
                        return 1;
                    }
                    if (va < vb)
                    {
                        return -1;
                    }
                    aIndex += 4;
                    bIndex += 4;
                }
            }

            for (int i = byteCount; i > 0; i--)
            {
                short va = bufferA.GetByte(aIndex);
                short vb = bufferB.GetByte(bIndex);
                if (va > vb)
                {
                    return 1;
                }
                if (va < vb)
                {
                    return -1;
                }
                aIndex++;
                bIndex++;
            }

            return aLen - bLen;
        }
예제 #3
0
        /// <summary>
        /// Compares the two specified buffers as described in {@link ByteBuf#compareTo(ByteBuf)}.
        /// This method is useful when implementing a new buffer type.
        /// </summary>
        public static int Compare(IByteBuffer bufferA, IByteBuffer bufferB)
        {
            int aLen      = bufferA.ReadableBytes;
            int bLen      = bufferB.ReadableBytes;
            int minLength = Math.Min(aLen, bLen);
            int uintCount = (int)((uint)minLength >> 2);
            int byteCount = minLength & 3;

            int aIndex = bufferA.ReaderIndex;
            int bIndex = bufferB.ReaderIndex;

            if (bufferA.Order == bufferB.Order)
            {
                for (int i = uintCount; i > 0; i--)
                {
                    long va = bufferA.GetUnsignedInt(aIndex);
                    long vb = bufferB.GetUnsignedInt(bIndex);
                    if (va > vb)
                    {
                        return(1);
                    }
                    if (va < vb)
                    {
                        return(-1);
                    }
                    aIndex += 4;
                    bIndex += 4;
                }
            }
            else
            {
                for (int i = uintCount; i > 0; i--)
                {
                    long va = bufferA.GetUnsignedInt(aIndex);
                    long vb = SwapInt(bufferB.GetInt(bIndex)) & 0xFFFFFFFFL;
                    if (va > vb)
                    {
                        return(1);
                    }
                    if (va < vb)
                    {
                        return(-1);
                    }
                    aIndex += 4;
                    bIndex += 4;
                }
            }

            for (int i = byteCount; i > 0; i--)
            {
                short va = bufferA.GetByte(aIndex);
                short vb = bufferB.GetByte(bIndex);
                if (va > vb)
                {
                    return(1);
                }
                if (va < vb)
                {
                    return(-1);
                }
                aIndex++;
                bIndex++;
            }

            return(aLen - bLen);
        }