Пример #1
0
 internal TimeSeriesReverseIterator(TimeSeriesImpl enclosingInstance, long from, long till)
 {
     InitBlock(enclosingInstance);
     pos = -1;
     this.from = from;
     blockIterator = Enclosing_Instance.index.GetEnumerator(new Key(from - Enclosing_Instance.maxBlockTimeInterval), new Key(till), IndexSortOrder.Descent);
     //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'IEnumerator.MoveNext' which has a different behavior.
     while (blockIterator.MoveNext())
     {
         //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'IEnumerator.Current' which has a different behavior.
         TimeSeriesBlock block = (TimeSeriesBlock) blockIterator.Current;
         int n = block.used;
         TimeSeriesTick[] e = block.Ticks;
         int l = 0, r = n;
         while (l < r)
         {
             int i = (l + r) >> 1;
             if (till >= e[i].Time)
             {
                 l = i + 1;
             }
             else
             {
                 r = i;
             }
         }
         Assert.That(l == r && (l == n || e[l].Time > till));
         if (l > 0)
         {
             if (e[l - 1].Time >= from)
             {
                 pos = l - 1;
                 currBlock = block;
             }
             return;
         }
     }
 }
Пример #2
0
        internal virtual void InsertInBlock(TimeSeriesBlock block, TimeSeriesTick tick)
        {
            long t = tick.Time;
            int i, n = block.used;

            TimeSeriesTick[] e = block.Ticks;
            int l = 0, r = n;
            while (l < r)
            {
                i = (l + r) >> 1;
                if (t > e[i].Time)
                {
                    l = i + 1;
                }
                else
                {
                    r = i;
                }
            }
            Assert.That(l == r && (l == n || e[l].Time >= t));
            if (r == 0)
            {
                if (e[n - 1].Time - t > maxBlockTimeInterval || n == e.Length)
                {
                    AddNewBlock(tick);
                    return;
                }
                block.timestamp = t;
            }
            else if (r == n)
            {
                if (t - e[0].Time > maxBlockTimeInterval || n == e.Length)
                {
                    AddNewBlock(tick);
                    return;
                }
            }

            if (n == e.Length)
            {
                AddNewBlock(e[n - 1]);
                for (i = n; --i > r; )
                {
                    e[i] = e[i - 1];
                }
            }
            else
            {
                for (i = n; i > r; i--)
                {
                    e[i] = e[i - 1];
                }
                block.used += 1;
            }

            e[r] = tick;
            block.Modify();
        }