summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-08-05 17:59:51 +0000
committerRich Hickey <richhickey@gmail.com>2006-08-05 17:59:51 +0000
commita619d3a6f9cde068d0945ab26b275113c8ffde1b (patch)
treeaebe0668658bb28612ad369c6112a1739880bb94
parent5572d24dae42bf686048a1add52437b4b3627ca0 (diff)
derived PersistentArrayList from IPersistentList
-rw-r--r--src/cli/runtime/PerisistentArrayList.cs10
-rw-r--r--src/jvm/clojure/lang/PersistentArrayList.java13
2 files changed, 17 insertions, 6 deletions
diff --git a/src/cli/runtime/PerisistentArrayList.cs b/src/cli/runtime/PerisistentArrayList.cs
index 3c71312a..f22dd334 100644
--- a/src/cli/runtime/PerisistentArrayList.cs
+++ b/src/cli/runtime/PerisistentArrayList.cs
@@ -14,7 +14,7 @@ using System.Collections;
namespace clojure.lang
{
-public class PersistentArrayList : PersistentArray{
+public class PersistentArrayList : PersistentArray, IPersistentList{
int _count;
@@ -72,7 +72,13 @@ override public IPersistentCollection cons(Object val) {
return ret;
}
-public PersistentArrayList remove() {
+public Object peek(){
+ if(_count > 0)
+ return nth(_count - 1);
+ return null;
+}
+
+public IPersistentList pop() {
if(_count == 0)
throw new InvalidOperationException();
PersistentArrayList ret = new PersistentArrayList(data.master, data.rev, data.baseline, data.history, _count - 1);
diff --git a/src/jvm/clojure/lang/PersistentArrayList.java b/src/jvm/clojure/lang/PersistentArrayList.java
index 538cfe07..c0276c27 100644
--- a/src/jvm/clojure/lang/PersistentArrayList.java
+++ b/src/jvm/clojure/lang/PersistentArrayList.java
@@ -12,7 +12,7 @@ package clojure.lang;
import java.util.BitSet;
-public class PersistentArrayList extends PersistentArray{
+public class PersistentArrayList extends PersistentArray implements IPersistentList{
int _count;
@@ -75,7 +75,13 @@ public PersistentArrayList cons(Object val) {
return ret;
}
-public PersistentArrayList remove() {
+public Object peek(){
+ if(_count > 0)
+ return nth(_count - 1);
+ return null;
+}
+
+public PersistentArrayList pop() {
if(_count == 0)
throw new IllegalAccessError();
PersistentArrayList ret = new PersistentArrayList(data.master, data.rev, data.baseline, data.history, _count - 1);
@@ -93,8 +99,7 @@ private void grow() {
newMaster.rev = data.master.rev;
newMaster.load = data.master.load;
newMaster.basis = data.master.basis;
- for(int i=0;i<data.master.array.length;i++)
- newMaster.array[i] = data.master.array[i];
+ System.arraycopy(data.master.array, 0, newMaster.array, 0, data.master.array.length);
data.master = newMaster;
}