コード例 #1
0
ファイル: List.cs プロジェクト: Vinayaka-Hebbar/FluidScript
 public bool Contains(T item)
 {
     if (item == null)
     {
         for (int i = 0; i < _size; i++)
         {
             if (_items[i] == null)
             {
                 return(true);
             }
         }
         return(false);
     }
     else
     {
         System.Collections.Generic.EqualityComparer <T> c = System.Collections.Generic.EqualityComparer <T> .Default;
         for (int i = 0; i < _size; i++)
         {
             if (c.Equals(_items[i], item))
             {
                 return(true);
             }
         }
         return(false);
     }
 }
コード例 #2
0
        public NCLinkedListNode <T> Find(T value)
        {
            NCLinkedListNode <T> head = this.head;

            System.Collections.Generic.EqualityComparer <T> comparer = System.Collections.Generic.EqualityComparer <T> .Default;
            if (head != null)
            {
                if (value != null)
                {
                    do
                    {
                        if (comparer.Equals(head.item, value))
                        {
                            return(head);
                        }
                        head = head.next;
                    }while (head != this.head);
                }
                else
                {
                    do
                    {
                        if (head.item == null)
                        {
                            return(head);
                        }
                        head = head.next;
                    }while (head != this.head);
                }
            }
            return(null);
        }
コード例 #3
0
 public bool Contains(T item)
 {
     if ((Object)item == null)
     {
         for (int i = 0; i < _size; i++)
         {
             if ((Object)_items[i] == null)
             {
                 Contract.Assert(Count > 0);
                 return(true);
             }
         }
         return(false);
     }
     else
     {
         System.Collections.Generic.EqualityComparer <T> c = System.Collections.Generic.EqualityComparer <T> .Default;
         for (int i = 0; i < _size; i++)
         {
             if (c.Equals(_items[i], item))
             {
                 Contract.Assert(Count > 0);
                 return(true);
             }
         }
         return(false);
     }
 }
コード例 #4
0
        static StackObject* GetHashCode_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject* ptr_of_this_method;
            StackObject* __ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @obj = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Collections.Generic.EqualityComparer<System.Int32> instance_of_this_method = (System.Collections.Generic.EqualityComparer<System.Int32>)typeof(System.Collections.Generic.EqualityComparer<System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetHashCode(@obj);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value = result_of_this_method;
            return __ret + 1;
        }
コード例 #5
0
        static StackObject *Equals_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @y = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Int32 @x = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Collections.Generic.EqualityComparer <System.Int32> instance_of_this_method = (System.Collections.Generic.EqualityComparer <System.Int32>) typeof(System.Collections.Generic.EqualityComparer <System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Equals(@x, @y);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method ? 1 : 0;
            return(__ret + 1);
        }
コード例 #6
0
        /// <summary>
        /// Remove the specified item from the list. Note that RemoveAt() is faster and is advisable if you already know the index.
        /// </summary>

        public bool Remove(T item)
        {
            if (buffer != null)
            {
                System.Collections.Generic.EqualityComparer <T> comp =
                    System.Collections.Generic.EqualityComparer <T> .Default;

                for (int i = 0; i < size; ++i)
                {
                    if (comp.Equals(buffer[i], item))
                    {
                        --size;
                        buffer[i] = default(T);
                        for (int b = i; b < size; ++b)
                        {
                            buffer[b] = buffer[b + 1];
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #7
0
        /// <summary>Compares the contents of a <see cref="IEnumerable{T}"/>
        /// implementation to another one to determine equality.</summary>
        /// <remarks>Thinking of the <see cref="IEnumerable{T}"/> implementation as
        /// a string with any number of characters, the algorithm checks
        /// each item in each list.  If any item of the list is not equal (or
        /// one list contains all the elements of another list), then that list
        /// element is compared to the other list element to see which
        /// list is greater.</remarks>
        /// <param name="x">The <see cref="IEnumerable{T}"/> implementation
        /// that is considered the left hand side.</param>
        /// <param name="y">The <see cref="IEnumerable{T}"/> implementation
        /// that is considered the right hand side.</param>
        /// <returns>True if the items are equal, false otherwise.</returns>
        private static bool Equals(System.Collections.Generic.IEnumerable <T> x,
                                   System.Collections.Generic.IEnumerable <T> y)
        {
            // If x and y are null, then return true, they are the same.
            if (x == null && y == null)
            {
                // They are the same, return 0.
                return(true);
            }

            // If one is null, then return a value based on whether or not
            // one is null or not.
            if (x == null || y == null)
            {
                // Return false, one is null, the other is not.
                return(false);
            }

            // Check to see if the counts on the IEnumerable implementations are equal.
            // This is a shortcut, if they are not equal, then the lists are not equal.
            // If the result is indeterminate, then get out.
            bool?enumerableCountsEqual = EnumerableCountsEqual(x, y);

            // If the enumerable counts have been able to be calculated (indicated by
            // a non-null value) and it is false, then no need to iterate through the items.
            if (enumerableCountsEqual != null && !enumerableCountsEqual.Value)
            {
                // The sequences are not equal.
                return(false);
            }

            // The counts of the items in the enumerations are equal, or indeterminate
            // so a full iteration needs to be made to compare each item.
            // Get the default comparer for T first.
            System.Collections.Generic.EqualityComparer <T> defaultComparer =
                System.Collections.Generic.EqualityComparer <T> .Default;

            // Get the enumerator for y.
            System.Collections.Generic.IEnumerator <T> otherEnumerator = y.GetEnumerator();

            // Call Dispose on IDisposable if there is an implementation on the
            // IEnumerator<T> returned by a call to y.GetEnumerator().
            using (otherEnumerator as IDisposable)
            {
                // Cycle through the items in this list.
                foreach (T item in x)
                {
                    // If there isn't an item to get, then this has more
                    // items than that, they are not equal.
                    if (!otherEnumerator.MoveNext())
                    {
                        // Return false.
                        return(false);
                    }

                    // Perform a comparison.  Must check this on the left hand side
                    // and that on the right hand side.
                    bool comparison = defaultComparer.Equals(item, otherEnumerator.Current);

                    // If the value is false, return false.
                    if (!comparison)
                    {
                        // Return the value.
                        return(comparison);
                    }
                }

                // If there are no more items, then return true, the sequences
                // are equal.
                if (!otherEnumerator.MoveNext())
                {
                    // The sequences are equal.
                    return(true);
                }

                // The other sequence has more items than this one, return
                // false, these are not equal.
                return(false);
            }
        }