fixing isList fo the negative case. Oops.
This commit is contained in:
parent
faf04792a2
commit
4cf6865862
|
@ -266,25 +266,36 @@
|
||||||
if (hare === EMPTY) {
|
if (hare === EMPTY) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
while (true) {
|
|
||||||
if (!(hare instanceof Cons)) { return false; }
|
if (!(hare instanceof Cons)) { return false; }
|
||||||
if (tortoise instanceof Cons) {
|
while (true) {
|
||||||
|
// Loop invariant: at the beginning of the loop, both tortoise
|
||||||
|
// and hare should be pointing to a cons cell.
|
||||||
tortoise = tortoise.rest;
|
tortoise = tortoise.rest;
|
||||||
}
|
|
||||||
hare = hare.rest;
|
hare = hare.rest;
|
||||||
if (hare instanceof Cons) {
|
if (hare instanceof Cons) {
|
||||||
// optimization to get amortized linear time isList:
|
// optimization to get amortized linear time isList:
|
||||||
if (hare._isList) { tortoise._isList = true; return true; }
|
if (hare._isList !== undefined) {
|
||||||
|
tortoise._isList = hare._isList; return hare._isList;
|
||||||
|
}
|
||||||
hare = hare.rest;
|
hare = hare.rest;
|
||||||
// optimization to get amortized linear time isList:
|
// optimization to get amortized linear time isList:
|
||||||
if (hare instanceof Cons && hare._isList) { tortoise._isList = true; return true; }
|
if (hare instanceof Cons && hare._isList !== undefined) {
|
||||||
|
tortoise._isList = hare._isList; return hare._isList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (hare === EMPTY) {
|
if (hare === EMPTY) {
|
||||||
// optimization to get amortized linear time isList:
|
// optimization to get amortized linear time isList:
|
||||||
tortoise._isList = true;
|
tortoise._isList = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (tortoise === hare) { return false; }
|
if (tortoise === hare) {
|
||||||
|
tortoise._isList = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!(hare instanceof Cons)) {
|
||||||
|
tortoise._isList = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user