socket-function 0.43.0 → 0.44.0
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/package.json +1 -1
- package/src/misc.ts +19 -0
package/package.json
CHANGED
package/src/misc.ts
CHANGED
|
@@ -293,6 +293,25 @@ export function sort<T>(arr: T[], sortKey: (obj: T) => unknown) {
|
|
|
293
293
|
return arr;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
+
export class QueueLimited<T> {
|
|
297
|
+
private items: T[] = [];
|
|
298
|
+
private index = 0;
|
|
299
|
+
constructor(private readonly maxCount: number) { }
|
|
300
|
+
|
|
301
|
+
public push(item: T) {
|
|
302
|
+
this.index = (this.index + 1) % this.maxCount;
|
|
303
|
+
this.items[this.index] = item;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
public getAllUnordered() {
|
|
307
|
+
return this.items;
|
|
308
|
+
}
|
|
309
|
+
public reset() {
|
|
310
|
+
this.items = [];
|
|
311
|
+
this.index = 0;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
296
315
|
export function binarySearchBasic<T, V>(array: T[], getVal: (val: T) => V, searchValue: V): number {
|
|
297
316
|
return binarySearchIndex(array.length, i => compare(getVal(array[i]), searchValue));
|
|
298
317
|
}
|