socket-function 0.44.0 → 0.45.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/misc.ts +12 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
package/src/misc.ts CHANGED
@@ -298,20 +298,29 @@ export class QueueLimited<T> {
298
298
  private index = 0;
299
299
  constructor(private readonly maxCount: number) { }
300
300
 
301
- public push(item: T) {
301
+ public push(item: T): void {
302
302
  this.index = (this.index + 1) % this.maxCount;
303
303
  this.items[this.index] = item;
304
304
  }
305
305
 
306
- public getAllUnordered() {
306
+ public getAllUnordered(): T[] {
307
307
  return this.items;
308
308
  }
309
- public reset() {
309
+ public reset(): void {
310
310
  this.items = [];
311
311
  this.index = 0;
312
312
  }
313
+ public getOldest(): T | undefined {
314
+ if (this.items.length === 0) return undefined;
315
+ let index = this.index - 1;
316
+ if (index === -1) {
317
+ index += this.maxCount;
318
+ }
319
+ return this.items[index];
320
+ }
313
321
  }
314
322
 
323
+
315
324
  export function binarySearchBasic<T, V>(array: T[], getVal: (val: T) => V, searchValue: V): number {
316
325
  return binarySearchIndex(array.length, i => compare(getVal(array[i]), searchValue));
317
326
  }