queue-typed 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -37
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +96 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +103 -7
- package/dist/types/data-structures/binary-tree/bst.d.ts +156 -13
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +84 -35
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/types/data-structures/graph/directed-graph.d.ts +126 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +160 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +110 -27
- package/dist/types/data-structures/heap/heap.d.ts +107 -58
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +72 -404
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -5
- package/dist/types/data-structures/queue/deque.d.ts +95 -67
- package/dist/types/data-structures/queue/queue.d.ts +90 -34
- package/dist/types/data-structures/stack/stack.d.ts +58 -40
- package/dist/types/data-structures/trie/trie.d.ts +109 -47
- package/dist/types/interfaces/binary-tree.d.ts +1 -0
- package/dist/umd/queue-typed.js.map +1 -1
- package/dist/umd/queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +96 -2
- package/src/data-structures/binary-tree/binary-tree.ts +117 -7
- package/src/data-structures/binary-tree/bst.ts +322 -13
- package/src/data-structures/binary-tree/red-black-tree.ts +84 -35
- package/src/data-structures/binary-tree/tree-multi-map.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +126 -1
- package/src/data-structures/graph/undirected-graph.ts +160 -1
- package/src/data-structures/hash/hash-map.ts +110 -27
- package/src/data-structures/heap/heap.ts +107 -58
- package/src/data-structures/linked-list/doubly-linked-list.ts +72 -404
- package/src/data-structures/linked-list/singly-linked-list.ts +121 -5
- package/src/data-structures/queue/deque.ts +95 -67
- package/src/data-structures/queue/queue.ts +90 -34
- package/src/data-structures/stack/stack.ts +58 -40
- package/src/data-structures/trie/trie.ts +109 -47
- package/src/interfaces/binary-tree.ts +2 -0
package/README.md
CHANGED
|
@@ -94,55 +94,115 @@ for (let i = 0; i < magnitude; i++) {
|
|
|
94
94
|
|
|
95
95
|
[//]: # (No deletion!!! Start of Example Replace Section)
|
|
96
96
|
|
|
97
|
-
###
|
|
97
|
+
### basic Queue creation and push operation
|
|
98
98
|
```typescript
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
const queue = new Queue<number>();
|
|
99
|
+
// Create a simple Queue with initial values
|
|
100
|
+
const queue = new Queue([1, 2, 3, 4, 5]);
|
|
102
101
|
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
// Verify the queue maintains insertion order
|
|
103
|
+
console.log([...queue]); // [1, 2, 3, 4, 5];
|
|
105
104
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
// Check length
|
|
106
|
+
console.log(queue.length); // 5;
|
|
107
|
+
```
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
### Queue shift and peek operations
|
|
110
|
+
```typescript
|
|
111
|
+
const queue = new Queue<number>([10, 20, 30, 40]);
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
// Peek at the front element without removing it
|
|
114
|
+
console.log(queue.first); // 10;
|
|
115
|
+
|
|
116
|
+
// Remove and get the first element (FIFO)
|
|
117
|
+
const first = queue.shift();
|
|
118
|
+
console.log(first); // 10;
|
|
119
|
+
|
|
120
|
+
// Verify remaining elements and length decreased
|
|
121
|
+
console.log([...queue]); // [20, 30, 40];
|
|
122
|
+
console.log(queue.length); // 3;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Queue for...of iteration and isEmpty check
|
|
126
|
+
```typescript
|
|
127
|
+
const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
const elements: string[] = [];
|
|
130
|
+
for (const item of queue) {
|
|
131
|
+
elements.push(item);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Verify all elements are iterated in order
|
|
135
|
+
console.log(elements); // ['A', 'B', 'C', 'D'];
|
|
136
|
+
|
|
137
|
+
// Process all elements
|
|
138
|
+
while (queue.length > 0) {
|
|
139
|
+
queue.shift();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
console.log(queue.length); // 0;
|
|
120
143
|
```
|
|
121
144
|
|
|
122
|
-
###
|
|
145
|
+
### Queue as message broker for event processing
|
|
123
146
|
```typescript
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
147
|
+
interface Message {
|
|
148
|
+
id: string;
|
|
149
|
+
type: 'email' | 'sms' | 'push';
|
|
150
|
+
recipient: string;
|
|
151
|
+
content: string;
|
|
152
|
+
timestamp: Date;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Create a message queue for real-time event processing
|
|
156
|
+
const messageQueue = new Queue<Message>([
|
|
157
|
+
{
|
|
158
|
+
id: 'msg-001',
|
|
159
|
+
type: 'email',
|
|
160
|
+
recipient: 'user@example.com',
|
|
161
|
+
content: 'Welcome!',
|
|
162
|
+
timestamp: new Date()
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: 'msg-002',
|
|
166
|
+
type: 'sms',
|
|
167
|
+
recipient: '+1234567890',
|
|
168
|
+
content: 'OTP: 123456',
|
|
169
|
+
timestamp: new Date()
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: 'msg-003',
|
|
173
|
+
type: 'push',
|
|
174
|
+
recipient: 'device-token-xyz',
|
|
175
|
+
content: 'New notification',
|
|
176
|
+
timestamp: new Date()
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: 'msg-004',
|
|
180
|
+
type: 'email',
|
|
181
|
+
recipient: 'admin@example.com',
|
|
182
|
+
content: 'Daily report',
|
|
183
|
+
timestamp: new Date()
|
|
184
|
+
}
|
|
185
|
+
]);
|
|
186
|
+
|
|
187
|
+
// Process messages in FIFO order (first message first)
|
|
188
|
+
const processedMessages: string[] = [];
|
|
189
|
+
while (messageQueue.length > 0) {
|
|
190
|
+
const message = messageQueue.shift();
|
|
191
|
+
if (message) {
|
|
192
|
+
processedMessages.push(`${message.type}:${message.recipient}`);
|
|
142
193
|
}
|
|
143
194
|
}
|
|
144
195
|
|
|
145
|
-
|
|
196
|
+
// Verify messages were processed in order
|
|
197
|
+
console.log(processedMessages); // [
|
|
198
|
+
// 'email:user@example.com',
|
|
199
|
+
// 'sms:+1234567890',
|
|
200
|
+
// 'push:device-token-xyz',
|
|
201
|
+
// 'email:admin@example.com'
|
|
202
|
+
// ];
|
|
203
|
+
|
|
204
|
+
// Queue should be empty after processing all messages
|
|
205
|
+
console.log(messageQueue.length); // 0;
|
|
146
206
|
```
|
|
147
207
|
|
|
148
208
|
[//]: # (No deletion!!! End of Example Replace Section)
|