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>
This commit is contained in:
parent
ca48071919
commit
d61a511728
@ -4,7 +4,6 @@ function init(list) {
|
|||||||
list._idleNext = list;
|
list._idleNext = list;
|
||||||
list._idlePrev = list;
|
list._idlePrev = list;
|
||||||
}
|
}
|
||||||
exports.init = init;
|
|
||||||
|
|
||||||
// create a new linked list
|
// create a new linked list
|
||||||
function create() {
|
function create() {
|
||||||
@ -12,15 +11,12 @@ function create() {
|
|||||||
init(list);
|
init(list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
exports.create = create;
|
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
exports.peek = peek;
|
|
||||||
|
|
||||||
|
|
||||||
// remove the most idle item from the list
|
// remove the most idle item from the list
|
||||||
function shift(list) {
|
function shift(list) {
|
||||||
@ -28,8 +24,6 @@ function shift(list) {
|
|||||||
remove(first);
|
remove(first);
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
exports.shift = shift;
|
|
||||||
|
|
||||||
|
|
||||||
// remove a item from its list
|
// remove a item from its list
|
||||||
function remove(item) {
|
function remove(item) {
|
||||||
@ -44,8 +38,6 @@ function remove(item) {
|
|||||||
item._idleNext = null;
|
item._idleNext = null;
|
||||||
item._idlePrev = null;
|
item._idlePrev = null;
|
||||||
}
|
}
|
||||||
exports.remove = remove;
|
|
||||||
|
|
||||||
|
|
||||||
// remove a item from its list and place at the end.
|
// remove a item from its list and place at the end.
|
||||||
function append(list, item) {
|
function append(list, item) {
|
||||||
@ -62,10 +54,17 @@ function append(list, item) {
|
|||||||
list._idleNext._idlePrev = item;
|
list._idleNext._idlePrev = item;
|
||||||
list._idleNext = item;
|
list._idleNext = item;
|
||||||
}
|
}
|
||||||
exports.append = append;
|
|
||||||
|
|
||||||
|
|
||||||
function isEmpty(list) {
|
function isEmpty(list) {
|
||||||
return list._idleNext === list;
|
return list._idleNext === list;
|
||||||
}
|
}
|
||||||
exports.isEmpty = isEmpty;
|
|
||||||
|
module.exports = {
|
||||||
|
init,
|
||||||
|
create,
|
||||||
|
peek,
|
||||||
|
shift,
|
||||||
|
remove,
|
||||||
|
append,
|
||||||
|
isEmpty
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user