Exemple #1
0
 public static int Compare(NodeIndex index1, NodeIndex index2)
 {
     if (index1 < index2)
     {
         return -1;
     }
     if (index1 > index2)
     {
         return 1;
     }
     return 0;
 }
Exemple #2
0
 internal static bool CreateBetween(NodeIndex before, NodeIndex after, out NodeIndex index)
 {
     return Create(before.bigValue, before.smallValue, after.bigValue, after.smallValue, out index);
 }
Exemple #3
0
 internal static bool CreateBefore(NodeIndex after, out NodeIndex index)
 {
     return Create(-2147483648, -32768, after.bigValue, after.smallValue, out index);
 }
Exemple #4
0
 internal static bool CreateAfter(NodeIndex before, out NodeIndex index)
 {
     return Create(before.bigValue, before.smallValue, 0x7fffffff, 0x7fff, out index);
 }
Exemple #5
0
 internal static bool CreateFirst(out NodeIndex index)
 {
     return Create(-2147483648, -32768, 0x7fffffff, 0x7fff, out index);
 }
Exemple #6
0
 private static bool Create(int previousBigValue, short previousSmallValue, int nextBigValue, short nextSmallValue, out NodeIndex index)
 {
     int num;
     short num2;
     index = new NodeIndex();
     if (previousBigValue == nextBigValue)
     {
         num = previousBigValue;
         if (!CreateSmallValue(previousSmallValue, nextSmallValue, out num2))
         {
             return false;
         }
     }
     else if (CreateBigValue(previousBigValue, nextBigValue, out num))
     {
         num2 = 0;
     }
     else if (num == previousBigValue)
     {
         if (!CreateSmallValue(previousSmallValue, nextSmallValue, out num2))
         {
             return false;
         }
     }
     else
     {
         return false;
     }
     index.bigValue = num;
     index.smallValue = num2;
     return true;
 }
Exemple #7
0
        /// <summary>
        /// Creates an index for a new node.
        /// </summary>
        /// <param name="previousBigValue">The big value of the previous node.</param>
        /// <param name="previousSmallValue">The small value of the previous node.</param>
        /// <param name="nextBigValue">The big value of the next node.</param>
        /// <param name="nextSmallValue">The small value of the next node.</param>
        /// <param name="index">Returns the new index.</param>
        /// <returns>Returns true if the new index was created, or false if there are no more indexes.</returns>
        private static bool Create(int previousBigValue, short previousSmallValue, int nextBigValue, short nextSmallValue, out NodeIndex index)
        {
            Param.Ignore(previousBigValue, previousSmallValue, nextBigValue, nextSmallValue);

            // Validate the conditions we allow.
            Debug.Assert(
                (previousBigValue < nextBigValue) ||
                ((previousBigValue == nextBigValue) && (previousSmallValue < nextSmallValue)) ||
                ((previousBigValue == nextSmallValue) && (previousSmallValue == nextSmallValue)),
                "The values are not allowed.");

            int bigValue;
            short smallValue;

            index = new NodeIndex();

            // Check whether the indexes are the same up to the small value.
            if (previousBigValue == nextBigValue)
            {
                bigValue = previousBigValue;

                if (!CreateSmallValue(previousSmallValue, nextSmallValue, out smallValue))
                {
                    return false;
                }
            }
            else
            {
                if (CreateBigValue(previousBigValue, nextBigValue, out bigValue))
                {
                    smallValue = 0;
                }
                else if (bigValue == previousBigValue)
                {
                    if (!CreateSmallValue(previousSmallValue, nextSmallValue, out smallValue))
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }

            index.bigValue = bigValue;
            index.smallValue = smallValue;

            return true;
        }
Exemple #8
0
 /// <summary>
 /// Creates an index for a new node which is the first node in the list.
 /// </summary>
 /// <param name="index">Returns the new index.</param>
 /// <returns>Returns true if the new index was created, or false if there are no more indexes.</returns>
 internal static bool CreateFirst(out NodeIndex index)
 {
     return Create(int.MinValue, short.MinValue, int.MaxValue, short.MaxValue, out index);
 }
Exemple #9
0
 /// <summary>
 /// Creates an index for a new node being inserted at the beginning of the list.
 /// </summary>
 /// <param name="after">The index of the next node.</param>
 /// <param name="index">Returns the new index.</param>
 /// <returns>Returns true if the new index was created, or false if there are no more indexes.</returns>
 internal static bool CreateBefore(NodeIndex after, out NodeIndex index)
 {
     Param.Ignore(after);
     return Create(int.MinValue, short.MinValue, after.bigValue, after.smallValue, out index);
 }
Exemple #10
0
 /// <summary>
 /// Creates an index for a new node being inserted at the beginning of the list.
 /// </summary>
 /// <param name="before">The index of the previous node.</param>
 /// <param name="index">Returns the new index.</param>
 /// <returns>Returns true if the new index was created, or false if there are no more indexes.</returns>
 internal static bool CreateAfter(NodeIndex before, out NodeIndex index)
 {
     Param.Ignore(before);
     return Create(before.bigValue, before.smallValue, int.MaxValue, short.MaxValue, out index);
 }
Exemple #11
0
        /// <summary>
        /// Compares the two indexes and returns a standard comparison result.
        /// </summary>
        /// <param name="index1">The first index.</param>
        /// <param name="index2">The second index.</param>
        /// <returns>Returns a negative value if the first index is less than the second index, a positive
        /// value if the second index is greater than the first index, or zero if the two indexes are equal.</returns>
        public static int Compare(NodeIndex index1, NodeIndex index2)
        {
            Param.Ignore(index1, index2);

            if (index1 < index2)
            {
                return -1;
            }
            else if (index1 > index2)
            {
                return 1;
            }

            return 0;
        }