mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2025-01-18 11:14:05 +00:00
feat: Change the size property of all queue-based data structures to length to align with JavaScript's Array.
This commit is contained in:
parent
d27784228b
commit
17cfcbd66c
|
@ -14,7 +14,7 @@ export abstract class IterableElementBase<E, R, C> {
|
|||
}
|
||||
}
|
||||
|
||||
abstract get size(): number;
|
||||
// abstract get size(): number;
|
||||
|
||||
protected _toElementFn?: (rawElement: R) => E;
|
||||
|
||||
|
|
|
@ -544,7 +544,7 @@ export class BinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = o
|
|||
const queue = new Queue<BinaryTreeNode<K, V>>([this._root]);
|
||||
let potentialParent: BinaryTreeNode<K, V> | undefined; // Record the parent node of the potential insertion location
|
||||
|
||||
while (queue.size > 0) {
|
||||
while (queue.length > 0) {
|
||||
const cur = queue.shift();
|
||||
|
||||
if (!cur) continue;
|
||||
|
@ -1530,7 +1530,7 @@ export class BinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = o
|
|||
]);
|
||||
|
||||
const dfs = (level: number) => {
|
||||
if (queue.size === 0) return;
|
||||
if (queue.length === 0) return;
|
||||
|
||||
const current = queue.shift()!;
|
||||
ans.push(callback(current));
|
||||
|
@ -1549,8 +1549,8 @@ export class BinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = o
|
|||
dfs(0);
|
||||
} else {
|
||||
const queue = new Queue<OptNodeOrNull<BinaryTreeNode<K, V>>>([startNode]);
|
||||
while (queue.size > 0) {
|
||||
const levelSize = queue.size;
|
||||
while (queue.length > 0) {
|
||||
const levelSize = queue.length;
|
||||
|
||||
for (let i = 0; i < levelSize; i++) {
|
||||
const current = queue.shift()!;
|
||||
|
@ -1609,7 +1609,7 @@ export class BinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = o
|
|||
dfs(startNode);
|
||||
} else {
|
||||
const queue = new Queue([startNode]);
|
||||
while (queue.size > 0) {
|
||||
while (queue.length > 0) {
|
||||
const cur = queue.shift();
|
||||
if (this.isRealNode(cur)) {
|
||||
if (this.isLeaf(cur)) {
|
||||
|
|
|
@ -792,7 +792,7 @@ export class BST<K = any, V = any, R = object, MK = any, MV = any, MR = object>
|
|||
return ans;
|
||||
} else {
|
||||
const queue = new Queue<BSTNode<K, V>>([this._root]);
|
||||
while (queue.size > 0) {
|
||||
while (queue.length > 0) {
|
||||
const cur = queue.shift();
|
||||
if (this.isRealNode(cur)) {
|
||||
const compared = this._compare(cur.key, targetKey);
|
||||
|
|
|
@ -356,8 +356,8 @@ export abstract class AbstractGraph<
|
|||
const queue = new Queue<VO>([vertex1]);
|
||||
visited.set(vertex1, true);
|
||||
let cost = 0;
|
||||
while (queue.size > 0) {
|
||||
for (let i = 0; i < queue.size; i++) {
|
||||
while (queue.length > 0) {
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
const cur = queue.shift();
|
||||
if (cur === vertex2) {
|
||||
return cost;
|
||||
|
|
|
@ -159,7 +159,7 @@ export class DoublyLinkedListNode<E = any> {
|
|||
* const initialNode = this.currentSong;
|
||||
*
|
||||
* // Loop through the playlist twice
|
||||
* for (let i = 0; i < this.playlist.size * 2; i++) {
|
||||
* for (let i = 0; i < this.playlist.length * 2; i++) {
|
||||
* playedSongs.push(this.currentSong!.value);
|
||||
* this.currentSong = this.currentSong!.next || this.playlist.head; // Loop back to the start if needed
|
||||
* }
|
||||
|
@ -280,7 +280,7 @@ export class DoublyLinkedListNode<E = any> {
|
|||
* }
|
||||
*
|
||||
* // Check capacity
|
||||
* if (this.list.size >= this.capacity) {
|
||||
* if (this.list.length >= this.capacity) {
|
||||
* // Delete the least recently used element (the tail of the linked list)
|
||||
* const removedNode = this.list.tail;
|
||||
* if (removedNode) {
|
||||
|
@ -325,9 +325,9 @@ export class DoublyLinkedListNode<E = any> {
|
|||
* this.map.clear();
|
||||
* }
|
||||
*
|
||||
* // Get the current cache size
|
||||
* get size(): number {
|
||||
* return this.list.size;
|
||||
* // Get the current cache length
|
||||
* get length(): number {
|
||||
* return this.list.length;
|
||||
* }
|
||||
*
|
||||
* // Check if it is empty
|
||||
|
@ -386,7 +386,7 @@ export class DoublyLinkedListNode<E = any> {
|
|||
*
|
||||
* console.log(cache.delete('a')); // true
|
||||
* console.log(cache.get('a')); // undefined
|
||||
* console.log(cache.size); // 1
|
||||
* console.log(cache.length); // 1
|
||||
*
|
||||
* // Should support clearing cache
|
||||
* cache.clear();
|
||||
|
@ -394,7 +394,7 @@ export class DoublyLinkedListNode<E = any> {
|
|||
* cache.set('b', 2);
|
||||
* cache.clear();
|
||||
*
|
||||
* console.log(cache.size); // 0
|
||||
* console.log(cache.length); // 0
|
||||
* console.log(cache.isEmpty); // true
|
||||
* @example
|
||||
* // finding lyrics by timestamp in Coldplay's "Fix You"
|
||||
|
@ -531,7 +531,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
super(options);
|
||||
this._head = undefined;
|
||||
this._tail = undefined;
|
||||
this._size = 0;
|
||||
this._length = 0;
|
||||
|
||||
if (options) {
|
||||
const { maxLen } = options;
|
||||
|
@ -562,14 +562,14 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
return this._tail;
|
||||
}
|
||||
|
||||
protected _size: number;
|
||||
protected _length: number;
|
||||
|
||||
/**
|
||||
* The function returns the size of an object.
|
||||
* @returns The size of the object, which is a number.
|
||||
* The function returns the length of an object.
|
||||
* @returns The length of the object, which is a number.
|
||||
*/
|
||||
get size(): number {
|
||||
return this._size;
|
||||
get length(): number {
|
||||
return this._length;
|
||||
}
|
||||
|
||||
protected _maxLen: number = -1;
|
||||
|
@ -652,8 +652,8 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
this.tail!.next = newNode;
|
||||
this._tail = newNode;
|
||||
}
|
||||
this._size++;
|
||||
if (this._maxLen > 0 && this.size > this._maxLen) this.shift();
|
||||
this._length++;
|
||||
if (this._maxLen > 0 && this.length > this._maxLen) this.shift();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -674,7 +674,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
this._tail = removedNode.prev;
|
||||
this.tail!.next = undefined;
|
||||
}
|
||||
this._size--;
|
||||
this._length--;
|
||||
return removedNode.value;
|
||||
}
|
||||
|
||||
|
@ -695,7 +695,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
this._head = removedNode.next;
|
||||
this.head!.prev = undefined;
|
||||
}
|
||||
this._size--;
|
||||
this._length--;
|
||||
return removedNode.value;
|
||||
}
|
||||
|
||||
|
@ -719,8 +719,8 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
this.head!.prev = newNode;
|
||||
this._head = newNode;
|
||||
}
|
||||
this._size++;
|
||||
if (this._maxLen > 0 && this._size > this._maxLen) this.pop();
|
||||
this._length++;
|
||||
if (this._maxLen > 0 && this._length > this._maxLen) this.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -786,7 +786,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* or the linked list is empty, it will return undefined.
|
||||
*/
|
||||
at(index: number): E | undefined {
|
||||
if (index < 0 || index >= this._size) return undefined;
|
||||
if (index < 0 || index >= this._length) return undefined;
|
||||
let current = this.head;
|
||||
for (let i = 0; i < index; i++) {
|
||||
current = current!.next;
|
||||
|
@ -806,7 +806,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* valid range of the linked list, otherwise it returns `undefined`.
|
||||
*/
|
||||
getNodeAt(index: number): DoublyLinkedListNode<E> | undefined {
|
||||
if (index < 0 || index >= this._size) return undefined;
|
||||
if (index < 0 || index >= this._length) return undefined;
|
||||
let current = this.head;
|
||||
for (let i = 0; i < index; i++) {
|
||||
current = current!.next;
|
||||
|
@ -861,15 +861,15 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* `addAt` method can be either a value of type `E` or a `DoublyLinkedListNode<E>` object.
|
||||
* @returns The `addAt` method returns a boolean value. It returns `true` if the element or node was
|
||||
* successfully added at the specified index, and `false` if the index is out of bounds (less than 0
|
||||
* or greater than the size of the list).
|
||||
* or greater than the length of the list).
|
||||
*/
|
||||
addAt(index: number, newElementOrNode: E | DoublyLinkedListNode<E>): boolean {
|
||||
if (index < 0 || index > this._size) return false;
|
||||
if (index < 0 || index > this._length) return false;
|
||||
if (index === 0) {
|
||||
this.unshift(newElementOrNode);
|
||||
return true;
|
||||
}
|
||||
if (index === this._size) {
|
||||
if (index === this._length) {
|
||||
this.push(newElementOrNode);
|
||||
return true;
|
||||
}
|
||||
|
@ -881,7 +881,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
newNode.next = nextNode;
|
||||
prevNode!.next = newNode;
|
||||
nextNode!.prev = newNode;
|
||||
this._size++;
|
||||
this._length++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -919,7 +919,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
if (existingNode === this.head) {
|
||||
this._head = newNode;
|
||||
}
|
||||
this._size++;
|
||||
this._length++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -958,7 +958,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
if (existingNode === this.tail) {
|
||||
this._tail = newNode;
|
||||
}
|
||||
this._size++;
|
||||
this._length++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -976,12 +976,12 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* bounds.
|
||||
*/
|
||||
deleteAt(index: number): boolean {
|
||||
if (index < 0 || index >= this._size) return false;
|
||||
if (index < 0 || index >= this._length) return false;
|
||||
if (index === 0) {
|
||||
this.shift();
|
||||
return true;
|
||||
}
|
||||
if (index === this._size - 1) {
|
||||
if (index === this._length - 1) {
|
||||
this.pop();
|
||||
return true;
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
const nextNode = removedNode!.next;
|
||||
prevNode!.next = nextNode;
|
||||
nextNode!.prev = prevNode;
|
||||
this._size--;
|
||||
this._length--;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1021,7 +1021,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
const nextNode = node.next;
|
||||
if (prevNode) prevNode.next = nextNode;
|
||||
if (nextNode) nextNode.prev = prevNode;
|
||||
this._size--;
|
||||
this._length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1032,23 +1032,23 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* Time Complexity: O(1)
|
||||
* Space Complexity: O(1)
|
||||
*
|
||||
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
||||
* The function checks if a variable has a length greater than zero and returns a boolean value.
|
||||
* @returns A boolean value is being returned.
|
||||
*/
|
||||
isEmpty(): boolean {
|
||||
return this._size === 0;
|
||||
return this._length === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time Complexity: O(1)
|
||||
* Space Complexity: O(1)
|
||||
*
|
||||
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
||||
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
||||
*/
|
||||
clear(): void {
|
||||
this._head = undefined;
|
||||
this._tail = undefined;
|
||||
this._size = 0;
|
||||
this._length = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,14 +121,14 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
return this._maxLen;
|
||||
}
|
||||
|
||||
protected _size: number = 0;
|
||||
protected _length: number = 0;
|
||||
|
||||
/**
|
||||
* The function returns the size of an object.
|
||||
* @returns The size of the object, which is a number.
|
||||
* The function returns the length of an object.
|
||||
* @returns The length of the object, which is a number.
|
||||
*/
|
||||
get size(): number {
|
||||
return this._size;
|
||||
get length(): number {
|
||||
return this._length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,8 +166,8 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
this.tail!.next = newNode;
|
||||
this._tail = newNode;
|
||||
}
|
||||
this._size++;
|
||||
if (this._maxLen > 0 && this.size > this._maxLen) this.shift();
|
||||
this._length++;
|
||||
if (this._maxLen > 0 && this.length > this._maxLen) this.shift();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
const value = this.head.value;
|
||||
this._head = undefined;
|
||||
this._tail = undefined;
|
||||
this._size--;
|
||||
this._length--;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
const value = this.tail!.value;
|
||||
current.next = undefined;
|
||||
this._tail = current;
|
||||
this._size--;
|
||||
this._length--;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
if (!this.head) return undefined;
|
||||
const removedNode = this.head;
|
||||
this._head = this.head.next;
|
||||
this._size--;
|
||||
this._length--;
|
||||
return removedNode.value;
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
newNode.next = this.head;
|
||||
this._head = newNode;
|
||||
}
|
||||
this._size++;
|
||||
this._length++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* `undefined` if the index is out of bounds.
|
||||
*/
|
||||
at(index: number): E | undefined {
|
||||
if (index < 0 || index >= this._size) return undefined;
|
||||
if (index < 0 || index >= this._length) return undefined;
|
||||
let current = this.head;
|
||||
for (let i = 0; i < index; i++) {
|
||||
current = current!.next;
|
||||
|
@ -379,12 +379,12 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* bounds.
|
||||
*/
|
||||
deleteAt(index: number): boolean {
|
||||
if (index < 0 || index >= this._size) return false;
|
||||
if (index < 0 || index >= this._length) return false;
|
||||
if (index === 0) {
|
||||
this.shift();
|
||||
return true;
|
||||
}
|
||||
if (index === this._size - 1) {
|
||||
if (index === this._length - 1) {
|
||||
this.pop();
|
||||
return true;
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
const prevNode = this.getNodeAt(index - 1);
|
||||
const removedNode = prevNode!.next;
|
||||
prevNode!.next = removedNode!.next;
|
||||
this._size--;
|
||||
this._length--;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
this._tail = prev;
|
||||
}
|
||||
}
|
||||
this._size--;
|
||||
this._length--;
|
||||
return true;
|
||||
}
|
||||
prev = current;
|
||||
|
@ -456,13 +456,13 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* successfully added at the specified index, and `false` if the index is out of bounds.
|
||||
*/
|
||||
addAt(index: number, newElementOrNode: E | SinglyLinkedListNode<E>): boolean {
|
||||
if (index < 0 || index > this._size) return false;
|
||||
if (index < 0 || index > this._length) return false;
|
||||
|
||||
if (index === 0) {
|
||||
this.unshift(newElementOrNode);
|
||||
return true;
|
||||
}
|
||||
if (index === this._size) {
|
||||
if (index === this._length) {
|
||||
this.push(newElementOrNode);
|
||||
return true;
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
const prevNode = this.getNodeAt(index - 1);
|
||||
newNode.next = prevNode!.next;
|
||||
prevNode!.next = newNode;
|
||||
this._size++;
|
||||
this._length++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -484,7 +484,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
||||
*/
|
||||
isEmpty(): boolean {
|
||||
return this._size === 0;
|
||||
return this._length === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -496,7 +496,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
clear(): void {
|
||||
this._head = undefined;
|
||||
this._tail = undefined;
|
||||
this._size = 0;
|
||||
this._length = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -639,7 +639,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
const newNode = this._ensureNode(newElementOrNode);
|
||||
newNode.next = current.next;
|
||||
current.next = newNode;
|
||||
this._size++;
|
||||
this._length++;
|
||||
return true;
|
||||
}
|
||||
current = current.next;
|
||||
|
@ -674,7 +674,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
|
|||
if (existingNode === this.tail) {
|
||||
this._tail = newNode;
|
||||
}
|
||||
this._size++;
|
||||
this._length++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,14 +140,14 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
return this._buckets;
|
||||
}
|
||||
|
||||
protected _size = 0;
|
||||
protected _length = 0;
|
||||
|
||||
/**
|
||||
* The size function returns the number of items in the stack.
|
||||
* The length function returns the number of items in the stack.
|
||||
* @return The number of values in the set
|
||||
*/
|
||||
get size() {
|
||||
return this._size;
|
||||
get length() {
|
||||
return this._length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,7 +156,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The first element of the collection, of type E, is being returned.
|
||||
*/
|
||||
get first(): E | undefined {
|
||||
if (this._size === 0) return;
|
||||
if (this._length === 0) return;
|
||||
return this._buckets[this._bucketFirst][this._firstInBucket];
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @return The last element in the array
|
||||
*/
|
||||
get last(): E | undefined {
|
||||
if (this._size === 0) return;
|
||||
if (this._length === 0) return;
|
||||
return this._buckets[this._bucketLast][this._lastInBucket];
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The size of the data structure after the element has been pushed.
|
||||
*/
|
||||
push(element: E): boolean {
|
||||
if (this._size) {
|
||||
if (this._length) {
|
||||
if (this._lastInBucket < this._bucketSize - 1) {
|
||||
this._lastInBucket += 1;
|
||||
} else if (this._bucketLast < this._bucketCount - 1) {
|
||||
|
@ -191,9 +191,9 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
}
|
||||
if (this._bucketLast === this._bucketFirst && this._lastInBucket === this._firstInBucket) this._reallocate();
|
||||
}
|
||||
this._size += 1;
|
||||
this._length += 1;
|
||||
this._buckets[this._bucketLast][this._lastInBucket] = element;
|
||||
if (this._maxLen > 0 && this._size > this._maxLen) this.shift();
|
||||
if (this._maxLen > 0 && this._length > this._maxLen) this.shift();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -206,9 +206,9 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The element that was removed from the data structure is being returned.
|
||||
*/
|
||||
pop(): E | undefined {
|
||||
if (this._size === 0) return;
|
||||
if (this._length === 0) return;
|
||||
const element = this._buckets[this._bucketLast][this._lastInBucket];
|
||||
if (this._size !== 1) {
|
||||
if (this._length !== 1) {
|
||||
if (this._lastInBucket > 0) {
|
||||
this._lastInBucket -= 1;
|
||||
} else if (this._bucketLast > 0) {
|
||||
|
@ -219,7 +219,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
this._lastInBucket = this._bucketSize - 1;
|
||||
}
|
||||
}
|
||||
this._size -= 1;
|
||||
this._length -= 1;
|
||||
return element;
|
||||
}
|
||||
|
||||
|
@ -233,9 +233,9 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* returned.
|
||||
*/
|
||||
shift(): E | undefined {
|
||||
if (this._size === 0) return;
|
||||
if (this._length === 0) return;
|
||||
const element = this._buckets[this._bucketFirst][this._firstInBucket];
|
||||
if (this._size !== 1) {
|
||||
if (this._length !== 1) {
|
||||
if (this._firstInBucket < this._bucketSize - 1) {
|
||||
this._firstInBucket += 1;
|
||||
} else if (this._bucketFirst < this._bucketCount - 1) {
|
||||
|
@ -246,7 +246,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
this._firstInBucket = 0;
|
||||
}
|
||||
}
|
||||
this._size -= 1;
|
||||
this._length -= 1;
|
||||
return element;
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The size of the data structure after the element has been added.
|
||||
*/
|
||||
unshift(element: E): boolean {
|
||||
if (this._size) {
|
||||
if (this._length) {
|
||||
if (this._firstInBucket > 0) {
|
||||
this._firstInBucket -= 1;
|
||||
} else if (this._bucketFirst > 0) {
|
||||
|
@ -273,9 +273,9 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
}
|
||||
if (this._bucketFirst === this._bucketLast && this._firstInBucket === this._lastInBucket) this._reallocate();
|
||||
}
|
||||
this._size += 1;
|
||||
this._length += 1;
|
||||
this._buckets[this._bucketFirst][this._firstInBucket] = element;
|
||||
if (this._maxLen > 0 && this._size > this._maxLen) this.pop();
|
||||
if (this._maxLen > 0 && this._length > this._maxLen) this.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
||||
*/
|
||||
isEmpty(): boolean {
|
||||
return this._size === 0;
|
||||
return this._length === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -351,7 +351,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
clear(): void {
|
||||
this._buckets = [new Array(this._bucketSize)];
|
||||
this._bucketCount = 1;
|
||||
this._bucketFirst = this._bucketLast = this._size = 0;
|
||||
this._bucketFirst = this._bucketLast = this._length = 0;
|
||||
this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
*/
|
||||
*begin(): Generator<E> {
|
||||
let index = 0;
|
||||
while (index < this._size) {
|
||||
while (index < this._length) {
|
||||
yield this.at(index);
|
||||
index++;
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* the last element.
|
||||
*/
|
||||
*reverseBegin(): Generator<E> {
|
||||
let index = this._size - 1;
|
||||
let index = this._length - 1;
|
||||
while (index >= 0) {
|
||||
yield this.at(index);
|
||||
index--;
|
||||
|
@ -389,7 +389,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The element at the specified position in the data structure is being returned.
|
||||
*/
|
||||
at(pos: number): E {
|
||||
rangeCheck(pos, 0, this._size - 1);
|
||||
rangeCheck(pos, 0, this._length - 1);
|
||||
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
|
||||
return this._buckets[bucketIndex][indexInBucket]!;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* position in the data structure.
|
||||
*/
|
||||
setAt(pos: number, element: E): boolean {
|
||||
rangeCheck(pos, 0, this._size - 1);
|
||||
rangeCheck(pos, 0, this._length - 1);
|
||||
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
|
||||
this._buckets[bucketIndex][indexInBucket] = element;
|
||||
return true;
|
||||
|
@ -427,15 +427,15 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The size of the array after the insertion is being returned.
|
||||
*/
|
||||
addAt(pos: number, element: E, num = 1): boolean {
|
||||
const length = this._size;
|
||||
const length = this._length;
|
||||
rangeCheck(pos, 0, length);
|
||||
if (pos === 0) {
|
||||
while (num--) this.unshift(element);
|
||||
} else if (pos === this._size) {
|
||||
} else if (pos === this._length) {
|
||||
while (num--) this.push(element);
|
||||
} else {
|
||||
const arr: E[] = [];
|
||||
for (let i = pos; i < this._size; ++i) {
|
||||
for (let i = pos; i < this._length; ++i) {
|
||||
arr.push(this.at(i));
|
||||
}
|
||||
this.cut(pos - 1, true);
|
||||
|
@ -465,7 +465,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
|
||||
this._bucketLast = bucketIndex;
|
||||
this._lastInBucket = indexInBucket;
|
||||
this._size = pos + 1;
|
||||
this._length = pos + 1;
|
||||
return this;
|
||||
} else {
|
||||
const newDeque = new Deque<E>([], { bucketSize: this._bucketSize });
|
||||
|
@ -501,12 +501,12 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
|
||||
this._bucketFirst = bucketIndex;
|
||||
this._firstInBucket = indexInBucket;
|
||||
this._size = this._size - pos;
|
||||
this._length = this._length - pos;
|
||||
return this;
|
||||
} else {
|
||||
const newDeque = new Deque<E>([], { bucketSize: this._bucketSize });
|
||||
if (pos < 0) pos = 0;
|
||||
for (let i = pos; i < this._size; i++) {
|
||||
for (let i = pos; i < this._length; i++) {
|
||||
newDeque.push(this.at(i));
|
||||
}
|
||||
|
||||
|
@ -526,11 +526,11 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The size of the data structure after the deletion operation is performed.
|
||||
*/
|
||||
deleteAt(pos: number): boolean {
|
||||
rangeCheck(pos, 0, this._size - 1);
|
||||
rangeCheck(pos, 0, this._length - 1);
|
||||
if (pos === 0) this.shift();
|
||||
else if (pos === this._size - 1) this.pop();
|
||||
else if (pos === this._length - 1) this.pop();
|
||||
else {
|
||||
const length = this._size - 1;
|
||||
const length = this._length - 1;
|
||||
let { bucketIndex: curBucket, indexInBucket: curPointer } = this._getBucketAndPosition(pos);
|
||||
for (let i = pos; i < length; ++i) {
|
||||
const { bucketIndex: nextBucket, indexInBucket: nextPointer } = this._getBucketAndPosition(pos + 1);
|
||||
|
@ -554,7 +554,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The size of the data structure after the element has been deleted.
|
||||
*/
|
||||
delete(element: E): boolean {
|
||||
const size = this._size;
|
||||
const size = this._length;
|
||||
if (size === 0) return false;
|
||||
let i = 0;
|
||||
let index = 0;
|
||||
|
@ -600,12 +600,12 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* @returns The size of the modified array is being returned.
|
||||
*/
|
||||
unique(): this {
|
||||
if (this._size <= 1) {
|
||||
if (this._length <= 1) {
|
||||
return this;
|
||||
}
|
||||
let index = 1;
|
||||
let prev = this.at(0);
|
||||
for (let i = 1; i < this._size; ++i) {
|
||||
for (let i = 1; i < this._length; ++i) {
|
||||
const cur = this.at(i);
|
||||
if (cur !== prev) {
|
||||
prev = cur;
|
||||
|
@ -628,11 +628,11 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
*/
|
||||
sort(comparator?: (x: E, y: E) => number): this {
|
||||
const arr: E[] = [];
|
||||
for (let i = 0; i < this._size; ++i) {
|
||||
for (let i = 0; i < this._length; ++i) {
|
||||
arr.push(this.at(i));
|
||||
}
|
||||
arr.sort(comparator);
|
||||
for (let i = 0; i < this._size; ++i) {
|
||||
for (let i = 0; i < this._length; ++i) {
|
||||
this.setAt(i, arr[i]);
|
||||
}
|
||||
return this;
|
||||
|
@ -645,10 +645,10 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
|
||||
* memory usage.
|
||||
* @returns Nothing is being returned. The function is using the `return` statement to exit early if
|
||||
* `this._size` is 0, but it does not return any value.
|
||||
* `this._length` is 0, but it does not return any value.
|
||||
*/
|
||||
shrinkToFit(): void {
|
||||
if (this._size === 0) return;
|
||||
if (this._length === 0) return;
|
||||
const newBuckets = [];
|
||||
if (this._bucketFirst === this._bucketLast) return;
|
||||
else if (this._bucketFirst < this._bucketLast) {
|
||||
|
@ -680,7 +680,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* in the data structure. If the element is not found, it returns -1.
|
||||
*/
|
||||
indexOf(element: E): number {
|
||||
for (let i = 0; i < this._size; ++i) {
|
||||
for (let i = 0; i < this._length; ++i) {
|
||||
if (this.at(i) === element) {
|
||||
return i;
|
||||
}
|
||||
|
@ -780,7 +780,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|||
* object to be iterated over using a for...of loop.
|
||||
*/
|
||||
protected *_getIterator(): IterableIterator<E> {
|
||||
for (let i = 0; i < this._size; ++i) {
|
||||
for (let i = 0; i < this._length; ++i) {
|
||||
yield this.at(i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,10 +52,10 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|||
}
|
||||
|
||||
/**
|
||||
* The size function returns the number of elements in an array.
|
||||
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
||||
* The length function returns the number of elements in an array.
|
||||
* @returns {number} The length of the array, which is the difference between the length of the array and the offset.
|
||||
*/
|
||||
get size(): number {
|
||||
get length(): number {
|
||||
return this.elements.length - this.offset;
|
||||
}
|
||||
|
||||
|
@ -65,10 +65,10 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|||
*
|
||||
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
||||
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
||||
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
||||
* the `_offset` index. If the data structure is empty (length is 0), it returns `undefined`.
|
||||
*/
|
||||
get first(): E | undefined {
|
||||
return this.size > 0 ? this.elements[this.offset] : undefined;
|
||||
return this.length > 0 ? this.elements[this.offset] : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|||
* array is empty, it returns `undefined`.
|
||||
*/
|
||||
get last(): E | undefined {
|
||||
return this.size > 0 ? this.elements[this.elements.length - 1] : undefined;
|
||||
return this.length > 0 ? this.elements[this.elements.length - 1] : undefined;
|
||||
}
|
||||
|
||||
protected _autoCompactRatio: number = 0.5;
|
||||
|
@ -126,7 +126,7 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|||
*/
|
||||
push(element: E): boolean {
|
||||
this.elements.push(element);
|
||||
if (this._maxLen > 0 && this.size > this._maxLen) this.shift();
|
||||
if (this._maxLen > 0 && this.length > this._maxLen) this.shift();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|||
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
||||
*/
|
||||
shift(): E | undefined {
|
||||
if (this.size === 0) return undefined;
|
||||
if (this.length === 0) return undefined;
|
||||
|
||||
const first = this.first;
|
||||
this._offset += 1;
|
||||
|
@ -213,11 +213,11 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|||
* Time Complexity: O(1)
|
||||
* Space Complexity: O(1)
|
||||
*
|
||||
* The function checks if a data structure is empty by comparing its size to zero.
|
||||
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
||||
* The function checks if a data structure is empty by comparing its length to zero.
|
||||
* @returns {boolean} A boolean value indicating whether the length of the object is 0 or not.
|
||||
*/
|
||||
isEmpty(): boolean {
|
||||
return this.size === 0;
|
||||
return this.length === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,8 +34,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
it('should deleteAt', () => {
|
||||
expect(list.deleteAt(1)).toBe(true);
|
||||
expect(list.deleteAt(-1)).toBe(false);
|
||||
expect(list.deleteAt(list.size)).toBe(false);
|
||||
expect(list.size).toBe(4);
|
||||
expect(list.deleteAt(list.length)).toBe(false);
|
||||
expect(list.length).toBe(4);
|
||||
expect(list.deleteAt(4)).toBe(false);
|
||||
expect([...list]).toEqual([1, 3, 4, 5]);
|
||||
expect(list.isEmpty()).toBe(false);
|
||||
|
@ -103,7 +103,7 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
});
|
||||
|
||||
it('should initialize an empty list', () => {
|
||||
expect(list.size).toBe(0);
|
||||
expect(list.length).toBe(0);
|
||||
expect(list.head).toBe(undefined);
|
||||
expect(list.tail).toBe(undefined);
|
||||
});
|
||||
|
@ -119,7 +119,7 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
list.push(1);
|
||||
list.push(2);
|
||||
list.push(3);
|
||||
expect(list.size).toBe(3);
|
||||
expect(list.length).toBe(3);
|
||||
expect(list.head!.value).toBe(1);
|
||||
expect(list.tail!.value).toBe(3);
|
||||
});
|
||||
|
@ -130,7 +130,7 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
list.push(i);
|
||||
}
|
||||
expect(list.maxLen).toBe(10);
|
||||
expect(list.size).toBe(10);
|
||||
expect(list.length).toBe(10);
|
||||
expect(list.first).toBe(990);
|
||||
|
||||
list.clear();
|
||||
|
@ -139,7 +139,7 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
}
|
||||
|
||||
expect(list.maxLen).toBe(10);
|
||||
expect(list.size).toBe(10);
|
||||
expect(list.length).toBe(10);
|
||||
expect(list.last).toBe(990);
|
||||
});
|
||||
|
||||
|
@ -148,7 +148,7 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
list.push(2);
|
||||
const poppedValue = list.pop();
|
||||
expect(poppedValue).toBe(2);
|
||||
expect(list.size).toBe(1);
|
||||
expect(list.length).toBe(1);
|
||||
expect(list.head!.value).toBe(1);
|
||||
expect(list.tail!.value).toBe(1);
|
||||
list.pop();
|
||||
|
@ -164,19 +164,19 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
|
||||
// Inserting at the beginning
|
||||
list.addAt(0, 0);
|
||||
expect(list.size).toBe(4);
|
||||
expect(list.length).toBe(4);
|
||||
expect(list.at(0)).toBe(0);
|
||||
expect(list.at(1)).toBe(1);
|
||||
|
||||
// Inserting in the middle
|
||||
list.addAt(2, 1.5);
|
||||
expect(list.size).toBe(5);
|
||||
expect(list.length).toBe(5);
|
||||
expect(list.at(2)).toBe(1.5);
|
||||
expect(list.at(3)).toBe(2);
|
||||
|
||||
// Inserting at the end
|
||||
list.addAt(5, 4);
|
||||
expect(list.size).toBe(6);
|
||||
expect(list.length).toBe(6);
|
||||
expect(list.at(5)).toBe(4);
|
||||
expect(list.tail!.value).toBe(4);
|
||||
expect(list.at(-1)).toBe(undefined);
|
||||
|
@ -191,17 +191,17 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
// Deleting from the beginning
|
||||
const deletedValue = list.deleteAt(0);
|
||||
expect(deletedValue).toBe(true);
|
||||
expect(list.size).toBe(2);
|
||||
expect(list.length).toBe(2);
|
||||
expect(list.head!.value).toBe(2);
|
||||
|
||||
// Deleting from the middle
|
||||
list.deleteAt(0); // Deleting the second element
|
||||
expect(list.size).toBe(1);
|
||||
expect(list.length).toBe(1);
|
||||
expect(list.head!.value).toBe(3);
|
||||
|
||||
// Deleting from the end
|
||||
list.deleteAt(0);
|
||||
expect(list.size).toBe(0);
|
||||
expect(list.length).toBe(0);
|
||||
expect(list.head).toBe(undefined);
|
||||
expect(list.tail).toBe(undefined);
|
||||
});
|
||||
|
@ -212,16 +212,16 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
list.push(3);
|
||||
|
||||
list.delete(2);
|
||||
expect(list.size).toBe(2);
|
||||
expect(list.length).toBe(2);
|
||||
expect(list.head!.value).toBe(1);
|
||||
expect(list.tail!.value).toBe(3);
|
||||
|
||||
list.delete(1);
|
||||
expect(list.size).toBe(1);
|
||||
expect(list.length).toBe(1);
|
||||
expect(list.head!.value).toBe(3);
|
||||
|
||||
list.delete(3);
|
||||
expect(list.size).toBe(0);
|
||||
expect(list.length).toBe(0);
|
||||
expect(list.head).toBe(undefined);
|
||||
expect(list.tail).toBe(undefined);
|
||||
});
|
||||
|
@ -326,7 +326,7 @@ describe('DoublyLinkedList Operation Test', () => {
|
|||
|
||||
list.clear();
|
||||
|
||||
expect(list.size).toBe(0);
|
||||
expect(list.length).toBe(0);
|
||||
expect(list.head).toBe(undefined);
|
||||
expect(list.tail).toBe(undefined);
|
||||
});
|
||||
|
@ -597,7 +597,7 @@ describe('classic use', () => {
|
|||
const initialNode = this.currentSong;
|
||||
|
||||
// Loop through the playlist twice
|
||||
for (let i = 0; i < this.playlist.size * 2; i++) {
|
||||
for (let i = 0; i < this.playlist.length * 2; i++) {
|
||||
playedSongs.push(this.currentSong!.value);
|
||||
this.currentSong = this.currentSong!.next || this.playlist.head; // Loop back to the start if needed
|
||||
}
|
||||
|
@ -719,7 +719,7 @@ describe('classic use', () => {
|
|||
}
|
||||
|
||||
// Check capacity
|
||||
if (this.list.size >= this.capacity) {
|
||||
if (this.list.length >= this.capacity) {
|
||||
// Delete the least recently used element (the tail of the linked list)
|
||||
const removedNode = this.list.tail;
|
||||
if (removedNode) {
|
||||
|
@ -764,9 +764,9 @@ describe('classic use', () => {
|
|||
this.map.clear();
|
||||
}
|
||||
|
||||
// Get the current cache size
|
||||
get size(): number {
|
||||
return this.list.size;
|
||||
// Get the current cache length
|
||||
get length(): number {
|
||||
return this.list.length;
|
||||
}
|
||||
|
||||
// Check if it is empty
|
||||
|
@ -825,7 +825,7 @@ describe('classic use', () => {
|
|||
|
||||
expect(cache.delete('a')).toBe(true);
|
||||
expect(cache.get('a')).toBeUndefined();
|
||||
expect(cache.size).toBe(1);
|
||||
expect(cache.length).toBe(1);
|
||||
|
||||
// Should support clearing cache
|
||||
cache.clear();
|
||||
|
@ -833,7 +833,7 @@ describe('classic use', () => {
|
|||
cache.set('b', 2);
|
||||
cache.clear();
|
||||
|
||||
expect(cache.size).toBe(0);
|
||||
expect(cache.length).toBe(0);
|
||||
expect(cache.isEmpty).toBe(true);
|
||||
});
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|||
list.push(i);
|
||||
}
|
||||
expect(list.maxLen).toBe(10);
|
||||
expect(list.size).toBe(10);
|
||||
expect(list.length).toBe(10);
|
||||
expect(list.first).toBe(990);
|
||||
});
|
||||
});
|
||||
|
@ -197,7 +197,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|||
list.push(3);
|
||||
list.clear();
|
||||
expect(list.toArray()).toEqual([]);
|
||||
expect(list.size).toBe(0);
|
||||
expect(list.length).toBe(0);
|
||||
expect(list.isEmpty()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
@ -287,10 +287,10 @@ describe('SinglyLinkedList Operation Test', () => {
|
|||
|
||||
describe('getLength', () => {
|
||||
it('should return the correct length of the list', () => {
|
||||
expect(list.size).toBe(0);
|
||||
expect(list.length).toBe(0);
|
||||
list.push(1);
|
||||
list.push(2);
|
||||
expect(list.size).toBe(2);
|
||||
expect(list.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -468,7 +468,7 @@ describe('SinglyLinkedList', () => {
|
|||
it('should initialize an empty list', () => {
|
||||
expect(list.head).toBe(undefined);
|
||||
expect(list.tail).toBe(undefined);
|
||||
expect(list.size).toBe(0);
|
||||
expect(list.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should push elements to the end of the list', () => {
|
||||
|
@ -476,7 +476,7 @@ describe('SinglyLinkedList', () => {
|
|||
list.push(2);
|
||||
expect(list.head!.value).toBe(1);
|
||||
expect(list.tail!.value).toBe(2);
|
||||
expect(list.size).toBe(2);
|
||||
expect(list.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should pop elements from the end of the list', () => {
|
||||
|
@ -486,7 +486,7 @@ describe('SinglyLinkedList', () => {
|
|||
expect(popped).toBe(2);
|
||||
expect(list.head!.value).toBe(1);
|
||||
expect(list.tail!.value).toBe(1);
|
||||
expect(list.size).toBe(1);
|
||||
expect(list.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should reverse the list', () => {
|
||||
|
|
|
@ -11,13 +11,13 @@ describe('Deque - Basic Operations', () => {
|
|||
});
|
||||
|
||||
it('push should add elements to the end', () => {
|
||||
expect(deque.size).toBe(2);
|
||||
expect(deque.length).toBe(2);
|
||||
expect(deque.last).toBe(2);
|
||||
});
|
||||
|
||||
it('pop should remove elements from the end', () => {
|
||||
expect(deque.pop()).toBe(2);
|
||||
expect(deque.size).toBe(1);
|
||||
expect(deque.length).toBe(1);
|
||||
expect(deque.pop()).toBe(1);
|
||||
expect(deque.isEmpty()).toBeTruthy();
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ describe('Deque - Basic Operations', () => {
|
|||
deque.clear();
|
||||
deque.unshift(1);
|
||||
deque.unshift(2);
|
||||
expect(deque.size).toBe(2);
|
||||
expect(deque.length).toBe(2);
|
||||
expect(deque.first).toBe(2);
|
||||
});
|
||||
|
||||
|
@ -35,7 +35,7 @@ describe('Deque - Basic Operations', () => {
|
|||
deque.unshift(1);
|
||||
deque.unshift(2);
|
||||
expect(deque.shift()).toBe(2);
|
||||
expect(deque.size).toBe(1);
|
||||
expect(deque.length).toBe(1);
|
||||
expect(deque.shift()).toBe(1);
|
||||
expect(deque.isEmpty()).toBeTruthy();
|
||||
});
|
||||
|
@ -88,24 +88,24 @@ describe('Deque - Basic Operations', () => {
|
|||
deque.push('0');
|
||||
deque.push('5');
|
||||
deque.push('9');
|
||||
expect(deque.size).toBe(6);
|
||||
expect(deque.length).toBe(6);
|
||||
deque.delete('2');
|
||||
expect(deque.size).toBe(5);
|
||||
expect(deque.length).toBe(5);
|
||||
expect([...deque]).toEqual(['1', '6', '0', '5', '9']);
|
||||
const cloned = deque.clone();
|
||||
expect([...cloned]).toEqual(['1', '6', '0', '5', '9']);
|
||||
expect(deque.size).toBe(5);
|
||||
expect(deque.length).toBe(5);
|
||||
deque.delete('5');
|
||||
expect(deque.size).toBe(4);
|
||||
expect(deque.length).toBe(4);
|
||||
expect([...deque]).toEqual(['1', '6', '0', '9']);
|
||||
expect([...cloned]).toEqual(['1', '6', '0', '5', '9']);
|
||||
expect(cloned.size).toBe(5);
|
||||
expect(cloned.length).toBe(5);
|
||||
cloned.push('8');
|
||||
expect(cloned.size).toBe(6);
|
||||
expect(cloned.length).toBe(6);
|
||||
cloned.delete('6');
|
||||
expect(cloned.size).toBe(5);
|
||||
expect(cloned.length).toBe(5);
|
||||
cloned.delete('6');
|
||||
expect(cloned.size).toBe(5);
|
||||
expect(cloned.length).toBe(5);
|
||||
});
|
||||
});
|
||||
describe('Deque - Complex Operations', () => {
|
||||
|
@ -126,15 +126,15 @@ describe('Deque - Complex Operations', () => {
|
|||
deque.push(1);
|
||||
deque.push(2);
|
||||
deque.push(3);
|
||||
expect(deque.size).toBe(3);
|
||||
expect(deque.length).toBe(3);
|
||||
deque.cut(1, true);
|
||||
expect(deque.size).toBe(2);
|
||||
expect(deque.length).toBe(2);
|
||||
expect(deque.toArray()).toEqual([1, 2]);
|
||||
|
||||
const dq1 = new Deque([1, 2, 3, 4, 5, 6, 7]);
|
||||
expect(dq1.size).toBe(7);
|
||||
expect(dq1.length).toBe(7);
|
||||
expect([...dq1.cut(3, true)]).toEqual([1, 2, 3, 4]);
|
||||
expect(dq1.size).toBe(4);
|
||||
expect(dq1.length).toBe(4);
|
||||
expect([...dq1]).toEqual([1, 2, 3, 4]);
|
||||
const dqCut = dq1.cut(2);
|
||||
expect(dqCut.toArray()).toEqual([1, 2, 3]);
|
||||
|
@ -228,7 +228,7 @@ describe('Deque - Complex Operations', () => {
|
|||
|
||||
it('shrinkToFit should reduce the memory footprint', () => {
|
||||
deque.shrinkToFit();
|
||||
expect(deque.size).toBe(0);
|
||||
expect(deque.length).toBe(0);
|
||||
expect(deque.has(1)).toBe(false);
|
||||
expect(deque.bucketFirst).toBe(0);
|
||||
expect(deque.bucketLast).toBe(0);
|
||||
|
@ -241,7 +241,7 @@ describe('Deque - Complex Operations', () => {
|
|||
deque.shrinkToFit();
|
||||
|
||||
deque = new Deque([1, 2, 3, 4, 5], { bucketSize: 2 });
|
||||
expect(deque.size).toBe(5);
|
||||
expect(deque.length).toBe(5);
|
||||
expect(deque.has(1)).toBe(true);
|
||||
expect(deque.bucketFirst).toBe(0);
|
||||
expect(deque.bucketLast).toBe(2);
|
||||
|
@ -322,19 +322,19 @@ describe('Deque - Utility Operations', () => {
|
|||
|
||||
it('should maxLen work well', () => {
|
||||
const dequeMaxLen = new Deque([3, 4, 5, 6, 7], { maxLen: 3 });
|
||||
expect(dequeMaxLen.size).toBe(3);
|
||||
expect(dequeMaxLen.length).toBe(3);
|
||||
expect(dequeMaxLen.toArray()).toEqual([5, 6, 7]);
|
||||
dequeMaxLen.unshift(4);
|
||||
dequeMaxLen.unshift(3);
|
||||
expect(dequeMaxLen.size).toBe(3);
|
||||
expect(dequeMaxLen.length).toBe(3);
|
||||
expect(dequeMaxLen.toArray()).toEqual([3, 4, 5]);
|
||||
|
||||
const dequeNoMaxLen = new Deque([3, 4, 5, 6, 7]);
|
||||
expect(dequeNoMaxLen.size).toBe(5);
|
||||
expect(dequeNoMaxLen.length).toBe(5);
|
||||
expect(dequeNoMaxLen.toArray()).toEqual([3, 4, 5, 6, 7]);
|
||||
dequeNoMaxLen.unshift(4);
|
||||
dequeNoMaxLen.unshift(3);
|
||||
expect(dequeNoMaxLen.size).toBe(7);
|
||||
expect(dequeNoMaxLen.length).toBe(7);
|
||||
expect(dequeNoMaxLen.toArray()).toEqual([3, 4, 3, 4, 5, 6, 7]);
|
||||
});
|
||||
});
|
||||
|
@ -350,21 +350,21 @@ describe('Deque - Additional Operations', () => {
|
|||
deque.push(1);
|
||||
deque.push(2);
|
||||
expect(deque.last).toBe(2);
|
||||
expect(deque.size).toBe(2);
|
||||
expect(deque.length).toBe(2);
|
||||
});
|
||||
|
||||
it('pop should remove and return the last element', () => {
|
||||
deque.push(1);
|
||||
deque.push(2);
|
||||
expect(deque.pop()).toBe(2);
|
||||
expect(deque.size).toBe(1);
|
||||
expect(deque.length).toBe(1);
|
||||
});
|
||||
|
||||
it('unshift should add an element to the beginning', () => {
|
||||
deque.unshift(1);
|
||||
deque.unshift(2);
|
||||
expect(deque.first).toBe(2);
|
||||
expect(deque.size).toBe(2);
|
||||
expect(deque.length).toBe(2);
|
||||
});
|
||||
|
||||
it('shift should remove and return the first element', () => {
|
||||
|
@ -372,13 +372,13 @@ describe('Deque - Additional Operations', () => {
|
|||
deque.unshift(1);
|
||||
deque.unshift(2);
|
||||
expect(deque.shift()).toBe(2);
|
||||
expect(deque.size).toBe(1);
|
||||
expect(deque.length).toBe(1);
|
||||
});
|
||||
|
||||
it('clear should reset the deque', () => {
|
||||
deque.unshift(1);
|
||||
deque.clear();
|
||||
expect(deque.size).toBe(0);
|
||||
expect(deque.length).toBe(0);
|
||||
expect(deque.isEmpty()).toBeTruthy();
|
||||
});
|
||||
|
||||
|
@ -411,7 +411,7 @@ describe('Deque - push Method', () => {
|
|||
it('push should add an element when deque is empty', () => {
|
||||
deque.push(1);
|
||||
expect(deque.last).toBe(1);
|
||||
expect(deque.size).toBe(1);
|
||||
expect(deque.length).toBe(1);
|
||||
});
|
||||
|
||||
it('push should add an element when lastInBucket is not at max', () => {
|
||||
|
@ -420,7 +420,7 @@ describe('Deque - push Method', () => {
|
|||
}
|
||||
deque.push(bucketSize);
|
||||
expect(deque.last).toBe(bucketSize);
|
||||
expect(deque.size).toBe(bucketSize);
|
||||
expect(deque.length).toBe(bucketSize);
|
||||
});
|
||||
|
||||
it('push should add an element and move to next bucket when last bucket is full', () => {
|
||||
|
@ -429,7 +429,7 @@ describe('Deque - push Method', () => {
|
|||
}
|
||||
deque.push(bucketSize + 1);
|
||||
expect(deque.last).toBe(bucketSize + 1);
|
||||
expect(deque.size).toBe(bucketSize + 1);
|
||||
expect(deque.length).toBe(bucketSize + 1);
|
||||
});
|
||||
|
||||
it('push should add an element and reallocate when last bucket and lastInBucket are at max', () => {
|
||||
|
@ -439,7 +439,7 @@ describe('Deque - push Method', () => {
|
|||
|
||||
deque.push(100);
|
||||
expect(deque.last).toBe(100);
|
||||
expect(deque.size).toBeGreaterThan(bucketSize);
|
||||
expect(deque.length).toBeGreaterThan(bucketSize);
|
||||
});
|
||||
});
|
||||
describe('Deque - pop Method', () => {
|
||||
|
@ -456,7 +456,7 @@ describe('Deque - pop Method', () => {
|
|||
deque.push(1);
|
||||
deque.push(2);
|
||||
expect(deque.pop()).toBe(2);
|
||||
expect(deque.size).toBe(1);
|
||||
expect(deque.length).toBe(1);
|
||||
});
|
||||
|
||||
it('pop should handle popping the only element', () => {
|
||||
|
@ -488,7 +488,7 @@ describe('Deque - unshift Method', () => {
|
|||
it('unshift should add an element to the beginning when deque is empty', () => {
|
||||
deque.unshift(1);
|
||||
expect(deque.first).toBe(1);
|
||||
expect(deque.size).toBe(1);
|
||||
expect(deque.length).toBe(1);
|
||||
});
|
||||
|
||||
it('unshift should add an element to the beginning and adjust firstInBucket', () => {
|
||||
|
@ -523,7 +523,7 @@ describe('Deque - shift Method', () => {
|
|||
deque.push(1);
|
||||
deque.push(2);
|
||||
expect(deque.shift()).toBe(1);
|
||||
expect(deque.size).toBe(1);
|
||||
expect(deque.length).toBe(1);
|
||||
});
|
||||
|
||||
it('shift should handle shifting the only element', () => {
|
||||
|
@ -565,7 +565,7 @@ describe('Deque', () => {
|
|||
|
||||
const numbers = new IterableNumbers([1, 6, 7, 3, 2, 4, 5]);
|
||||
const deque = new Deque(numbers, { bucketSize: 3 });
|
||||
expect(deque.size).toBe(7);
|
||||
expect(deque.length).toBe(7);
|
||||
expect(deque.bucketSize).toBe(3);
|
||||
expect(deque.maxLen).toBe(-1);
|
||||
});
|
||||
|
@ -591,7 +591,7 @@ describe('Deque', () => {
|
|||
|
||||
const numbers = new IterableNumbersWithSize([1, 6, 7, 3, 2, 4, 5]);
|
||||
const deque = new Deque(numbers, { bucketSize: 3 });
|
||||
expect(deque.size).toBe(7);
|
||||
expect(deque.length).toBe(7);
|
||||
expect(deque.bucketSize).toBe(3);
|
||||
expect(deque.maxLen).toBe(-1);
|
||||
});
|
||||
|
@ -601,7 +601,7 @@ describe('Deque', () => {
|
|||
key: number;
|
||||
}> = [{ key: 1 }, { key: 6 }, { key: 7 }, { key: 3 }, { key: 2 }, { key: 4 }, { key: 5 }];
|
||||
const deque = new Deque<number>(objArr, { toElementFn: item => item.key });
|
||||
expect(deque.size).toBe(7);
|
||||
expect(deque.length).toBe(7);
|
||||
expect(deque.has(1)).toBe(true);
|
||||
expect(deque.has(7)).toBe(true);
|
||||
expect(deque.has(8)).toBe(false);
|
||||
|
@ -612,7 +612,7 @@ describe('Deque', () => {
|
|||
key: number;
|
||||
}> = [{ key: 1 }, { key: 6 }, { key: 7 }, { key: 3 }, { key: 2 }, { key: 4 }, { key: 5 }];
|
||||
const deque = new Deque<number>(objArr, { toElementFn: item => item.key, bucketSize: 3 });
|
||||
expect(deque.size).toBe(7);
|
||||
expect(deque.length).toBe(7);
|
||||
expect(deque.has(1)).toBe(true);
|
||||
expect(deque.bucketFirst).toBe(0);
|
||||
expect(deque.bucketLast).toBe(2);
|
||||
|
@ -628,7 +628,7 @@ describe('Deque', () => {
|
|||
|
||||
it('should pop work well when bucket boundary is reached', () => {
|
||||
const deque = new Deque<number>([1, 6, 7, 3, 2, 4, 5], { bucketSize: 3 });
|
||||
expect(deque.size).toBe(7);
|
||||
expect(deque.length).toBe(7);
|
||||
expect(deque.has(1)).toBe(true);
|
||||
expect(deque.bucketFirst).toBe(0);
|
||||
expect(deque.bucketLast).toBe(2);
|
||||
|
@ -641,7 +641,7 @@ describe('Deque', () => {
|
|||
[4, 5]
|
||||
]);
|
||||
for (let i = 0; i < 3; ++i) deque.pop();
|
||||
expect(deque.size).toBe(4);
|
||||
expect(deque.length).toBe(4);
|
||||
expect(deque.has(1)).toBe(true);
|
||||
expect(deque.bucketFirst).toBe(0);
|
||||
expect(deque.bucketLast).toBe(1);
|
||||
|
@ -654,7 +654,7 @@ describe('Deque', () => {
|
|||
[4, 5]
|
||||
]); // TODO may be a problem
|
||||
deque.pop();
|
||||
expect(deque.size).toBe(3);
|
||||
expect(deque.length).toBe(3);
|
||||
expect(deque.has(1)).toBe(true);
|
||||
expect(deque.bucketFirst).toBe(0);
|
||||
expect(deque.bucketLast).toBe(1);
|
||||
|
@ -670,7 +670,7 @@ describe('Deque', () => {
|
|||
|
||||
it('should shift work well when bucket boundary is reached and should shrinkToFit', () => {
|
||||
const deque = new Deque<number>([1, 6, 7, 3, 2, 4, 5], { bucketSize: 3 });
|
||||
expect(deque.size).toBe(7);
|
||||
expect(deque.length).toBe(7);
|
||||
expect(deque.has(1)).toBe(true);
|
||||
expect(deque.bucketFirst).toBe(0);
|
||||
expect(deque.bucketLast).toBe(2);
|
||||
|
@ -683,7 +683,7 @@ describe('Deque', () => {
|
|||
[4, 5]
|
||||
]);
|
||||
for (let i = 0; i < 3; ++i) deque.shift();
|
||||
expect(deque.size).toBe(4);
|
||||
expect(deque.length).toBe(4);
|
||||
expect(deque.has(1)).toBe(false);
|
||||
expect(deque.bucketFirst).toBe(1);
|
||||
expect(deque.bucketLast).toBe(2);
|
||||
|
@ -696,7 +696,7 @@ describe('Deque', () => {
|
|||
[4, 5]
|
||||
]); // TODO may be a problem
|
||||
deque.shift();
|
||||
expect(deque.size).toBe(3);
|
||||
expect(deque.length).toBe(3);
|
||||
expect(deque.has(1)).toBe(false);
|
||||
expect(deque.bucketFirst).toBe(1);
|
||||
expect(deque.bucketLast).toBe(2);
|
||||
|
@ -709,7 +709,7 @@ describe('Deque', () => {
|
|||
[4, 5]
|
||||
]); // TODO may be a problem
|
||||
deque.shrinkToFit();
|
||||
expect(deque.size).toBe(3);
|
||||
expect(deque.length).toBe(3);
|
||||
expect(deque.has(1)).toBe(false);
|
||||
expect(deque.bucketFirst).toBe(0);
|
||||
expect(deque.bucketLast).toBe(1);
|
||||
|
@ -735,7 +735,7 @@ describe('classic uses', () => {
|
|||
|
||||
// Rotate clockwise to the right (forward)
|
||||
rotateClockwise(steps: number): void {
|
||||
const n = this.deque.size;
|
||||
const n = this.deque.length;
|
||||
if (n === 0) return;
|
||||
|
||||
for (let i = 0; i < steps; i++) {
|
||||
|
@ -746,7 +746,7 @@ describe('classic uses', () => {
|
|||
|
||||
// Rotate counterclockwise to the left (backward)
|
||||
rotateCounterClockwise(steps: number): void {
|
||||
const n = this.deque.size;
|
||||
const n = this.deque.length;
|
||||
if (n === 0) return;
|
||||
|
||||
for (let i = 0; i < steps; i++) {
|
||||
|
|
|
@ -11,21 +11,21 @@ describe('Queue', () => {
|
|||
});
|
||||
|
||||
it('new Queue() should create an empty queue', () => {
|
||||
expect(queue.size).toBe(0);
|
||||
expect(queue.length).toBe(0);
|
||||
expect(queue.isEmpty()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('push should add elements to the queue', () => {
|
||||
queue.push(1);
|
||||
queue.push(2);
|
||||
expect(queue.size).toBe(2);
|
||||
expect(queue.length).toBe(2);
|
||||
});
|
||||
|
||||
it('shift should remove the first element', () => {
|
||||
queue.push(1);
|
||||
queue.push(2);
|
||||
expect(queue.shift()).toBe(1);
|
||||
expect(queue.size).toBe(1);
|
||||
expect(queue.length).toBe(1);
|
||||
});
|
||||
|
||||
it('shift should return undefined if queue is empty', () => {
|
||||
|
@ -36,17 +36,17 @@ describe('Queue', () => {
|
|||
queue.push(1);
|
||||
queue.push(2);
|
||||
expect(queue.first).toBe(1);
|
||||
expect(queue.size).toBe(2);
|
||||
expect(queue.length).toBe(2);
|
||||
});
|
||||
|
||||
it('first should return undefined if queue is empty', () => {
|
||||
expect(queue.first).toBeUndefined();
|
||||
});
|
||||
|
||||
it('size should return the number of elements', () => {
|
||||
it('length should return the number of elements', () => {
|
||||
queue.push(1);
|
||||
queue.push(2);
|
||||
expect(queue.size).toBe(2);
|
||||
expect(queue.length).toBe(2);
|
||||
});
|
||||
|
||||
it('isEmpty should return true if the queue is empty', () => {
|
||||
|
@ -68,7 +68,7 @@ describe('Queue', () => {
|
|||
queue.push(1);
|
||||
queue.push(2);
|
||||
queue.clear();
|
||||
expect(queue.size).toBe(0);
|
||||
expect(queue.length).toBe(0);
|
||||
});
|
||||
|
||||
it('forEach should iterate over all elements', () => {
|
||||
|
@ -96,7 +96,7 @@ describe('Queue', () => {
|
|||
queue.push(i);
|
||||
}
|
||||
expect(queue.maxLen).toBe(10);
|
||||
expect(queue.size).toBe(10);
|
||||
expect(queue.length).toBe(10);
|
||||
expect(queue.first).toBe(990);
|
||||
});
|
||||
|
||||
|
@ -129,9 +129,9 @@ describe('Queue', () => {
|
|||
toElementFn: rawElement => rawElement.id
|
||||
});
|
||||
|
||||
expect(queue.size).toBe(5);
|
||||
expect(queue.length).toBe(5);
|
||||
queue.shift();
|
||||
expect(queue.size).toBe(4);
|
||||
expect(queue.length).toBe(4);
|
||||
expect(queue.at(1)).toBe('3');
|
||||
});
|
||||
|
||||
|
@ -203,11 +203,11 @@ describe('Queue', () => {
|
|||
queue.push(9);
|
||||
queue.push(10);
|
||||
expect(queue.elements.length).toBe(10);
|
||||
while (queue.size > 7) queue.shift();
|
||||
expect(queue.size).toBe(7);
|
||||
while (queue.length > 7) queue.shift();
|
||||
expect(queue.length).toBe(7);
|
||||
expect(queue.elements.length).toBe(10);
|
||||
queue.shift();
|
||||
expect(queue.size).toBe(6);
|
||||
expect(queue.length).toBe(6);
|
||||
expect(queue.elements.length).toBe(6);
|
||||
});
|
||||
});
|
||||
|
@ -270,7 +270,7 @@ describe('Queue - Additional Methods', () => {
|
|||
queue.push(1);
|
||||
queue.push(2);
|
||||
expect(queue.last).toBe(2);
|
||||
expect(queue.size).toBe(2);
|
||||
expect(queue.length).toBe(2);
|
||||
});
|
||||
|
||||
it('peekLast should return undefined if queue is empty', () => {
|
||||
|
@ -303,7 +303,7 @@ describe('Queue - Static and Clone Methods', () => {
|
|||
const array = [1, 2, 3];
|
||||
const queue = Queue.fromArray(array);
|
||||
expect(queue.toArray()).toEqual(array);
|
||||
expect(queue.size).toBe(array.length);
|
||||
expect(queue.length).toBe(array.length);
|
||||
});
|
||||
|
||||
it('fromArray should create an empty queue from an empty array', () => {
|
||||
|
@ -318,7 +318,7 @@ describe('Queue - Static and Clone Methods', () => {
|
|||
|
||||
const clonedQueue = originalQueue.clone();
|
||||
expect(clonedQueue.toArray()).toEqual(originalQueue.toArray());
|
||||
expect(clonedQueue.size).toBe(originalQueue.size);
|
||||
expect(clonedQueue.length).toBe(originalQueue.length);
|
||||
});
|
||||
|
||||
it('clone should not affect the original queue when mutated', () => {
|
||||
|
@ -329,7 +329,7 @@ describe('Queue - Static and Clone Methods', () => {
|
|||
const clonedQueue = originalQueue.clone();
|
||||
clonedQueue.push(3);
|
||||
|
||||
expect(clonedQueue.size).not.toBe(originalQueue.size);
|
||||
expect(clonedQueue.length).not.toBe(originalQueue.length);
|
||||
expect(originalQueue.toArray()).not.toContain(3);
|
||||
});
|
||||
});
|
||||
|
@ -345,14 +345,14 @@ describe('LinkedListQueue', () => {
|
|||
|
||||
it('should push elements to the end of the queue', () => {
|
||||
expect(queue.first).toBe('A');
|
||||
expect(queue.size).toBe(2);
|
||||
expect(queue.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should shift elements from the front of the queue', () => {
|
||||
const dequeued = queue.shift();
|
||||
expect(dequeued).toBe('A');
|
||||
expect(queue.first).toBe('B');
|
||||
expect(queue.size).toBe(1);
|
||||
expect(queue.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should peek at the front of the queue', () => {
|
||||
|
@ -362,6 +362,6 @@ describe('LinkedListQueue', () => {
|
|||
it('should clone method work correctly', () => {
|
||||
const cloned = queue.clone();
|
||||
expect(cloned instanceof LinkedListQueue).toBe(true);
|
||||
expect(cloned.size).toBe(2);
|
||||
expect(cloned.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -263,7 +263,7 @@ describe('conversions', () => {
|
|||
'triangle'
|
||||
]);
|
||||
const dq = new Deque<string>(heap);
|
||||
expect(dq.size).toBe(10);
|
||||
expect(dq.length).toBe(10);
|
||||
if (isDebug) dq.print();
|
||||
expect([...dq]).toEqual([
|
||||
'transmit',
|
||||
|
|
Loading…
Reference in a new issue