/// <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;
        }
Example #2
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);
        }
Example #3
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));
 }
Example #4
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));
 }
Example #5
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));
 }
Example #6
0
 /// <summary>
 /// Creates an index for a new node being inserted into the middle of the list.
 /// </summary>
 /// <param name="before">The index of the previous node.</param>
 /// <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 CreateBetween(NodeIndex before, NodeIndex after, out NodeIndex index)
 {
     Param.Ignore(before, after);
     return(Create(before.bigValue, before.smallValue, after.bigValue, after.smallValue, out index));
 }
        /// <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;
        }
 /// <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);
 }
 /// <summary>
 /// Creates an index for a new node being inserted into the middle of the list.
 /// </summary>
 /// <param name="before">
 /// The index of the previous node.
 /// </param>
 /// <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 CreateBetween(NodeIndex before, NodeIndex after, out NodeIndex index)
 {
     Param.Ignore(before, after);
     return Create(before.bigValue, before.smallValue, after.bigValue, after.smallValue, out index);
 }
 /// <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);
 }
 /// <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);
 }