当前位置: 首页>>代码示例>>C#>>正文


C# Field.CompareTo方法代码示例

本文整理汇总了C#中Field.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Field.CompareTo方法的具体用法?C# Field.CompareTo怎么用?C# Field.CompareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Field的用法示例。


在下文中一共展示了Field.CompareTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IntersectOn

        private static IndexRange IntersectOn(IndexRange range, SqlExpressionType op, Field value, bool nullCheck)
        {
            var start = range.StartValue;
            var startPosition = range.StartOffset;
            var end = range.EndValue;
            var endPosition = range.EndOffset;

            bool inclusive = op == SqlExpressionType.Is ||
                             op == SqlExpressionType.Equal ||
                             op == SqlExpressionType.GreaterOrEqualThan ||
                             op == SqlExpressionType.SmallerOrEqualThan;

            if (op == SqlExpressionType.Is ||
                op == SqlExpressionType.Equal ||
                op == SqlExpressionType.GreaterThan ||
                op == SqlExpressionType.GreaterOrEqualThan) {
                // With this operator, NULL values must return null.
                if (nullCheck && value.IsNull) {
                    return IndexRange.Null;
                }

                if (start.Equals(IndexRange.FirstInSet)) {
                    start = value;
                    startPosition = inclusive ? RangeFieldOffset.FirstValue : RangeFieldOffset.AfterLastValue;
                } else {
                    int c = value.CompareTo(start);
                    if ((c == 0 && startPosition == RangeFieldOffset.FirstValue) || c > 0) {
                        start = value;
                        startPosition = inclusive ? RangeFieldOffset.FirstValue : RangeFieldOffset.AfterLastValue;
                    }
                }
            }

            if (op == SqlExpressionType.Is ||
                op == SqlExpressionType.Equal ||
                op == SqlExpressionType.SmallerThan ||
                op == SqlExpressionType.SmallerOrEqualThan) {
                // With this operator, NULL values must return null.
                if (nullCheck && value.IsNull) {
                    return IndexRange.Null;
                }

                // If start is first in set, then we have to change it to after NULL
                if (nullCheck && start.Equals(IndexRange.FirstInSet)) {
                    start = Field.Null();
                    startPosition = RangeFieldOffset.AfterLastValue;
                }

                if (end.Equals(IndexRange.LastInSet)) {
                    end = value;
                    endPosition = inclusive ? RangeFieldOffset.LastValue : RangeFieldOffset.BeforeFirstValue;
                } else {
                    int c = value.CompareTo(end);
                    if ((c == 0 && endPosition == RangeFieldOffset.LastValue) || c < 0) {
                        end = value;
                        endPosition = inclusive ? RangeFieldOffset.LastValue : RangeFieldOffset.BeforeFirstValue;
                    }
                }
            }

            // If start and end are not null types (if either are, then it means it
            // is a placeholder value meaning start or end of set).
            if (!start.Equals(IndexRange.FirstInSet) &&
                !end.Equals(IndexRange.LastInSet)) {
                // If start is higher than end, return null
                int c = start.CompareTo(end);
                if ((c == 0 && (startPosition == RangeFieldOffset.AfterLastValue ||
                                endPosition == RangeFieldOffset.BeforeFirstValue)) ||
                    c > 0) {
                    return IndexRange.Null;
                }
            }

            // The new intersected range
            return new IndexRange(startPosition, start, endPosition, end);
        }
开发者ID:deveel,项目名称:deveeldb,代码行数:76,代码来源:IndexRangeSet.cs

示例2: HighestSearch

        private int HighestSearch(Field ob, IList<int> list, int lower, int higher)
        {
            if ((higher - lower) <= 5) {
                // Start from the bottom up until we find the highest val
                for (var i = higher; i >= lower; --i) {
                    int res = ob.CompareTo(GetValue(list[i]));
                    if (res >= 0)
                        return i + 1;
                }
                // Didn't find return lowest
                return lower;
            }

            var mid = (lower + higher)/2;
            int compResult = ob.CompareTo(GetValue(list[mid]));

            if (compResult == 0)
                // We know the bottom is between 'mid' and 'higher'
                return HighestSearch(ob, list, mid, higher);

            if (compResult < 0)
                return HighestSearch(ob, list, lower, mid - 1);

            return HighestSearch(ob, list, mid + 1, higher);
        }
开发者ID:deveel,项目名称:deveeldb,代码行数:25,代码来源:BlindSearchIndex.cs


注:本文中的Field.CompareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。