private void insertInBlock(TimeSeriesBlock block, TimeSeriesTick tick) #endif { long t = tick.Time; int i, n = block.used; int l = 0, r = n; while (l < r) { i = (l + r) >> 1; if (t >= block[i].Time) { l = i + 1; } else { r = i; } } Debug.Assert(l == r && (l == n || block[l].Time >= t)); if (r == 0) { if (block[n - 1].Time - t > maxBlockTimeInterval || n == block.Ticks.Length) { addNewBlock(tick); return; } if (block.timestamp != t) { index.Remove(new Key(block.timestamp), block); block.timestamp = t; index.Put(new Key(block.timestamp), block); } } else if (r == n) { if (t - block[0].Time > maxBlockTimeInterval || n == block.Ticks.Length) { addNewBlock(tick); return; } } if (n == block.Ticks.Length) { addNewBlock(block[n - 1]); Array.Copy(block.Ticks, r, block.Ticks, r + 1, n - r - 1); } else { if (n != r) { Array.Copy(block.Ticks, r, block.Ticks, r + 1, n - r); } block.used += 1; } block[r] = tick; block.Modify(); }
private long remove(long from, long till) { long nRemoved = 0; IEnumerator blockIterator = index.GetEnumerator(from - maxBlockTimeInterval, till); while (blockIterator.MoveNext()) { TimeSeriesBlock block = (TimeSeriesBlock)blockIterator.Current; int n = block.used; int l = 0, r = n; while (l < r) { int i = (l + r) >> 1; if (from > block[i].Time) { l = i + 1; } else { r = i; } } Debug.Assert(l == r && (l == n || block[l].Time >= from)); while (r < n && block[r].Time <= till) { r += 1; nRemoved += 1; } if (l == 0 && r == n) { index.Remove(block.timestamp, block); block.Deallocate(); blockIterator.Reset(); } else if (l != r) { if (l == 0) { index.Remove(block.timestamp, block); block.timestamp = block[r].Time; index.Put(block.timestamp, block); blockIterator.Reset(); } Array.Copy(block.Ticks, r, block.Ticks, l, n - r); block.used = l + n - r; block.Modify(); } } return(nRemoved); }