Permalink
Browse files

lib: refactor internal/linkedlist

PR-URL: #11406
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information...
jasnell committed Feb 15, 2017
1 parent ca48071 commit d61a511728919c4833ba7717777af93f51aedbc8
Showing with 10 additions and 11 deletions.
  1. +10 −11 lib/internal/linkedlist.js
View
@@ -4,32 +4,26 @@ function init(list) {
list._idleNext = list;
list._idlePrev = list;
}
exports.init = init;
// create a new linked list
function create() {
const list = { _idleNext: null, _idlePrev: null };
init(list);
return list;
}
exports.create = create;
// show the most idle item
function peek(list) {
if (list._idlePrev === list) return null;
return list._idlePrev;
}
exports.peek = peek;
// remove the most idle item from the list
function shift(list) {
const first = list._idlePrev;
remove(first);
return first;
}
exports.shift = shift;
// remove a item from its list
function remove(item) {
@@ -44,8 +38,6 @@ function remove(item) {
item._idleNext = null;
item._idlePrev = null;
}
exports.remove = remove;
// remove a item from its list and place at the end.
function append(list, item) {
@@ -62,10 +54,17 @@ function append(list, item) {
list._idleNext._idlePrev = item;
list._idleNext = item;
}
exports.append = append;
function isEmpty(list) {
return list._idleNext === list;
}
exports.isEmpty = isEmpty;
module.exports = {
init,
create,
peek,
shift,
remove,
append,
isEmpty
};

0 comments on commit d61a511

Please sign in to comment.