@@ -90,6 +90,7 @@ _with array of numbers_
9090const p = new PriorityQueue (function (a , b ) {
9191 return a > b ;
9292});
93+
9394p .push (2 );
9495p .push (7 );
9596p .push (4 );
@@ -128,7 +129,7 @@ p.push({ text: 'f', value: 1 });
128129
129130## API
130131
131- ### push(value)
132+ ### push(value: T )
132133
133134Add elements to queue
134135
@@ -141,7 +142,7 @@ p.push(3); // adding "3" to queue
141142// The queue: [3, 1, 2]
142143```
143144
144- ### pop
145+ ### pop()
145146
146147Extract the largest or smallest element from the queue
147148
@@ -156,7 +157,7 @@ const elmenet = p.pop(); // Output: 3
156157
157158The queue looks like this ` [2, 1] `
158159
159- ### top
160+ ### top()
160161
161162Peek the element (get the largest or smallest element without removing it from queue)
162163
@@ -171,7 +172,7 @@ const elmenet = p.pop(); // Output: 3
171172// The queue is remained the same
172173```
173174
174- ### size
175+ ### size()
175176
176177Get the size of the queue
177178
@@ -185,14 +186,14 @@ p.push(4); // adding "4" to queue
185186const length = p .size (); // Output: 4
186187```
187188
188- ### empty
189+ ### empty()
189190
190191Check whether the queue is empty or not.
191192
192193- true: if the queue is empty
193194- false: if the queue has data
194195
195- ### toArray
196+ ### toArray()
196197
197198Extract queue to array
198199
@@ -205,6 +206,54 @@ p.push(3); // adding "3" to queue
205206const array = p .toArray (); // Output: [3, 1, 2]
206207```
207208
209+ ### clear()
210+
211+ Removes all of the elements from this priority queue.
212+
213+ ### contains(value: T, comparator?: (item: T) => boolean)
214+
215+ Returns true if this queue contains the specified element.
216+
217+ - true: if the element exists in queue
218+ - false: if the element does not exist in queue
219+
220+ _ with array of numbers_
221+
222+ ``` ts
223+ const p = new PriorityQueue ();
224+ p .push (2 );
225+ p .push (7 );
226+ p .push (4 );
227+ p .push (1 );
228+ p .push (8 );
229+ p .push (1 );
230+
231+ p .contains (8 ); // true
232+ p .contains (100 ); // false
233+ ```
234+
235+ _ with array of objects_
236+
237+ ``` ts
238+ const p = new PriorityQueue (function (a , b ) {
239+ return a .value > b .value ;
240+ });
241+
242+ p .push ({ text: ' a' , value: 2 });
243+ p .push ({ text: ' b' , value: 7 });
244+ p .push ({ text: ' c' , value: 4 });
245+ p .push ({ text: ' d' , value: 1 });
246+ p .push ({ text: ' e' , value: 8 });
247+ p .push ({ text: ' f' , value: 1 });
248+
249+ function callback(item : any ) {
250+ return item .value === element .value ;
251+ }
252+
253+ p .contains (8 , callback ); // true
254+ p .contains (100 , callback ); // false
255+ ```
256+
208257## Running time
209258
210259You can check the performance of the package here: [ https://jsperf.com/p-queue-ts ] ( https://jsperf.com/p-queue-ts )
0 commit comments