Esempio n. 1
0
        /// <summary>
        /// returns all offset of all records in table of first key column
        /// </summary>
        /// <typeparam name="T">type of key column</typeparam>
        /// <returns></returns>
        internal IEnumerable <int> Rows <T>(DbColumn column = null)
            where T : IComparable <T>
        {
            if (column == null)
            {
                yield break;
            }

            var treeReader = column.IndexTree <T>();

            if (treeReader.Root == null)
            {
                //itemspage has only one page, no tree root
                var page = column.IndexItems <T>().Pages.FirstOrDefault();
                if (page != null)
                {
                    foreach (var cvsOfs in page.Items.SelectMany(i => i.Value))
                    {
                        yield return(cvsOfs);
                    }
                }
            }
            else
            {
                //In-Order return all values
                foreach (var offs in
                         treeReader.DumpTreeNodesInOrder(treeReader.Root)
                         .SelectMany(pair => pair.Value))
                {
                    yield return(offs);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Fast indexed column coomparison by a constant value
        /// </summary>
        /// <typeparam name="T">type of column</typeparam>
        /// <param name="key">table key</param>
        /// <param name="column">comlumn to compare</param>
        /// <param name="comparer">comparison operator</param>
        /// <param name="value">constant value</param>
        /// <returns></returns>
        internal IEnumerable <KeyValuePair <T, List <int> > > CompareIndexedKeyWithKey <T>(
            DbColumn key, DbColumn column, TokenType comparer, T value)
            where T : IComparable <T>
        {
            var nodeTree = column.IndexTree <T>();
            int offset   = -1;

            var collection = Enumerable.Empty <KeyValuePair <T, List <int> > >();

            if (nodeTree.Root == null)
            {
                //go to .bin file directly, it's ONE page of items
                collection = column.IndexItems <T>()
                             .FindByOper(DbGenerator.ItemsPageStart, value, comparer);
            }
            else
            {
                //this's for tree node page structure
                switch (comparer)
                {
                case TokenType.Equal:                         // "="
                    //find page with key
                    var baseNode = nodeTree.FindKey(value) as PageIndexNodeBase <T>;
                    if (baseNode != null)
                    {
                        switch (baseNode.Type)
                        {
                        case MetaIndexType.Node:
                            //it's in a tree node page
                            var nodePage = baseNode as PageIndexNode <T>;
                            if (nodePage != null && nodePage.Values != null)
                            {
                                collection = new KeyValuePair <T, List <int> >[] {
                                    new KeyValuePair <T, List <int> >(value, nodePage.Values)
                                };
                            }
                            break;

                        case MetaIndexType.Items:
                            //it's in a items page
                            offset = ((PageIndexItems <T>)baseNode).Offset;
                            DbKeyValues <T> item = column.IndexItems <T>().Find(offset, value);
                            if (item != null && item.Values != null)
                            {
                                collection = new KeyValuePair <T, List <int> >[] {
                                    new KeyValuePair <T, List <int> >(value, item.Values)
                                };
                            }
                            break;
                        }
                    }
                    break;

                case TokenType.Less:                         // "<"
                    collection = nodeTree.FindLessKey(value, TokenType.Less);
                    break;

                case TokenType.LessOrEqual:                         // "<="
                    collection = nodeTree.FindLessKey(value, TokenType.LessOrEqual);
                    break;

                case TokenType.Greater:                         // ">"
                    collection = nodeTree.FindGreaterKey(value, TokenType.Greater);
                    break;

                case TokenType.GreaterOrEqual:                          //">="
                    collection = nodeTree.FindGreaterKey(value, TokenType.GreaterOrEqual);
                    break;
                    //throw new ArgumentException($"Operator: {Expression.Operator.Name} not implemented yet!");
                }
            }

            foreach (var ofs in collection)
            {
                yield return(ofs);
            }
        }