Example #1
0
        void VerifyEnumerator(IEnumerator <Quote> e, long tickStart, long tickEnd, IterationOrder order = IterationOrder.AscentOrder)
        {
            int  n        = 0;
            long tickCurr = 0;

            if (order == IterationOrder.DescentOrder)
            {
                tickCurr = long.MaxValue;
            }
            while (e.MoveNext())
            {
                Quote q = e.Current;
                Tests.Assert(q.Ticks >= tickStart);
                Tests.Assert(q.Ticks <= tickEnd);
                // TODO: FAILED_TEST
                if (order == IterationOrder.AscentOrder)
                {
                    Tests.Assert(q.Ticks >= tickCurr);
                }
                else
                {
                    Tests.Assert(q.Ticks <= tickCurr);
                }
                tickCurr = q.Ticks;
                n++;
            }
            Tests.Assert(!e.MoveNext());
            Tests.AssertException <InvalidOperationException>(
                () => { long ticks = e.Current.Ticks; });
            e.Reset();
            Tests.Assert(e.MoveNext());
        }
 /// <summary>
 /// Creates an instance whose range is the k-element subsets of
 /// {0, ..., n - 1} represented as <c>int[]</c> arrays.
 /// <para>
 /// If the <c>iterationOrder</c> argument is set to
 /// <see cref="IterationOrder.LEXICOGRAPHIC"/>, the arrays returned by the
 /// <see cref="iterator()"/> are sorted in descending order and
 /// they are visited in lexicographic order with significance from
 /// right to left.
 /// For example, <c>new Combinations(4, 2).iterator()</c> returns
 /// an iterator that will generate the following sequence of arrays
 /// on successive calls to
 /// <c>next()</c>:<para/>
 /// <c>[0, 1], [0, 2], [1, 2], [0, 3], [1, 3], [2, 3]</c>
 /// </para>
 /// If <c>k == 0</c> an iterator containing an empty array is returned;
 /// if <c>k == n</c> an iterator containing [0, ..., n - 1] is returned.
 ///
 /// </summary>
 /// <param name="n">Size of the set from which subsets are selected.</param>
 /// <param name="k">Size of the subsets to be enumerated.></param>
 /// <param name="iterationOrder">Specifies the <see cref="iterator()"/>.</param>
 /// <exception cref="NotPositiveException"> if <c>n < 0</c>.</exception>
 /// <exception cref="NumberIsTooLargeException"> if <c>k > n</c>.</exception>
 private Combinations(int n, int k, IterationOrder iterationOrder)
 {
     CombinatoricsUtils.checkBinomial(n, k);
     this.n = n;
     this.k = k;
     this.iterationOrder = iterationOrder;
 }
Example #3
0
        private IEnumerable iterator(long from, long till, IterationOrder order)
        {
            IEnumerator enumerator = index.GetEnumerator(from - maxBlockTimeInterval, till, order);

            return(order == IterationOrder.AscentOrder
                ? (IEnumerable) new TimeSeriesEnumerator(enumerator, from, till)
                : (IEnumerable) new TimeSeriesReverseEnumerator(enumerator, from, till));
        }
Example #4
0
        private IEnumerable <T> iterator(long from, long till, IterationOrder order)
        {
            IEnumerable <TimeSeriesBlock> enumerable = index.Range(from - maxBlockTimeInterval, till, order);

            return(order == IterationOrder.AscentOrder
                ? (IEnumerable <T>) new TimeSeriesEnumerable(enumerable, from, till)
                : (IEnumerable <T>) new TimeSeriesReverseEnumerable(enumerable, from, till));
        }
        /// <summary>
        /// Get all items containing specified attribute in desired order
        /// </summary>
        /// <param name="name">attribute name</param>
        /// <param name="order">ascending or descending sort order</param>
        /// <returns>iterator through all items containing specified attribute or null if there is not such attribute in the database</returns>
        public IEnumerable <Item> GetOccurrences(String name, IterationOrder order)
        {
            checkIfActive();
            int id;

            if (!db.name2id.TryGetValue(name, out id))
            {
                return(null);
            }
            Index index = (Index)db.storage.GetObjectByOID(id);

            return(new Item.ItemEnumerable(index.Range(null, null, order)));
        }
Example #6
0
        static int VerifyDictionaryEnumerator(IDictionaryEnumerator de, IterationOrder order)
        {
            long prev = long.MinValue;

            if (order == IterationOrder.DescentOrder)
            {
                prev = long.MaxValue;
            }
            int i = 0;

            while (de.MoveNext())
            {
                DictionaryEntry e1 = (DictionaryEntry)de.Current;
                DictionaryEntry e2 = de.Entry;
                Tests.Assert(e1.Equals(e2));
                long k  = (long)e1.Key;
                long k2 = (long)de.Key;
                Tests.Assert(k == k2);
                RecordFull v1 = (RecordFull)e1.Value;
                RecordFull v2 = (RecordFull)de.Value;
                Tests.Assert(v1.Equals(v2));
                Tests.Assert(v1.Int32Val == k);
                if (order == IterationOrder.AscentOrder)
                {
                    Tests.Assert(k >= prev);
                }
                else
                {
                    Tests.Assert(k <= prev);
                }
                prev = k;
                i++;
            }
            Tests.VerifyDictionaryEnumeratorDone(de);
            return(i);
        }
Example #7
0
        static int VerifyDictionaryEnumerator(IDictionaryEnumerator de, IterationOrder order)
        {
            string prev = "";

            if (order == IterationOrder.DescentOrder)
            {
                prev = "9999999999999999999";
            }
            int i = 0;

            while (de.MoveNext())
            {
                DictionaryEntry e1 = (DictionaryEntry)de.Current;
                DictionaryEntry e2 = de.Entry;
                Tests.Assert(e1.Equals(e2));
                string k  = (string)e1.Key;
                string k2 = (string)de.Key;
                Tests.Assert(k == k2);
                RecordFull v1 = (RecordFull)e1.Value;
                RecordFull v2 = (RecordFull)de.Value;
                Tests.Assert(v1.Equals(v2));
                Tests.Assert(v1.StrVal == k);
                if (order == IterationOrder.AscentOrder)
                {
                    Tests.Assert(k.CompareTo(prev) >= 0);
                }
                else
                {
                    Tests.Assert(k.CompareTo(prev) <= 0);
                }
                prev = k;
                i++;
            }
            Tests.VerifyDictionaryEnumeratorDone(de);
            return(i);
        }
        public IEnumerator GetEnumerator(object from, object till, IterationOrder order)
#endif
        {
            return(Range(from, till, order).GetEnumerator());
        }
Example #9
0
 void VerifyEnumerator(IEnumerator<Quote> e, long tickStart, long tickEnd, IterationOrder order = IterationOrder.AscentOrder)
 {
     int n = 0;
     long tickCurr = 0;
     if (order == IterationOrder.DescentOrder)
         tickCurr = long.MaxValue;
     while (e.MoveNext())
     {
         Quote q = e.Current;
         Tests.Assert(q.Ticks >= tickStart);
         Tests.Assert(q.Ticks <= tickEnd);
         // TODO: FAILED_TEST
         if (order == IterationOrder.AscentOrder)
             Tests.Assert(q.Ticks >= tickCurr);
         else
             Tests.Assert(q.Ticks <= tickCurr);
         tickCurr = q.Ticks;
         n++;
     }
     Tests.Assert(!e.MoveNext());
     Tests.AssertException<InvalidOperationException>(
         () => { long ticks = e.Current.Ticks; });
     e.Reset();
     Tests.Assert(e.MoveNext());
 }
 /// <summary>
 /// Constructor of order-by component with specified sort order
 /// </summary>
 /// <param name="name">attribute name</param>
 /// <param name="order">sort ascending or descebding sort order</param>
 public OrderBy(String name, IterationOrder order)
 {
     this.name  = name;
     this.order = order;
 }
 public IEnumerable <V> Range(K from, K till, IterationOrder order)
Example #12
0
 public IEnumerable Range(DateTime from, DateTime till, IterationOrder order)
 {
     return(iterator(from.Ticks, till.Ticks, order));
 }
 public IEnumerator <V> GetEnumerator(K from, K till, IterationOrder order)
Example #14
0
 public IEnumerator <T> GetEnumerator(DateTime from, DateTime till, IterationOrder order)
Example #15
0
 public IEnumerator <T> GetEnumerator(IterationOrder order)
        public IEnumerable StartsWith(string prefix, IterationOrder order)
#endif
        {
            return(new ExtendEnumerable(index.StartsWith(transformStringKey(prefix), order)));
        }
 public virtual IDictionaryEnumerator GetDictionaryEnumerator(Key from, Key till, IterationOrder order)
 {
     return(new ExtendDictionaryEnumerator(index.GetDictionaryEnumerator(transformKey(from), transformKey(till), order)));
 }
 public IEnumerable <V> StartsWith(string prefix, IterationOrder order)
 IEnumerable GenericIndex.StartsWith(string prefix, IterationOrder order)
 {
     return((IEnumerable)StartsWith(prefix, order));
 }
        public IEnumerable Range(object from, object till, IterationOrder order)
#endif
        {
            return(Range(KeyBuilder.getKeyFromObject(from), KeyBuilder.getKeyFromObject(till), order));
        }
Example #21
0
 public IEnumerator GetEnumerator(DateTime from, DateTime till, IterationOrder order)
 {
     return(iterator(from.Ticks, till.Ticks, order).GetEnumerator());
 }
        public virtual IEnumerable Range(Key from, Key till, IterationOrder order)
#endif
        {
            return(new ExtendEnumerable(index.Range(transformKey(from), transformKey(till), order)));
        }
Example #23
0
 public IEnumerator GetEnumerator(IterationOrder order)
 {
     return(iterator(0, Int64.MaxValue, order).GetEnumerator());
 }
Example #24
0
        public override IEnumerable Range(Key from, Key till, IterationOrder order)
#endif
        {
            return(base.Range(convertKey(from), convertKey(till), order));
        }
Example #25
0
 public IEnumerable Range(IterationOrder order)
 {
     return(iterator(0, Int64.MaxValue, order));
 }
Example #26
0
 static int VerifyDictionaryEnumerator(IDictionaryEnumerator de, IterationOrder order)
 {
     long prev = long.MinValue;
     if (order == IterationOrder.DescentOrder)
         prev = long.MaxValue;
     int i = 0;
     while (de.MoveNext())
     {
         DictionaryEntry e1 = (DictionaryEntry)de.Current;
         DictionaryEntry e2 = de.Entry;
         Tests.Assert(e1.Equals(e2));
         long k = (long)e1.Key;
         long k2 = (long)de.Key;
         Tests.Assert(k == k2);
         RecordFull v1 = (RecordFull)e1.Value;
         RecordFull v2 = (RecordFull)de.Value;
         Tests.Assert(v1.Equals(v2));
         Tests.Assert(v1.Int32Val == k);
         if (order == IterationOrder.AscentOrder)
             Tests.Assert(k >= prev);
         else
             Tests.Assert(k <= prev);
         prev = k;
         i++;
     }
     Tests.VerifyDictionaryEnumeratorDone(de);
     return i;
 }
Example #27
0
 /// <summary>
 /// Constructor of order-by component with specified sort order
 /// </summary>    
 /// <param name="name">attribute name</param>
 /// <param name="order">sort ascending or descebding sort order</param>
 public OrderBy(String name, IterationOrder order)
 {
     this.name = name;
     this.order = order;
 }
 public virtual IEnumerable <V> Range(Key from, Key till, IterationOrder order)
Example #29
0
 public IEnumerable <T> Range(DateTime from, DateTime till, IterationOrder order)
 IEnumerable GenericIndex.Range(Key from, Key till, IterationOrder order)
 {
     return((IEnumerable)Range(from, till, order));
 }
Example #31
0
 public override IEnumerable <T> Range(Key from, Key till, IterationOrder order)
Example #32
0
 public IEnumerable <T> Range(IterationOrder order)
Example #33
0
 public override IDictionaryEnumerator GetDictionaryEnumerator(Key from, Key till, IterationOrder order)
 {
     return(base.GetDictionaryEnumerator(convertKey(from), convertKey(till), order));
 }
Example #34
0
 static int VerifyDictionaryEnumerator(IDictionaryEnumerator de, IterationOrder order)
 {
     string prev = "";
     if (order == IterationOrder.DescentOrder)
         prev = "9999999999999999999";
     int i = 0;
     while (de.MoveNext())
     {
         DictionaryEntry e1 = (DictionaryEntry)de.Current;
         DictionaryEntry e2 = de.Entry;
         Tests.Assert(e1.Equals(e2));
         string k = (string)e1.Key;
         string k2 = (string)de.Key;
         Tests.Assert(k == k2);
         RecordFull v1 = (RecordFull)e1.Value;
         RecordFull v2 = (RecordFull)de.Value;
         Tests.Assert(v1.Equals(v2));
         Tests.Assert(v1.StrVal == k);
         if (order == IterationOrder.AscentOrder)
             Tests.Assert(k.CompareTo(prev) >= 0);
         else
             Tests.Assert(k.CompareTo(prev) <= 0);
         prev = k;
         i++;
     }
     Tests.VerifyDictionaryEnumeratorDone(de);
     return i;
 }