Comparing version 0.0.785 to 0.0.786
@@ -648,3 +648,4 @@ import { Cache } from './cache'; | ||
lru.get(Number.MIN_SAFE_INTEGER + i - 1); | ||
lru.get(Number.MIN_SAFE_INTEGER + i); | ||
trc.get(Number.MIN_SAFE_INTEGER + i); | ||
dwc.get(Number.MIN_SAFE_INTEGER + i + 1); | ||
@@ -651,0 +652,0 @@ if (i + 1 !== capacity) continue; |
{ | ||
"name": "spica", | ||
"version": "0.0.785", | ||
"version": "0.0.786", | ||
"description": "Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.", | ||
@@ -5,0 +5,0 @@ "private": false, |
47
queue.ts
@@ -12,7 +12,6 @@ import { Heap } from './heap'; | ||
private count = 0; | ||
private irregular = 0; | ||
public get length(): number { | ||
return this.count === 0 | ||
return this.head === this.tail | ||
? this.head.length | ||
: this.head.length + this.tail.length + size * (this.count - 2) + (this.irregular || size); | ||
: this.head.length + this.count + this.tail.length; | ||
} | ||
@@ -38,6 +37,5 @@ // Faster than queue.length > 0. | ||
assert(this.tail.isEmpty()); | ||
++this.count; | ||
if (tail.size !== size && tail !== this.head) { | ||
this.irregular = tail.size; | ||
assert(this.irregular === initsize); | ||
if (this.head !== tail) { | ||
assert(this.head.next !== this.tail); | ||
this.count += tail.size; | ||
} | ||
@@ -47,3 +45,2 @@ } | ||
} | ||
private prev?: FixedQueue<T> = undefined; | ||
public pop(): T | undefined { | ||
@@ -53,16 +50,17 @@ const head = this.head; | ||
if (head.isEmpty() && !head.next.isEmpty()) { | ||
if (this.prev?.isEmpty()) { | ||
this.head = this.prev.next = head.next; | ||
head.next = head; | ||
const tail = this.tail; | ||
// 空になるごとの削除と再作成を避ける | ||
if (tail.next !== head) { | ||
assert(tail.next.next === head); | ||
// 初期サイズの方を消す | ||
tail.next.next = tail.next; | ||
tail.next = head; | ||
assert(head.size === size); | ||
} | ||
else { | ||
this.head = head.next; | ||
this.prev = head; | ||
assert(this.tail.next.isEmpty()); | ||
this.head = head.next; | ||
if (this.head !== tail) { | ||
assert(this.head !== this.tail); | ||
this.count -= head.next.size; | ||
} | ||
assert(this.prev.next === this.head); | ||
--this.count; | ||
if (this.head.size === this.irregular) { | ||
assert(this.irregular === initsize); | ||
this.irregular = 0; | ||
} | ||
} | ||
@@ -74,3 +72,2 @@ return value; | ||
this.count = 0; | ||
this.irregular = 0; | ||
} | ||
@@ -110,6 +107,6 @@ public *[Symbol.iterator](): Iterator<T, undefined, undefined> { | ||
} | ||
public peek(index: 0 | -1 = 0): T | undefined { | ||
return index === 0 | ||
? this.array[this.head] | ||
: this.array[this.tail - 1 & this.mask]; | ||
public peek(index: number = 0): T | undefined { | ||
return index >= 0 | ||
? this.array[this.head + index & this.mask] | ||
: this.array[this.tail + index & this.mask]; | ||
} | ||
@@ -116,0 +113,0 @@ public push(value: T): void { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
842218
27491