diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jvm/clojure/lang/ArrayChunk.java | 12 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ChunkBuffer.java | 37 |
2 files changed, 48 insertions, 1 deletions
diff --git a/src/jvm/clojure/lang/ArrayChunk.java b/src/jvm/clojure/lang/ArrayChunk.java index 3d3d645a..08f863cf 100644 --- a/src/jvm/clojure/lang/ArrayChunk.java +++ b/src/jvm/clojure/lang/ArrayChunk.java @@ -16,10 +16,20 @@ public final class ArrayChunk implements Indexed{ final Object[] array; final int off; +final int end; + +public ArrayChunk(Object[] array){ + this(array, 0, array.length); +} public ArrayChunk(Object[] array, int off){ + this(array, off, array.length); +} + +public ArrayChunk(Object[] array, int off, int end){ this.array = array; this.off = off; + this.end = end; } public Object nth(int i){ @@ -27,6 +37,6 @@ public Object nth(int i){ } public int count(){ - return array.length - off; + return end - off; } } diff --git a/src/jvm/clojure/lang/ChunkBuffer.java b/src/jvm/clojure/lang/ChunkBuffer.java new file mode 100644 index 00000000..aee01e0e --- /dev/null +++ b/src/jvm/clojure/lang/ChunkBuffer.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) + * which can be found in the file epl-v10.html at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +/* rich May 26, 2009 */ + +package clojure.lang; + +final public class ChunkBuffer implements Counted{ + Object[] buffer; + int offset; + +public ChunkBuffer(int capacity){ + buffer = new Object[capacity]; + offset = 0; +} + +public void add(Object o){ + buffer[offset++] = o; +} + +public Indexed chunk(){ + ArrayChunk ret = new ArrayChunk(buffer, 0, offset); + buffer = null; + return ret; +} + +public int count(){ + return offset; +} +} |