Skip to content

Commit cced25c

Browse files
authored
Merge pull request #23 from datastructures-js/fix_readme
update
2 parents 15e2264 + 7e32de9 commit cced25c

File tree

4 files changed

+33
-129
lines changed

4 files changed

+33
-129
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
## [4.1.4] - 2022-05-15
9+
### Fixed
10+
- README
11+
812
## [4.1.3] - 2021-06-20
913
### Fixed
1014
- index.d.ts

README.md

Lines changed: 24 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# @datastructures-js/queue
22

3-
[![build:?](https://travis-ci.org/datastructures-js/queue.svg?branch=master)](https://travis-ci.org/datastructures-js/queue)
43
[![npm](https://img.shields.io/npm/v/@datastructures-js/queue.svg)](https://www.npmjs.com/package/@datastructures-js/queue)
54
[![npm](https://img.shields.io/npm/dm/@datastructures-js/queue.svg)](https://www.npmjs.com/packages/@datastructures-js/queue) [![npm](https://img.shields.io/badge/node-%3E=%206.0-blue.svg)](https://www.npmjs.com/package/@datastructures-js/queue)
65

@@ -14,16 +13,16 @@ A performant queue implementation in javascript.
1413
* [import](#import)
1514
* [API](#api)
1615
* [constructor](#constructor)
17-
* [Queue.fromArray(elements)](#queuefromarrayelements)
18-
* [.enqueue(element)](#enqueueelement)
19-
* [.front()](#front)
20-
* [.back()](#back)
21-
* [.dequeue()](#dequeue)
22-
* [.isEmpty()](#isEmpty)
23-
* [.size()](#size)
24-
* [.clone()](#clone)
25-
* [.toArray()](#toarray)
26-
* [.clear()](#clear)
16+
* [Queue.fromArray](#queuefromarray)
17+
* [enqueue](#enqueue)
18+
* [front](#front)
19+
* [back](#back)
20+
* [dequeue](#dequeue)
21+
* [isEmpty](#isEmpty)
22+
* [size](#size)
23+
* [clone](#clone)
24+
* [toArray](#toarray)
25+
* [clear](#clear)
2726
* [Build](#build)
2827
* [License](#license)
2928

@@ -67,7 +66,7 @@ const queue = new Queue<number>();
6766
const queue = new Queue<number>([1, 2, 3]);
6867
```
6968

70-
### Queue.fromArray(elements)
69+
### Queue.fromArray
7170

7271
##### JS
7372
```js
@@ -92,142 +91,63 @@ const list = [10, 3, 8, 40, 1];
9291
const queue = Queue.fromArray<number>(list);
9392
```
9493

95-
### .enqueue(element)
94+
### enqueue
9695
adds an element at the back of the queue.
9796

98-
<table>
99-
<tr>
100-
<th align="center">params</th>
101-
<th align="center">return</th>
102-
<th align="center">runtime</th>
103-
</tr>
104-
<tr>
105-
<td align="center">element: T</td>
106-
<td align="center">Queue&lt;T&gt;</td>
107-
<td align="center">O(1)</td>
108-
</tr>
109-
</table>
110-
11197
```js
11298
queue.enqueue(10).enqueue(20);
11399
```
114100

115-
### .front()
101+
### front
116102
peeks on the front element of the queue.
117103

118-
<table>
119-
<tr>
120-
<th align="center">return</th>
121-
<th align="center">runtime</th>
122-
</tr>
123-
<tr>
124-
<td align="center">T</td>
125-
<td align="center">O(1)</td>
126-
</tr>
127-
</table>
128-
129104
```js
130105
console.log(queue.front()); // 10
131106
```
132107

133-
### .back()
108+
### back
134109
peeks on the back element in the queue.
135110

136-
<table>
137-
<tr>
138-
<th align="center">return</th>
139-
<th align="center">runtime</th>
140-
</tr>
141-
<tr>
142-
<td align="center">T</td>
143-
<td align="center">O(1)</td>
144-
</tr>
145-
</table>
146-
147111
```js
148112
console.log(queue.back()); // 20
149113
```
150114

151-
### .dequeue()
152-
dequeue the front element in the queue. It does not use *.shift()* to dequeue the element. Instead, it uses a pointer to get the front element and only remove elements when reaching half size of the queue.
153-
154-
<table>
155-
<tr>
156-
<th align="center">return</th>
157-
<th align="center">runtime</th>
158-
</tr>
159-
<tr>
160-
<td align="center">T</td>
161-
<td align="center">O(n*log(n))</td>
162-
</tr>
163-
</table>
115+
### dequeue
116+
dequeue the front element in the queue.
164117

165118
```js
166119
console.log(queue.dequeue()); // 10
167120
console.log(queue.front()); // 20
168121
```
169122

170-
Dequeuing all elements takes <i>O(n\*log(n))</i> instead of <i>O(n<sup>2</sup>)</i> when using shift().
123+
Dequeuing all elements takes <i>O(n\*log(n))</i> instead of <i>O(n<sup>2</sup>)</i> when using shift/unshift with arrays.
171124

172125
<b>benchmark:</b>
173126

174127
dequeuing 1 million elements in Node v12
175128

176129
<table>
177-
<tr><td>.dequeue()</td><td>.shift()</td></tr>
178-
<tr><td>~ 40 ms</td><td>~ 3 minutes</td></tr>
130+
<tr><td>dequeue</td><td>shift</td></tr>
131+
<tr><td>~40 ms</td><td>~3 minutes</td></tr>
179132
</table>
180133

181-
### .isEmpty()
134+
### isEmpty
182135
checks if the queue is empty.
183136

184-
<table>
185-
<tr>
186-
<th align="center">return</th>
187-
<th align="center">runtime</th>
188-
</tr>
189-
<tr>
190-
<td align="center">boolean</td>
191-
<td align="center">O(1)</td>
192-
</tr>
193-
</table>
194-
195137
```js
196138
console.log(queue.isEmpty()); // false
197139
```
198140

199-
### .size()
141+
### size
200142
returns the number of elements in the queue.
201143

202-
<table>
203-
<tr>
204-
<th align="center">return</th>
205-
<th align="center">runtime</th>
206-
</tr>
207-
<tr>
208-
<td align="center">number</td>
209-
<td align="center">O(1)</td>
210-
</tr>
211-
</table>
212-
213144
```js
214145
console.log(queue.size()); // 1
215146
```
216147

217-
### .clone()
148+
### clone
218149
creates a shallow copy of the queue.
219150

220-
<table>
221-
<tr>
222-
<th align="center">return</th>
223-
<th align="center">runtime</th>
224-
</tr>
225-
<tr>
226-
<td align="center">Queue&lt;T&gt;</td>
227-
<td align="center">O(n)</td>
228-
</tr>
229-
</table>
230-
231151
```js
232152
const queue = Queue.fromArray([{ id: 2 }, { id: 4 } , { id: 8 }]);
233153
const clone = queue.clone();
@@ -238,37 +158,17 @@ console.log(queue.front()); // { id: 2 }
238158
console.log(clone.front()); // { id: 4 }
239159
```
240160

241-
### .toArray()
161+
### toArray
242162
returns a copy of the remaining elements as an array.
243163

244-
<table>
245-
<tr>
246-
<th align="center">return</th>
247-
<th align="center">runtime</th>
248-
</tr>
249-
<tr>
250-
<td align="center">T[]</td>
251-
<td align="center">O(n)</td>
252-
</tr>
253-
</table>
254-
255164
```js
256165
queue.enqueue(4).enqueue(2);
257166
console.log(queue.toArray()); // [20, 4, 2]
258167
```
259168

260-
### .clear()
169+
### clear
261170
clears all elements from the queue.
262171

263-
<table>
264-
<tr>
265-
<th>runtime</th>
266-
</tr>
267-
<tr>
268-
<td>O(1)</td>
269-
</tr>
270-
</table>
271-
272172
```js
273173
queue.clear();
274174
queue.size(); // 0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@datastructures-js/queue",
3-
"version": "4.1.3",
3+
"version": "4.1.4",
44
"description": "a performant queue implementation in javascript",
55
"main": "index.js",
66
"scripts": {

src/queue.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Queue {
1717
/**
1818
* Adds an element at the back of the queue.
1919
* @public
20-
* @param {any} element
20+
* @param {number|string|object} element
2121
*/
2222
enqueue(element) {
2323
this._elements.push(element);
@@ -27,7 +27,7 @@ class Queue {
2727
/**
2828
* Dequeues the front element in the queue.
2929
* @public
30-
* @returns {any}
30+
* @returns {number|string|object}
3131
*/
3232
dequeue() {
3333
if (this.size() === 0) return null;
@@ -47,7 +47,7 @@ class Queue {
4747
/**
4848
* Returns the front element of the queue.
4949
* @public
50-
* @returns {any}
50+
* @returns {number|string|object}
5151
*/
5252
front() {
5353
return this.size() > 0 ? this._elements[this._offset] : null;
@@ -56,7 +56,7 @@ class Queue {
5656
/**
5757
* Returns the back element of the queue.
5858
* @public
59-
* @returns {any}
59+
* @returns {number|string|object}
6060
*/
6161
back() {
6262
return this.size() > 0 ? this._elements[this._elements.length - 1] : null;

0 commit comments

Comments
 (0)