--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pertests.scala Mon Apr 21 10:19:23 2008 +0100
@@ -0,0 +1,21 @@
+import alt.collections._
+import traversable._
+import buildable.Building._;
+
+def time(action : => Unit) = { val start = System.currentTimeMillis(); action; System.currentTimeMillis() - start }
+
+def foo (n : Int) = List.range(1, n).map( (_ : Int) * 2);
+def bar(n : Int) = Traversable.fromIterable(List.range(1, n)).map((_ : Int) * 2).as[List, Int]
+
+val size = 100000;
+
+var myWay = 0L;
+var standardWay = 0L;
+
+for (i <- 0 until 10) {
+ standardWay = standardWay + time(foo(size));
+ myWay = myWay + time(bar(size));
+}
+
+println("My way: " + myWay);
+println("Standard way: " + standardWay);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scratch/fingertree.scala Mon Apr 21 10:19:23 2008 +0100
@@ -0,0 +1,19 @@
+package alt.collections.sequence;
+
+object FingerTree{
+ type I[+T] = FingerTree[T];
+
+ def empty = Empty;
+
+
+ private case object Empty extends FingerTree[Nothing];
+ private case class Single[+T](t : T) extends FingerTree[Nothing];
+ private case class Deep[T](left : T, center : FingerTree[Buffer[T]], right : T)(val size : Int);
+
+ sealed abstract class FingerTree[+T] extends Sequence[T]{
+
+ }
+
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scratch/intmap.scala Mon Apr 21 10:19:23 2008 +0100
@@ -0,0 +1,54 @@
+package alt.collections.map;
+
+import alt.collections.traversable._;
+import alt.collections.buildable._;
+
+// Extremely unoptimised immutable IntMap implementation.
+// About the simplest possible thing you could do
+class IntMap extends MapType[Int]{
+
+
+ class IntMap[+V] private (contents : MapNode) extends Map[V]{
+ def traverse(f : ((K, V)) => Unit) = {
+
+ }
+
+ }
+}
+
+object MapNode{
+ val chunkSize = 4;
+ val arraySize = 1 << chunkSize;
+ val mask = arraySize - 1;
+}
+
+private class MapNode(val value : Any, val children : Array[MapNode]){
+ import MapNode._;
+
+ def this() = this(null, null);
+
+ val get(key : Int) : Any =
+ if (key == 0) value;
+ else {
+ val chunk = key && mask;
+ if (!hasChild(chunk)) null;
+ else {
+ children(chunk).get(key >> chunkSize);
+ }
+ }
+
+ def hasChild(chunk : Int) = (children != null && children(chunk) != null);
+
+ def put(key : Int, value : Any) : MapNode = {
+ if (key == 0) new MapNode(value, children);
+ else {
+ val chunk = key && mask;
+ val newchildren = Array(children :_*);
+ if (newchildren(chunk) == null){
+ newchildren(chunk) = new MapNode();
+ }
+ newchildren(chunk) = newchildren(chunk).put(key >> chunkSize, value);
+ new MapNode(this.value, newchildren);
+ }
+ }
+}