repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(deps-dev): apply updates
[poolifier.git]
/
src
/
deque.ts
diff --git
a/src/deque.ts
b/src/deque.ts
index 723f1a4950688bcea0244e83a8f764b02cdf5a38..0d55f5b665115b3c5efc2580fcdb56562926b340 100644
(file)
--- a/
src/deque.ts
+++ b/
src/deque.ts
@@
-1,19
+1,15
@@
-// Copyright Jerome Benoit. 2023. All Rights Reserved.
+// Copyright Jerome Benoit. 2023
-2024
. All Rights Reserved.
/**
/**
- *
Nod
e.
+ *
Linked list node interfac
e.
*
*
- * @typeParam T - Type of node data.
+ * @typeParam T - Type of
linked list
node data.
* @internal
*/
* @internal
*/
-export class Node<T> {
- public data: T
- public next?: Node<T>
- public prev?: Node<T>
-
- public constructor (data: T) {
- this.data = data
- }
+export interface ILinkedListNode<T> {
+ data: T
+ next?: ILinkedListNode<T>
+ prev?: ILinkedListNode<T>
}
/**
}
/**
@@
-24,8
+20,8
@@
export class Node<T> {
* @internal
*/
export class Deque<T> {
* @internal
*/
export class Deque<T> {
- private head?: Node<T>
- private tail?: Node<T>
+ private head?:
ILinkedList
Node<T>
+ private tail?:
ILinkedList
Node<T>
/** The size of the deque. */
public size!: number
/** The maximum size of the deque. */
/** The size of the deque. */
public size!: number
/** The maximum size of the deque. */
@@
-42,7
+38,7
@@
export class Deque<T> {
* @returns The new size of the queue.
*/
public push (data: T): number {
* @returns The new size of the queue.
*/
public push (data: T): number {
- const node
= new Node(data)
+ const node
: ILinkedListNode<T> = { data }
if (this.tail == null) {
this.head = this.tail = node
} else {
if (this.tail == null) {
this.head = this.tail = node
} else {
@@
-59,7
+55,7
@@
export class Deque<T> {
* @returns The new size of the queue.
*/
public unshift (data: T): number {
* @returns The new size of the queue.
*/
public unshift (data: T): number {
- const node
= new Node(data)
+ const node
: ILinkedListNode<T> = { data }
if (this.head == null) {
this.head = this.tail = node
} else {
if (this.head == null) {
this.head = this.tail = node
} else {
@@
-79,7
+75,7
@@
export class Deque<T> {
return
}
const tail = this.tail
return
}
const tail = this.tail
- this.tail =
(this.tail as Node<T>)
.prev
+ this.tail =
this.tail?
.prev
if (this.tail == null) {
delete this.head
} else {
if (this.tail == null) {
delete this.head
} else {
@@
-106,7
+102,7
@@
export class Deque<T> {
delete this.head.prev
}
--this.size
delete this.head.prev
}
--this.size
- return head
?
.data
+ return head.data
}
/**
}
/**
@@
-155,7
+151,7
@@
export class Deque<T> {
value: node.data,
done: false
}
value: node.data,
done: false
}
- node = node.next
as Node<T>
+ node = node.next
return ret
}
}
return ret
}
}
@@
-183,7
+179,7
@@
export class Deque<T> {
value: node.data,
done: false
}
value: node.data,
done: false
}
- node = node.prev
as Node<T>
+ node = node.prev
return ret
}
}
return ret
}
}