void ForceChunk() { if (_chunk != null) { return; } long count; try { count = RangeCount(_start, _end, _step); } catch (ArithmeticException) { // size of total range is > Long.MAX_VALUE so must step to count // this only happens in pathological range cases like: // (range -9223372036854775808 9223372036854775807 9223372036854775807) count = SteppingCount(_start, _end, _step); } if (count > CHUNK_SIZE) { // not last chunk long nextStart = _start + (_step * CHUNK_SIZE); // cannot overflow, must be < end _chunkNext = new LongRange(nextStart, _end, _step, _boundsCheck); _chunk = new LongChunk(_start, _step, CHUNK_SIZE); } else { // last chunk _chunk = new LongChunk(_start, _step, (int)count); // count must } }
private LongRange(long start, long end, long step, IBoundsCheck boundsCheck, LongChunk chunk, ISeq chunkNext) { _start = start; _end = end; _step = step; _boundsCheck = boundsCheck; _chunk = chunk; _chunkNext = chunkNext; }
private LongRange(IPersistentMap meta, long start, long end, long step, IBoundsCheck boundsCheck, LongChunk chunk, ISeq chunkNext) : base(meta) { _start = start; _end = end; _step = step; _boundsCheck = boundsCheck; _chunk = chunk; _chunkNext = chunkNext; }
public override ISeq next() { if (_next != null) { return(_next); } ForceChunk(); if (_chunk.count() > 1) { LongChunk smallerChunk = (LongChunk)_chunk.dropFirst(); _next = new LongRange(smallerChunk.first(), _end, _step, _boundsCheck, smallerChunk, _chunkNext); return(_next); } return(chunkedNext()); }