Browse Source

lib: refactor internal/linkedlist

PR-URL: https://github.com/nodejs/node/pull/11406
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
v6
James M Snell 8 years ago
parent
commit
d61a511728
  1. 21
      lib/internal/linkedlist.js

21
lib/internal/linkedlist.js

@ -4,7 +4,6 @@ function init(list) {
list._idleNext = list;
list._idlePrev = list;
}
exports.init = init;
// create a new linked list
function create() {
@ -12,15 +11,12 @@ function create() {
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) {
@ -28,8 +24,6 @@ function shift(list) {
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
};

Loading…
Cancel
Save