MCPcopy Index your code
hub / github.com/clojure/clojure / ArrayChunk

Class ArrayChunk

src/jvm/clojure/lang/ArrayChunk.java:17–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15import java.io.Serializable;
16
17public final class ArrayChunk implements IChunk, Serializable {
18
19private static final long serialVersionUID = -8302142882294545702L;
20
21final Object[] array;
22final int off;
23final int end;
24
25public ArrayChunk(Object[] array){
26 this(array, 0, array.length);
27}
28
29public ArrayChunk(Object[] array, int off){
30 this(array, off, array.length);
31}
32
33public ArrayChunk(Object[] array, int off, int end){
34 this.array = array;
35 this.off = off;
36 this.end = end;
37}
38
39public Object nth(int i){
40 return array[off + i];
41}
42
43public Object nth(int i, Object notFound){
44 if(i >= 0 && i < count())
45 return nth(i);
46 return notFound;
47}
48
49public int count(){
50 return end - off;
51}
52
53public IChunk dropFirst(){
54 if(off==end)
55 throw new IllegalStateException("dropFirst of empty chunk");
56 return new ArrayChunk(array, off + 1, end);
57}
58
59public Object reduce(IFn f, Object start) {
60 Object ret = f.invoke(start, array[off]);
61 if(RT.isReduced(ret))
62 return ret;
63 for(int x = off + 1; x < end; x++)
64 {
65 ret = f.invoke(ret, array[x]);
66 if(RT.isReduced(ret))
67 return ret;
68 }
69 return ret;
70}
71}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected