Linked-List refactor (#6056)

* Added failing linked-list test for #7059

* Fixed linked-list remove bug #7059

* Added failing linked-list test for #7059

* Switched LinkedList to use Map

* Removed this.last from LinkedList

* Removed this.first from LinkedList

* Switching to deleting old LinkedList entries

* LinkedList rewritten to be better

* Using null as LinkList ends to reduce hashing

* Using adhoc map... cause it's better than ECMA6 Map

* compliance with TiddlyWiki coding conventions

* Made link-list tests confirm the prev links

Co-authored-by: btheado <brian.theado@gmail.com>
This commit is contained in:
Cameron Fischer
2022-11-27 12:48:08 -05:00
committed by GitHub
parent 34a20463c7
commit 856aca2f92
2 changed files with 108 additions and 75 deletions

View File

@@ -59,10 +59,35 @@ describe("LinkedList class tests", function() {
return pair;
};
// This returns an array in reverse using a LinkList's prev member. Thus
// testing that prev is not corrupt. It doesn't exist in the LinkList module
// itself to avoid full support for it. Maybe that will change later.
function toReverseArray(list) {
var visits = Object.create(null),
value = list.prev.get(null),
array = [];
while(value !== null) {
array.push(value);
var prev = list.prev.get(value);
if(Array.isArray(prev)) {
var i = (visits[value] || prev.length) - 1;
visits[value] = i;
value = prev[i];
} else {
value = prev;
}
}
return array;
};
// compares an array and a linked list to make sure they match up
function compare(pair) {
expect(pair.list.toArray()).toEqual(pair.array);
var forward = pair.list.toArray();
expect(forward).toEqual(pair.array);
expect(pair.list.length).toBe(pair.array.length);
// Now we reverse the linked list and test it back to front, thus
// confirming that the list.prev isn't corrupt.
expect(toReverseArray(pair.list)).toEqual(forward.reverse());
return pair;
};
@@ -115,7 +140,7 @@ describe("LinkedList class tests", function() {
// for list.last to be anything other than a string, but I
// can't figure out how to make that corruption manifest a problem.
// So I dig into its private members. Bleh...
expect(typeof pair.list.last).toBe("string");
expect(typeof pair.list.prev.get(null)).toBe("string");
});
it("can pushTop value linked to by a repeat item", function() {