Skip to content
Permalink
Browse files
refactor: optimized internal structure of the queue
  • Loading branch information
hbarcelos committed Feb 5, 2020
1 parent 52205db commit ea687897b992f9f7b7d540a89fcd981fb33de77c
Showing with 5 additions and 12 deletions.
  1. +5 −12 round-linked-queue.js
@@ -4,7 +4,6 @@ class RoundLinkedQueue {
constructor(maxLength) {
this._maxLength = maxLength;
this._length = 0;
this._root = 0;
this._first = null;
this._last = null;
}
@@ -32,24 +31,18 @@ class RoundLinkedQueue {
};

if (this.length < this.maxLength) {
if (!this._root) {
this._root = node;
if (!this._first) {
this._first = node;
this._last = node;
} else {
const previousLast = this._last;
previousLast.next = node;

this._last = node;
}

this._length += 1;
} else {
this._root = this._root.next;
this._last.next = node;
this._first = this._root;
this._last = node;
this._first = this._first.next;
}

this._last.next = node;
this._last = node;
}
}

0 comments on commit ea68789

Please sign in to comment.