예제 #1
0
        private static IEnumerable <TSource> Equal <TSource>(IIndex <int, TSource> source,
                                                             BinaryExpression binaryExpression)
        {
            if (source is Index <int, TSource> )
            {
                Index <int, TSource> index = (Index <int, TSource>)source;
                int max = index.Max();
                ConstantExpression constantExpression = null;
                if (binaryExpression.Right.NodeType == ExpressionType.Constant)
                {
                    constantExpression = (ConstantExpression)binaryExpression.Right;
                }

                if (source.Contains((int)constantExpression.Value))
                {
                    var item = source[(int)constantExpression.Value];
                    yield return(item);
                }
            }
            else if (source is EqualIndex <int, TSource> )
            {
                EqualIndex <int, TSource> index = (EqualIndex <int, TSource>)source;
                ConstantExpression        constantExpression = null;
                if (binaryExpression.Right.NodeType == ExpressionType.Constant)
                {
                    constantExpression = (ConstantExpression)binaryExpression.Right;
                }
                if (source.Contains((int)constantExpression.Value))
                {
                    var item = source[(int)constantExpression.Value];
                    yield return(item);
                }
            }
        }
예제 #2
0
        //public static IIndex<TKey, TSource> ToAvlIndex<TSource, TKey>(
        //    this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) where TKey : IComparable<TKey>
        //{
        //    Index<TKey, TSource> index = new Index<TKey, TSource>();
        //    foreach (var item in source)
        //    {
        //        TKey key = keySelector(item);
        //        index.Add(key, item);
        //    }
        //    return index;
        //}

        public static IIndex <TKey, TSource> ToEqualIndex <TSource, TKey>(
            this IEnumerable <TSource> source, Func <TSource, TKey> keySelector) where TKey : IComparable <TKey>
        {
            EqualIndex <TKey, TSource> index = new EqualIndex <TKey, TSource>();

            foreach (var item in source)
            {
                TKey key = keySelector(item);
                index.Add(key, item);
            }
            return(index);
        }