Пример #1
0
        /// <summary>
        /// get the collection of all items, sorted by the provided index.
        /// </summary>
        /// <param name="ascending"></param>
        /// <returns></returns>
        public ValueCollection <TKey, TValue> ItemCollection(string indexFieldOrPropertyName, bool ascending)
        {
            IIndex <TValue> index = this.Indexes.getIndex(indexFieldOrPropertyName);

            ValueCollection <TKey, TValue> collection = new ValueCollection <TKey, TValue>(this, index.AllItems(ascending).GetEnumerator());

            return(collection);
        }
Пример #2
0
        public List <TValue> Take(int count)
        {
            lock (this.store._Locker)
            {
                List <TValue> valuelist = new List <TValue>();

                if (count == 0)
                {
                    return(valuelist);
                }

                int skipped = 0;
                int taken   = 0;

                if (string.IsNullOrEmpty(this.OrderByFieldName))
                {
                    // if there is not an order by field, use the primary key.
                    foreach (TValue item in store.ItemCollection(this.ascending))
                    {
                        if (this.predicate(item))
                        {
                            if (skipped < this.skip)
                            {
                                skipped += 1;
                                continue;
                            }

                            valuelist.Add(item);
                            taken += 1;
                            if (taken >= count)
                            {
                                return(valuelist);
                            }
                        }
                    }
                    return(valuelist);
                }
                else
                {
                    // there is an order by field.
                    // check whether this is an index or not.
                    if (store.Indexes.HasIndex(this.OrderByFieldName))
                    {
                        IIndex <TValue> index = store.Indexes.getIndex(this.OrderByFieldName);

                        foreach (Int64 blockposition in index.AllItems(this.ascending))
                        {
                            TValue record = store.getValue(blockposition);

                            if (this.predicate(record))
                            {
                                if (skipped < this.skip)
                                {
                                    skipped += 1;
                                    continue;
                                }

                                valuelist.Add(record);
                                taken += 1;
                                if (taken >= count)
                                {
                                    return(valuelist);
                                }
                            }
                        }

                        return(valuelist);
                    }

                    else
                    {
                        /// the most expensive and brutal way.

                        throw new NotImplementedException("order by non-index field is not support yet");
                    }
                }
            }
        }