Skip to content

Commit

Permalink
linkedlist: remove unused methods
Browse files Browse the repository at this point in the history
PR-URL: #11726
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
  • Loading branch information
mscdex authored and jasnell committed Apr 4, 2017
1 parent 394b6ac commit b40dab5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 45 deletions.
16 changes: 0 additions & 16 deletions lib/internal/linkedlist.js
Expand Up @@ -5,26 +5,12 @@ function init(list) {
list._idlePrev = list; list._idlePrev = list;
} }


// create a new linked list
function create() {
const list = { _idleNext: null, _idlePrev: null };
init(list);
return list;
}

// show the most idle item // show the most idle item
function peek(list) { function peek(list) {
if (list._idlePrev === list) return null; if (list._idlePrev === list) return null;
return list._idlePrev; return list._idlePrev;
} }


// remove the most idle item from the list
function shift(list) {
const first = list._idlePrev;
remove(first);
return first;
}

// remove a item from its list // remove a item from its list
function remove(item) { function remove(item) {
if (item._idleNext) { if (item._idleNext) {
Expand Down Expand Up @@ -61,9 +47,7 @@ function isEmpty(list) {


module.exports = { module.exports = {
init, init,
create,
peek, peek,
shift,
remove, remove,
append, append,
isEmpty isEmpty
Expand Down
36 changes: 7 additions & 29 deletions test/parallel/test-timers-linked-list.js
Expand Up @@ -59,14 +59,8 @@ L.append(list, D);
// list -> A -> B -> C -> D // list -> A -> B -> C -> D
assert.strictEqual(A, L.peek(list)); assert.strictEqual(A, L.peek(list));


assert.strictEqual(A, L.shift(list)); L.remove(A);
// list -> B -> C -> D L.remove(B);
assert.strictEqual(B, L.peek(list));

assert.strictEqual(B, L.shift(list));
// list -> C -> D
assert.strictEqual(C, L.peek(list));

// B is already removed, so removing it again shouldn't hurt. // B is already removed, so removing it again shouldn't hurt.
L.remove(B); L.remove(B);
// list -> C -> D // list -> C -> D
Expand Down Expand Up @@ -104,26 +98,10 @@ L.append(list, A);


// Append should REMOVE C from the list and append it to the end. // Append should REMOVE C from the list and append it to the end.
L.append(list, C); L.append(list, C);

// list -> D -> B -> A -> C // list -> D -> B -> A -> C
assert.strictEqual(D, L.shift(list));
// list -> B -> A -> C
assert.strictEqual(B, L.peek(list));
assert.strictEqual(B, L.shift(list));
// list -> A -> C
assert.strictEqual(A, L.peek(list));
assert.strictEqual(A, L.shift(list));
// list -> C
assert.strictEqual(C, L.peek(list));
assert.strictEqual(C, L.shift(list));
// list
assert.ok(L.isEmpty(list));

const list2 = L.create();
const list3 = L.create();
assert.ok(L.isEmpty(list2));
assert.ok(L.isEmpty(list3));


// Objects should have identical keys/properties, but be different objects. assert.strictEqual(D, L.peek(list));
assert.deepStrictEqual(list2, list3); assert.strictEqual(B, L.peek(D));
assert.notStrictEqual(list2, list3); assert.strictEqual(A, L.peek(B));
assert.strictEqual(C, L.peek(A));
assert.strictEqual(list, L.peek(C));

0 comments on commit b40dab5

Please sign in to comment.