public static ISeq create(final long start, long end, long step) { if(step > 0) { if(end <= start) return PersistentList.EMPTY; return new LongRange(start, end, step, positiveStep(end)); } else if(step < 0) { if(end >= start) return PersistentList.EMPTY; return new LongRange(start, end, step, negativeStep(end)); } else { if(end == start) return PersistentList.EMPTY; return Repeat.create(start); } }
public ISeq chunkedNext() { return chunkedMore().seq(); }
public ISeq next() { if(_next != null) return _next; forceChunk(); if(_chunk.count() > 1) { LongChunk smallerChunk = _chunk.dropFirst(); _next = new LongRange(smallerChunk.first(), end, step, boundsCheck, smallerChunk, _chunkNext); return _next; } return chunkedNext(); }
public static ISeq create(long end) { if(end > 0) return new LongRange(0L, end, 1L, positiveStep(end)); return PersistentList.EMPTY; }
public void forceChunk() { if(_chunk != null) return; long count; try { count = rangeCount(start, end, step); } catch(ArithmeticException e) { // 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 be <= CHUNK_SIZE } }
public int count() { try { long c = rangeCount(start, end, step); if(c > Integer.MAX_VALUE) { return Numbers.throwIntOverflow(); } else { return (int) c; } } catch(ArithmeticException e) { // rare case from large range or step, fall back to iterating and counting Iterator iter = this.iterator(); long count = 0; while(iter.hasNext()) { iter.next(); count++; } if(count > Integer.MAX_VALUE) return Numbers.throwIntOverflow(); else return (int)count; } }
public ISeq chunkedMore() { forceChunk(); if(_chunkNext == null) return PersistentList.EMPTY; return _chunkNext; }
public Obj withMeta(IPersistentMap meta){ if(meta == _meta) return this; return new LongRange(meta, start, end, step, boundsCheck, _chunk, _chunkNext); }
public void forceChunk() { if(_chunk != null) return; long count; try { count = rangeCount(start, end, step); } catch(ArithmeticException e) { // 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 _chunk = new LongChunk(start, step, CHUNK_SIZE); _chunkNext = new LongRange(nextStart, end, step, boundsCheck); } else { // last chunk _chunk = new LongChunk(start, step, (int) count); // count must be <= CHUNK_SIZE } }
public static ISeq create(long start, long end) { if(start >= end) return PersistentList.EMPTY; return new LongRange(start, end, 1L, positiveStep(end)); }
public int count() { try { long c = rangeCount(start, end, step); if(c > Integer.MAX_VALUE) { return Numbers.throwIntOverflow(); } else { return (int) c; } } catch(ArithmeticException e) { // rare case from large range or step, fall back to iterating and counting Iterator iter = this.iterator(); long count = 0; while(iter.hasNext()) { iter.next(); count++; } if(count > Integer.MAX_VALUE) return Numbers.throwIntOverflow(); else return (int)count; } }
public IChunk chunkedFirst() { forceChunk(); return _chunk; }
public Obj withMeta(IPersistentMap meta){ if(meta == _meta) return this; return new LongRange(meta, start, end, step, boundsCheck, _chunk, _chunkNext); }
public static ISeq create(final long start, long end, long step) { if(step > 0) { if(end <= start) return PersistentList.EMPTY; return new LongRange(start, end, step, positiveStep(end)); } else if(step < 0) { if(end >= start) return PersistentList.EMPTY; return new LongRange(start, end, step, negativeStep(end)); } else { if(end == start) return PersistentList.EMPTY; return Repeat.create(start); } }
public ISeq next() { if(_next != null) return _next; forceChunk(); if(_chunk.count() > 1) { LongChunk smallerChunk = _chunk.dropFirst(); _next = new LongRange(smallerChunk.first(), end, step, boundsCheck, smallerChunk, _chunkNext); return _next; } return chunkedNext(); }
public static ISeq create(long end) { if(end > 0) return new LongRange(0L, end, 1L, positiveStep(end)); return PersistentList.EMPTY; }
public ISeq chunkedMore() { forceChunk(); if(_chunkNext == null) return PersistentList.EMPTY; return _chunkNext; }
public ISeq chunkedNext() { return chunkedMore().seq(); }
public static ISeq create(long start, long end) { if(start >= end) return PersistentList.EMPTY; return new LongRange(start, end, 1L, positiveStep(end)); }
public IChunk chunkedFirst() { forceChunk(); return _chunk; }