continuing to optimize
This commit is contained in:
parent
6d035504af
commit
d70db16956
|
@ -1,11 +1,13 @@
|
|||
#lang planet dyoo/whalesong
|
||||
|
||||
(define (mylen x)
|
||||
(define (mylen x acc)
|
||||
(cond
|
||||
[(empty? x)
|
||||
0]
|
||||
acc]
|
||||
[else
|
||||
(add1 (mylen (rest x)))]))
|
||||
(mylen (rest x) (add1 acc))]))
|
||||
"computing length"
|
||||
(mylen (build-list 100000 (lambda (i) i)))
|
||||
(define v (build-list 1000000 (lambda (i) i)))
|
||||
(printf "Built list\n")
|
||||
(mylen v 0)
|
||||
"done computing length"
|
|
@ -264,18 +264,26 @@
|
|||
var tortoise, hare;
|
||||
tortoise = hare = x;
|
||||
if (hare === EMPTY) {
|
||||
tortoise._isList = true;
|
||||
return true;
|
||||
}
|
||||
while (true) {
|
||||
if (!(hare instanceof Cons)) { return false; }
|
||||
if (tortoise instanceof Cons) {
|
||||
if (tortoise._isList === true) { return true; }
|
||||
tortoise = tortoise.rest;
|
||||
}
|
||||
hare = hare.rest;
|
||||
if (hare instanceof Cons) { hare = hare.rest; }
|
||||
if (hare === EMPTY) { return true; }
|
||||
if (hare instanceof Cons) {
|
||||
// optimization to get amortized linear time isList:
|
||||
if (hare._isList) { tortoise._isList = true; return true; }
|
||||
hare = hare.rest;
|
||||
// optimization to get amortized linear time isList:
|
||||
if (hare instanceof Cons && hare._isList) { tortoise._isList = true; return true; }
|
||||
}
|
||||
if (hare === EMPTY) {
|
||||
// optimization to get amortized linear time isList:
|
||||
tortoise._isList = true;
|
||||
return true;
|
||||
}
|
||||
if (tortoise === hare) { return false; }
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,10 +15,6 @@
|
|||
for (i = 0; i < n; i++) {
|
||||
this.elts[i] = initialElements[i];
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < n; i++) {
|
||||
this.elts[i] = undefined;
|
||||
}
|
||||
}
|
||||
this.mutable = true;
|
||||
};
|
||||
|
|
|
@ -395,7 +395,8 @@
|
|||
var frame = this.c[this.c.length - 1];
|
||||
var marks = frame.marks;
|
||||
var i;
|
||||
for (i = 0; i < marks.length; i++) {
|
||||
var l = marks.length;
|
||||
for (i = 0; i < l; i++) {
|
||||
if (key === marks[i][0]) {
|
||||
marks[i][1] = value;
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue
Block a user