diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/core.clj | 36 | ||||
-rw-r--r-- | src/jvm/clojure/lang/IEditableCollection.java | 2 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ITransientAssociative.java (renamed from src/jvm/clojure/lang/IMutableAssociative.java) | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ITransientCollection.java (renamed from src/jvm/clojure/lang/IMutableCollection.java) | 6 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ITransientVector.java (renamed from src/jvm/clojure/lang/IMutableVector.java) | 6 | ||||
-rw-r--r-- | src/jvm/clojure/lang/PersistentVector.java | 32 |
6 files changed, 44 insertions, 42 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index ef5f2482..a275236d 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -4319,37 +4319,39 @@ [promise val] (promise val)) ;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn mutable - "Returns a new, mutable version of the collection, in constant time." +(defn transient + "Returns a new, transient version of the collection, in constant time." [#^clojure.lang.IEditableCollection coll] - (.mutable coll)) + (.asTransient coll)) -(defn immutable! - "Returns a new, immutable version of the mutable collection, in constant time." - [#^clojure.lang.IMutableCollection coll] - (.immutable coll)) +(defn persistent! + "Returns a new, persistent version of the transient collection, in + constant time. The transient collection cannot be used after this + call, any such use will throw an exception." + [#^clojure.lang.ITransientCollection coll] + (.persistent coll)) (defn conj! - "Adds x to the mutable collection, and return coll. The 'addition' + "Adds x to the transient collection, and return coll. The 'addition' may happen at different 'places' depending on the concrete type." - [#^clojure.lang.IMutableCollection coll x] + [#^clojure.lang.ITransientCollection coll x] (.conj coll x)) (defn assoc! - "When applied to a mutable map, adds mapping of key(s) to - val(s). When applied to a mutable vector, sets the val at index. + "When applied to a transient map, adds mapping of key(s) to + val(s). When applied to a transient vector, sets the val at index. Note - index must be <= (count vector). Returns coll." - ([#^clojure.lang.IMutableAssociative coll key val] (.assoc coll key val)) - ([#^clojure.lang.IMutableAssociative coll key val & kvs] + ([#^clojure.lang.ITransientAssociative coll key val] (.assoc coll key val)) + ([#^clojure.lang.ITransientAssociative coll key val & kvs] (let [ret (.assoc coll key val)] (if kvs (recur ret (first kvs) (second kvs) (nnext kvs)) ret)))) (defn pop! - "Removes the last item from a mutable vector. If + "Removes the last item from a transient vector. If the collection is empty, throws an exception. Returns coll" - [#^clojure.lang.IMutableVector coll] + [#^clojure.lang.ITransientVector coll] (.pop coll)) ;redef into with batch support @@ -4358,10 +4360,10 @@ from-coll conjoined." [to from] (if (instance? clojure.lang.IEditableCollection to) - (#(loop [ret (mutable to) items (seq from)] + (#(loop [ret (transient to) items (seq from)] (if items (recur (conj! ret (first items)) (next items)) - (immutable! ret)))) + (persistent! ret)))) (#(loop [ret to items (seq from)] (if items (recur (conj ret (first items)) (next items)) diff --git a/src/jvm/clojure/lang/IEditableCollection.java b/src/jvm/clojure/lang/IEditableCollection.java index be447958..63ccb53a 100644 --- a/src/jvm/clojure/lang/IEditableCollection.java +++ b/src/jvm/clojure/lang/IEditableCollection.java @@ -13,5 +13,5 @@ package clojure.lang; public interface IEditableCollection{ -IMutableCollection mutable(); +ITransientCollection asTransient(); } diff --git a/src/jvm/clojure/lang/IMutableAssociative.java b/src/jvm/clojure/lang/ITransientAssociative.java index 1eef92c2..a4d2655a 100644 --- a/src/jvm/clojure/lang/IMutableAssociative.java +++ b/src/jvm/clojure/lang/ITransientAssociative.java @@ -12,7 +12,7 @@ package clojure.lang; -public interface IMutableAssociative extends IMutableCollection, ILookup{ +public interface ITransientAssociative extends ITransientCollection, ILookup{ -IMutableAssociative assoc(Object key, Object val); +ITransientAssociative assoc(Object key, Object val); } diff --git a/src/jvm/clojure/lang/IMutableCollection.java b/src/jvm/clojure/lang/ITransientCollection.java index a41f1701..0079d33b 100644 --- a/src/jvm/clojure/lang/IMutableCollection.java +++ b/src/jvm/clojure/lang/ITransientCollection.java @@ -12,9 +12,9 @@ package clojure.lang; -public interface IMutableCollection{ +public interface ITransientCollection{ -IMutableCollection conj(Object val); +ITransientCollection conj(Object val); -IPersistentCollection immutable(); +IPersistentCollection persistent(); } diff --git a/src/jvm/clojure/lang/IMutableVector.java b/src/jvm/clojure/lang/ITransientVector.java index 3deab315..6311754c 100644 --- a/src/jvm/clojure/lang/IMutableVector.java +++ b/src/jvm/clojure/lang/ITransientVector.java @@ -12,9 +12,9 @@ package clojure.lang; -public interface IMutableVector extends IMutableAssociative, Indexed{ +public interface ITransientVector extends ITransientAssociative, Indexed{ -IMutableVector assocN(int i, Object val); +ITransientVector assocN(int i, Object val); -IMutableVector pop(); +ITransientVector pop(); } diff --git a/src/jvm/clojure/lang/PersistentVector.java b/src/jvm/clojure/lang/PersistentVector.java index 752bccf8..2d55e2e8 100644 --- a/src/jvm/clojure/lang/PersistentVector.java +++ b/src/jvm/clojure/lang/PersistentVector.java @@ -43,24 +43,24 @@ final Object[] tail; public final static PersistentVector EMPTY = new PersistentVector(0, 5, EMPTY_NODE, new Object[]{}); static public PersistentVector create(ISeq items){ - MutableVector ret = EMPTY.mutable(); + TransientVector ret = EMPTY.asTransient(); for(; items != null; items = items.next()) ret = ret.conj(items.first()); - return ret.immutable(); + return ret.persistent(); } static public PersistentVector create(List items){ - MutableVector ret = EMPTY.mutable(); + TransientVector ret = EMPTY.asTransient(); for(Object item : items) ret = ret.conj(item); - return ret.immutable(); + return ret.persistent(); } static public PersistentVector create(Object... items){ - MutableVector ret = EMPTY.mutable(); + TransientVector ret = EMPTY.asTransient(); for(Object item : items) ret = ret.conj(item); - return ret.immutable(); + return ret.persistent(); } PersistentVector(int cnt, int shift, Node root, Object[] tail){ @@ -80,8 +80,8 @@ PersistentVector(IPersistentMap meta, int cnt, int shift, Node root, Object[] ta this.tail = tail; } -public MutableVector mutable(){ - return new MutableVector(this); +public TransientVector asTransient(){ + return new TransientVector(this); } final int tailoff(){ @@ -369,20 +369,20 @@ private Node popTail(int level, Node node){ } } -static final class MutableVector extends AFn implements IMutableVector, Counted{ +static final class TransientVector extends AFn implements ITransientVector, Counted{ int cnt; int shift; Node root; Object[] tail; - MutableVector(int cnt, int shift, Node root, Object[] tail){ + TransientVector(int cnt, int shift, Node root, Object[] tail){ this.cnt = cnt; this.shift = shift; this.root = root; this.tail = tail; } - MutableVector(PersistentVector v){ + TransientVector(PersistentVector v){ this(v.cnt, v.shift, editableRoot(v.root), editableTail(v.tail)); } @@ -413,7 +413,7 @@ static final class MutableVector extends AFn implements IMutableVector, Counted{ return new Node(new AtomicReference<Thread>(Thread.currentThread()), node.array.clone()); } - public PersistentVector immutable(){ + public PersistentVector persistent(){ ensureEditable(); // Thread owner = root.edit.get(); // if(owner != null && owner != Thread.currentThread()) @@ -432,7 +432,7 @@ static final class MutableVector extends AFn implements IMutableVector, Counted{ return ret; } - public MutableVector conj(Object val){ + public TransientVector conj(Object val){ ensureEditable(); int i = cnt; //room in tail? @@ -536,7 +536,7 @@ static final class MutableVector extends AFn implements IMutableVector, Counted{ return node[i & 0x01f]; } - public MutableVector assocN(int i, Object val){ + public TransientVector assocN(int i, Object val){ ensureEditable(); if(i >= 0 && i < cnt) { @@ -554,7 +554,7 @@ static final class MutableVector extends AFn implements IMutableVector, Counted{ throw new IndexOutOfBoundsException(); } - public MutableVector assoc(Object key, Object val){ + public TransientVector assoc(Object key, Object val){ //note - relies on ensureEditable in assocN if(Util.isInteger(key)) { @@ -579,7 +579,7 @@ static final class MutableVector extends AFn implements IMutableVector, Counted{ return ret; } - public MutableVector pop(){ + public TransientVector pop(){ ensureEditable(); if(cnt == 0) throw new IllegalStateException("Can't pop empty vector"); |