Skip to content

Commit d61a511

Browse files
committed
lib: refactor internal/linkedlist
PR-URL: #11406 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent ca48071 commit d61a511

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/internal/linkedlist.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,26 @@ function init(list) {
44
list._idleNext = list;
55
list._idlePrev = list;
66
}
7-
exports.init = init;
87

98
// create a new linked list
109
function create() {
1110
const list = { _idleNext: null, _idlePrev: null };
1211
init(list);
1312
return list;
1413
}
15-
exports.create = create;
1614

1715
// show the most idle item
1816
function peek(list) {
1917
if (list._idlePrev === list) return null;
2018
return list._idlePrev;
2119
}
22-
exports.peek = peek;
23-
2420

2521
// remove the most idle item from the list
2622
function shift(list) {
2723
const first = list._idlePrev;
2824
remove(first);
2925
return first;
3026
}
31-
exports.shift = shift;
32-
3327

3428
// remove a item from its list
3529
function remove(item) {
@@ -44,8 +38,6 @@ function remove(item) {
4438
item._idleNext = null;
4539
item._idlePrev = null;
4640
}
47-
exports.remove = remove;
48-
4941

5042
// remove a item from its list and place at the end.
5143
function append(list, item) {
@@ -62,10 +54,17 @@ function append(list, item) {
6254
list._idleNext._idlePrev = item;
6355
list._idleNext = item;
6456
}
65-
exports.append = append;
66-
6757

6858
function isEmpty(list) {
6959
return list._idleNext === list;
7060
}
71-
exports.isEmpty = isEmpty;
61+
62+
module.exports = {
63+
init,
64+
create,
65+
peek,
66+
shift,
67+
remove,
68+
append,
69+
isEmpty
70+
};

0 commit comments

Comments
 (0)