예제 #1
0
        protected bool Compare <T>(System.IComparable <T> obj, T comparand)
        {
            int  num = obj.CompareTo(comparand);
            bool result;

            switch (this.Operator)
            {
            case ComparaisonOperatorEnum.EQUALS:
                result = (num == 0);
                break;

            case ComparaisonOperatorEnum.INEQUALS:
                result = (num != 0);
                break;

            case ComparaisonOperatorEnum.SUPERIOR:
                result = (num > 0);
                break;

            case ComparaisonOperatorEnum.INFERIOR:
                result = (num < 0);
                break;

            default:
                throw new System.NotImplementedException(string.Format("Cannot use {0} comparator on IComparable {1} and {2}", this.Operator, obj, comparand));
            }
            return(result);
        }
        public override void InsertKeyAndValue(System.IComparable key, object value)
        {
            int  position = GetPositionOfKey(key);
            bool addToExistingCollection = false;
            int  realPosition            = 0;

            if (position >= 0)
            {
                addToExistingCollection = true;
                realPosition            = position - 1;
            }
            else
            {
                realPosition = -position - 1;
            }
            // If there is an element at this position and the key is different,
            // then right shift, size
            // safety is guaranteed by the rightShiftFrom method
            if (realPosition < nbKeys && key.CompareTo(keys[realPosition]) != 0)
            {
                RightShiftFrom(realPosition, true);
            }
            keys[realPosition] = key;
            // This is a non unique btree node, manage collection
            ManageCollectionValue(realPosition, value);
            if (!addToExistingCollection)
            {
                nbKeys++;
            }
        }
예제 #3
0
        /// <summary>
        /// 一致する物があるかどうかを検索します
        /// </summary>
        /// <param name="val">何を検索するかを設定します。</param>
        /// <returns>一致した情報を持っている binTreeNode を返します。</returns>
        public object Search(System.IComparable val)
        {
            int cc = val.CompareTo(v);

            if (cc < 0)
            {
                if (lL == 0)
                {
                    return(null);
                }
                else
                {
                    return(l.Search(val));
                }
            }
            else if (cc > 0)
            {
                if (rL == 0)
                {
                    return(null);
                }
                else
                {
                    return(r.Search(val));
                }
            }
            else
            {
                return(v);
            }
        }
예제 #4
0
        //=====================================
        //          関数
        //-------------------------------------
        /// <summary>
        /// 新しい要素を木に追加します
        /// </summary>
        /// <param name="val">追加したい要素</param>
        public virtual void Add(System.IComparable val)
        {
            int cc = val.CompareTo(this.v);

            if (cc < 0)
            {
                if (this.lL == 0)
                {
                    this.lL++;
                    this.l = new binTreeNode(val, this, true);
                }
                else
                {
                    l.Add(val);
                }
            }
            else
            {
                if (this.rL == 0)
                {
                    this.rL++;
                    this.r = new binTreeNode(val, this, false);
                }
                else
                {
                    this.r.Add(val);
                }
            }
        }
예제 #5
0
    public static T UnsignedToSigned <T>(object value)
        where T : System.IComparable
    {
        if (value == null)
        {
            throw new System.ArgumentNullException(nameof(value), "Parameter cannot be NULL.");
        }
        System.Type t         = value.GetType();
        System.Type tRet      = typeof(T);
        int         sizeRet   = System.Runtime.InteropServices.Marshal.SizeOf(tRet);
        int         sizeValue = System.Runtime.InteropServices.Marshal.SizeOf(t);

        if (sizeRet != sizeValue)
        {
            throw new System.NotSupportedException($"Type mismatch: {tRet.Name} is not the matching signed type for {t.Name}");
        }
        System.IComparable minValue = (System.IComparable)GetMinValue(t);

        System.IComparable minValueRet = (System.IComparable)GetMinValue(tRet);
        if (minValueRet.CompareTo(System.Convert.ChangeType(0, tRet)) == 0)
        {
            throw new System.NotSupportedException($"Type mismatch: {tRet.Name} is not a signed type.");
        }
        // If we already have an signed type
        // Type mismatch already prevented
        if (minValue.CompareTo(System.Convert.ChangeType(0, t)) != 0)
        {
            return((T)value);
        }
        return((T)UnsignedToSigned(value, t));
    }
 /// <summary>
 /// Gets the status by testing the supplied value.
 /// </summary>
 /// <returns>The status of the supplied value.</returns>
 /// <param name="provider">Object on which the field exists.</param>
 /// <param name="testValue">Test value.</param>
 private ValidationStatus GetStatus(Object provider, System.IComparable testValue)
 {
     m_CurrentStatusTooltip = string.Empty;
     if (this.Attribute.ValidationMethod == null)
     {
         foreach (StatusPropertyAttribute.Comparison comparison in this.Attribute.GetComparisons())
         {
             try
             {
                 if (
                     (testValue == null && comparison.TestValue == null && comparison.BadComparisonResult == 0) ||
                     (testValue.CompareTo(comparison.TestValue) == comparison.BadComparisonResult)
                     )
                 {
                     m_CurrentStatusTooltip = this.Attribute.BadStatusTooltip;
                     return(this.Attribute.BadStatusIcon);
                 }
             }
             catch (System.ArgumentException e)
             {
                 m_CurrentStatusTooltip = e.Message;
                 return(ValidationStatus.Error);
             }
         }
         return(ValidationStatus.Okay);
     }
     else
     {
         return(this.Attribute.ValidationMethod(provider, testValue, out m_CurrentStatusTooltip));
     }
 }
 public virtual int CompareTo(object o)
 {
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AtomicNativeObjectInfo anoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AtomicNativeObjectInfo
                                                                         )o;
     System.IComparable c2 = (System.IComparable)anoi.GetObject();
     System.IComparable c1 = (System.IComparable)theObject;
     return(c1.CompareTo(c2));
 }
예제 #8
0
 public override int CompareTo(object o)
 {
     if (o == null || o.GetType() != typeof(NeoDatis.Odb.Core.Query.SimpleCompareKey))
     {
         return(-1);
     }
     NeoDatis.Odb.Core.Query.SimpleCompareKey ckey = (NeoDatis.Odb.Core.Query.SimpleCompareKey
                                                      )o;
     return(key.CompareTo(ckey.key));
 }
예제 #9
0
    private int countLessThan(System.IComparable value, BinaryTree.Node current)
    {
        if (current == null)
        {
            return(0);
        }
        int count = 0;

        if (current.left == null && current.right == null)
        {
            if (value.CompareTo(current.value) < 0)
            {
                count += 1;
            }
        }
        if (current.left != null && current.right == null)
        {
            if (value.CompareTo(current.value) < 0)
            {
                count += 1;
            }
            count += countLessThan(value, current.left);
        }
        if (current.left == null && current.right != null)
        {
            if (value.CompareTo(current.value) < 0)
            {
                count += 1;
            }
            count += countLessThan(value, current.right);
        }
        if (current.left != null && current.right != null)
        {
            if (value.CompareTo(current.value) < 0)
            {
                count += 1;
            }
            count += countLessThan(value, current.left);
            count += countLessThan(value, current.right);
        }
        return(count);
    }
예제 #10
0
        private int ProjectSorter(
            GenericRecursor <T, TRet> x
            , GenericRecursor <T, TRet> y, int i)
        {
            SortDirection direction = this.m_sorts[i].Direction;

            if (x == null && y == null)
            {
                return(0);
            }

            if (x == null || y == null)
            {
                // return (int)direction * (x == null ? -1 : 1); // NULL-Values at top when ASC, bottom when DESC
                // return (int)direction * (x == null ? 1 : -1); // NULL-Values at bottom when ASC, top when DESC

                // return (x == null ? -1 : 1); // NULL-Values at top, indep. of search dir
                return(x == null ? 1 : -1);  // NULL-Values at bottom, indep. of search dir
            } // End if (x == null || y == null)


            if (x.Me == null && y.Me == null)
            {
                return(0);
            }

            if (x.Me == null || y.Me == null)
            {
                // return (int)direction * (x.Me == null ? -1 : 1); // NULL-Values at top when ASC, bottom when DESC
                // return (int)direction * (x.Me == null ? 1 : -1); // NULL-Values at bottom when ASC, top when DESC

                // return (x.Me == null ? -1 : 1); // NULL-Values at top, indep. of search dir
                return(x.Me == null ? 1 : -1);  // NULL-Values at bottom, indep. of search dir
            } // End if (x.Me == null || y.Me == null)

            System.IComparable a = this.m_sorts[i].Sort(x.Me);
            System.IComparable b = this.m_sorts[i].Sort(y.Me);

            if (a == null && b == null)
            {
                return(0);
            }

            if (a == null || b == null)
            {
                // return (int)direction * (a == null ? -1 : 1); // NULL-Values at top when ASC, bottom when DESC
                // return (int)direction * (a == null ? 1 : -1); // NULL-Values at bottom when ASC, top when DESC

                // return (a == null ? -1 : 1); // NULL-Values at top, indep. of search dir
                return(a == null ? 1 : -1);  // NULL-Values at bottom, indep. of search dir
            } // End if (a == null || b == null)

            return((int)direction * a.CompareTo(b));
        } // End Function ProjectSorter
예제 #11
0
 private int countmethod(BinaryTree.Node node, System.IComparable input)
 {
     if (node == null)
     {
         return(0);
     }
     if (input.CompareTo(node.value) < 0)
     {
         return(1 + countmethod(node.right, input) + countmethod(node.left, input));
     }
     return(0 + countmethod(node.right, input) + countmethod(node.left, input));
 }
예제 #12
0
 private int h(System.IComparable value, BinaryTree.Node n)
 {
     if (n == null)
     {
         return(0);
     }
     if (value.CompareTo(n.value) < 0)
     {
         return(1 + h(value, n.left) + h(value, n.right));
     }
     return(h(value, n.left) + h(value, n.right));
 }
예제 #13
0
    public override bool check()
    {
        System.IComparable chk = (System.IComparable)IsoSwitchesManager.getInstance().getIsoSwitches().consultSwitch(id);
        if (chk == null)
        {
            return(false);
        }

        bool c = false;

        switch (comparationType)
        {
        case ComparationType.Equal: c = chk.CompareTo(value.Value) == 0; break;

        case ComparationType.Greather: c = chk.CompareTo(value.Value) > 0; break;

        case ComparationType.Less: c = chk.CompareTo(value.Value) < 0; break;

        case ComparationType.Distinct: c = chk.CompareTo(value.Value) != 0; break;

        case ComparationType.GreatherEqual: c = chk.CompareTo(value.Value) >= 0; break;

        case ComparationType.LessEqual: c = chk.CompareTo(value.Value) <= 0; break;
        }

        return(c);
    }
예제 #14
0
 private int countLessThan(BinaryTree.Node current, System.IComparable value)
 {
     if (current == null)
     {
         return(0);
     }
     if (value.CompareTo(current.value) < 0)
     {
         return(1 + countLessThan(current.right, value) + countLessThan(current.left, value
                                                                        ));
     }
     return(countLessThan(current.right, value) + countLessThan(current.left, value));
 }
예제 #15
0
    /**
     * Simple insertion sort.
     * @param a an array of System.IComparable items.
     */
    public static void insertionSort(System.IComparable [] a)
    {
        int j;

/* 1*/ for (int p = 1; p < a.Length; p++)
        {
/* 2*/ System.IComparable tmp = a[p];
/* 3*/ for (j = p; j > 0 && tmp.CompareTo(a[j - 1]) < 0; j--)
            {
/* 4*/ a[j] = a[j - 1];
            }
/* 5*/ a[j] = tmp;
        }
    }
예제 #16
0
    private int countLessThan(BinaryTree.Node cur, System.IComparable value)
    {
        if (cur == null)
        {
            return(0);
        }
        int tmp = 0;

        if (value.CompareTo(cur.value) < 0)
        {
            tmp = 1;
        }
        return(tmp + countLessThan(cur.left, value) + countLessThan(cur.right, value));
    }
예제 #17
0
    private int clt(BinaryTree.Node current, System.IComparable val)
    {
        if (current == null)
        {
            return(0);
        }
        int ret = 0;

        if (val.CompareTo(current.value) < 0)
        {
            ret++;
        }
        return(ret + clt(current.left, val) + clt(current.right, val));
    }
예제 #18
0
    /**
     * Internal insertion sort routine for subarrays
     * that is used by quicksort.
     * @param a an array of System.IComparable items.
     * @param left the left-most index of the subarray.
     * @param right the right-most index of the subarray.
     */
    private static void insertionSort(System.IComparable [] a, int left, int right)
    {
        for (int p = left + 1; p <= right; p++)
        {
            System.IComparable tmp = a[p];
            int j;

            for (j = p; j > left && tmp.CompareTo(a[j - 1]) < 0; j--)
            {
                a[j] = a[j - 1];
            }
            a[j] = tmp;
        }
    }
예제 #19
0
    private int helper(BinaryTree.Node current, System.IComparable value)
    {
        if (current == null)
        {
            return(0);
        }
        int count = 0;

        if (value.CompareTo(current.value) < 0)
        {
            count = 1;
        }
        return(count + helper(current.right, value) + helper(current.left, value));
    }
예제 #20
0
 private int countLessThan(System.IComparable value, int count, BinaryTree.Node current
                           )
 {
     if (current == null)
     {
         return(count);
     }
     if (value.CompareTo(current.value) < 0)
     {
         count++;
     }
     return(count + countLessThan(value, 0, current.left) + countLessThan(value, 0, current
                                                                          .right));
 }
예제 #21
0
 public virtual int countLessThan(System.IComparable inputValue, BinaryTree.Node current
                                  )
 {
     if (current == null)
     {
         return(0);
     }
     if (inputValue.CompareTo(current.value) < 0)
     {
         return(1 + countLessThan(inputValue, current.left) + countLessThan(inputValue, current
                                                                            .right));
     }
     return(countLessThan(inputValue, current.left) + countLessThan(inputValue, current
                                                                    .right));
 }
예제 #22
0
    protected internal virtual int countLessThan(System.IComparable value, BinaryTree.Node
                                                 current)
    {
        if (current == null)
        {
            return(0);
        }
        int c = 0;

        if (value.CompareTo(current.value) < 0)
        {
            c = 1;
        }
        return(c + countLessThan(value, current.left) + countLessThan(value, current.right
                                                                      ));
    }
예제 #23
0
    protected internal virtual int countLessThan(BinaryTree.Node current, System.IComparable
                                                 value)
    {
        if (current == null)
        {
            return(0);
        }
        int count = 0;

        if (value.CompareTo(current.value) < 0)
        {
            count++;
        }
        return(count + countLessThan(current.left, value) + countLessThan(current.right,
                                                                          value));
    }
예제 #24
0
    private int countLess(BinaryTree.Node root, System.IComparable value)
    {
        if (root == null)
        {
            return(0);
        }
        int lessLeft  = countLess(root.left, value);
        int lessRight = countLess(root.right, value);
        int selfCount = 0;

        if (value.CompareTo(root.value) < 0)
        {
            selfCount = 1;
        }
        return(lessLeft + lessRight + selfCount);
    }
예제 #25
0
 private int countLessThan(System.IComparable pvalue, BinaryTree.Node current)
 {
     if (current == null)
     {
         return(0);
     }
     if (pvalue.CompareTo(current.value) < 0)
     {
         return(1 + countLessThan(pvalue, current.left) + countLessThan(pvalue, current.right
                                                                        ));
     }
     else
     {
         return(countLessThan(pvalue, current.left) + countLessThan(pvalue, current.right));
     }
 }
예제 #26
0
    public virtual int count(BinaryTree.Node root, System.IComparable value)
    {
        if (root == null)
        {
            return(0);
        }
        int count = 0;

        BinaryTree.Node    current = root;
        System.IComparable tmp     = current.value;
        if (tmp.CompareTo(value) > 0)
        {
            count = 1;
        }
        return(count(current.left, value) + count + count(current.right, value));
    }
예제 #27
0
        } // End Function ListClasses

        public List <TEntity> GetSortedInDotNet <TEntity>(
            Expression <System.Func <TEntity, bool> > predicate
            , params BlueMine.Data.SortTerm <TEntity>[] sorts
            ) where TEntity : class
        {
            List <TEntity> ls =
                this.m_ctx.Set <TEntity>()
                .Where(predicate)
                .AsNoTracking()
                .ToList();

            for (int i = 0; i < sorts.Length; ++i)
            {
                ls.Sort(
                    delegate(TEntity x, TEntity y)
                {
                    if (x == null && y == null)
                    {
                        return(0);
                    }

                    if (x == null || y == null)
                    {
                        return(x == null ? 1 : -1);
                    }

                    System.IComparable a = sorts[i].Sort(x);
                    System.IComparable b = sorts[i].Sort(y);

                    if (a == null && b == null)
                    {
                        return(0);
                    }

                    if (a == null || b == null)
                    {
                        return(a == null ? 1 : -1);
                    }

                    return(((int)(sorts[i].Direction)) * a.CompareTo(b));
                }     // End Delegate Comparison<in T>(T x, T y);
                    );
            } // Next i

            return(ls);
        } // End Function GetSortedInDotNet
예제 #28
0
    private int countLessThan(BinaryTree.Node current, System.IComparable obj)
    {
        int count = 0;

        if (obj.CompareTo(current.value) < 0)
        {
            count++;
        }
        if (current.right != null)
        {
            count += countLessThan(current.right, obj);
        }
        if (current.left != null)
        {
            count += countLessThan(current.left, obj);
        }
        return(count);
    }
예제 #29
0
    private int helper(System.IComparable value, BinaryTree.Node current)
    {
        int count = 0;

        if (value == null)
        {
            throw new System.ArgumentException();
        }
        if (current == null)
        {
            return(0);
        }
        if (value.CompareTo(current.value) < 0)
        {
            count++;
        }
        return(helper(value, current.left) + helper(value, current.right) + count);
    }
        static StackObject *CompareTo_0(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 @other = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.IComparable <System.Int32> instance_of_this_method = (System.IComparable <System.Int32>) typeof(System.IComparable <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.CompareTo(@other);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method;
            return(__ret + 1);
        }