Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use fixed queue #555

Merged
merged 49 commits into from
May 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3091f34
Add nodejs fixed_queue implementation
JaoodxD May 4, 2024
141fdb6
Use Task and TaskQueue interfaces in fixed-queue
JaoodxD May 4, 2024
bb347a3
Implement removal from queue
JaoodxD May 4, 2024
6ecc454
Add basic tests for fixed-queue
JaoodxD May 4, 2024
532a393
Add simple benchmark with fixed-queue as custom queue
JaoodxD May 4, 2024
5d6aaa6
Replace return with assertion to match original queue behavior
JaoodxD May 5, 2024
bda430c
Improve size calculation algorithm
JaoodxD May 5, 2024
d248503
Mention original fixed_queue implementation
JaoodxD May 5, 2024
811a952
Merge branch 'current' into use-fixed-queue
metcoder95 May 6, 2024
a6cab0a
Use old-style underscore private fields for best perforamnce with cur…
JaoodxD May 8, 2024
a291328
Expose current default taskQueue
JaoodxD May 8, 2024
8501041
Add benchmarks
JaoodxD May 8, 2024
90d46d0
Merge branch 'use-fixed-queue' of github.com:JaoodxD/piscina into use…
JaoodxD May 8, 2024
4475221
Merge branch 'current' into use-fixed-queue
metcoder95 May 9, 2024
b616d43
Expose `ArrayTaskQueue` and `FixedQueue` for named imports in commonjs
JaoodxD May 9, 2024
aa6e6e1
Use exposed queues
JaoodxD May 9, 2024
107d4a2
Optimize queue size accounting
JaoodxD May 9, 2024
9fa2bb4
Mention FixedQueue in docs
JaoodxD May 9, 2024
c0707d8
Add test case for issue with FixedQueue
JaoodxD May 9, 2024
4c00de3
Update tests for FixedQueue
JaoodxD May 14, 2024
5c575eb
Fix bug with removing elements from queue
JaoodxD May 14, 2024
aefcc95
Remove unused capacity property
JaoodxD May 14, 2024
bd776c5
Fix emptying head with remove lead to wrong isEmpty behavior
JaoodxD May 14, 2024
d5f2f77
Add nodejs fixed_queue implementation
JaoodxD May 4, 2024
7a5ab6b
Use Task and TaskQueue interfaces in fixed-queue
JaoodxD May 4, 2024
55dcebd
Implement removal from queue
JaoodxD May 4, 2024
0678138
Add basic tests for fixed-queue
JaoodxD May 4, 2024
f4704ce
Add simple benchmark with fixed-queue as custom queue
JaoodxD May 4, 2024
31953de
Replace return with assertion to match original queue behavior
JaoodxD May 5, 2024
ab95b36
Improve size calculation algorithm
JaoodxD May 5, 2024
897b620
Mention original fixed_queue implementation
JaoodxD May 5, 2024
6d0c137
Use old-style underscore private fields for best perforamnce with cur…
JaoodxD May 8, 2024
737cb5c
Expose current default taskQueue
JaoodxD May 8, 2024
80b41f9
Add benchmarks
JaoodxD May 8, 2024
1117bc4
Expose `ArrayTaskQueue` and `FixedQueue` for named imports in commonjs
JaoodxD May 9, 2024
dc69b13
Use exposed queues
JaoodxD May 9, 2024
aa78e18
Optimize queue size accounting
JaoodxD May 9, 2024
906df6e
Mention FixedQueue in docs
JaoodxD May 9, 2024
fc2e1ea
Add test case for issue with FixedQueue
JaoodxD May 9, 2024
dd8b9bb
Update tests for FixedQueue
JaoodxD May 14, 2024
395e630
Fix bug with removing elements from queue
JaoodxD May 14, 2024
ab45024
Remove unused capacity property
JaoodxD May 14, 2024
51b7df6
Fix emptying head with remove lead to wrong isEmpty behavior
JaoodxD May 14, 2024
8e9750c
Merge branch 'use-fixed-queue' of github.com:JaoodxD/piscina into use…
JaoodxD May 14, 2024
57988f4
Update README.md
JaoodxD May 14, 2024
a75fd76
Update README.md
JaoodxD May 14, 2024
fa84b3c
Update README.md
JaoodxD May 14, 2024
452feb2
Split benchmark scripts into queuetask only related and piscina related
JaoodxD May 14, 2024
f8d8f4f
Add tests of integration fixed-queue with Piscina
JaoodxD May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix bug with removing elements from queue
  • Loading branch information
JaoodxD committed May 14, 2024
commit 395e630e2f9791fdc04fbc05735694ff251c06a5
32 changes: 27 additions & 5 deletions src/fixed-queue.ts
metcoder95 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,36 @@ class FixedCircularBuffer {
top: number
list: Array<Task | undefined>
next: FixedCircularBuffer | null
_size: number

constructor () {
this.bottom = 0;
this.top = 0;
this.list = new Array(kSize);
this.next = null;
this._size = 0;
}

isEmpty () {
return this.top === this.bottom;
return this.top === this.bottom && this._size === 0;
}

isFull () {
return ((this.top + 1) & kMask) === this.bottom;
return this.top === this.bottom && this._size === kSize;
}

push (data:Task) {
this.list[this.top] = data;
this.top = (this.top + 1) & kMask;
this._size++;
}

shift () {
const nextItem = this.list[this.bottom];
if (nextItem === undefined) { return null; }
this.list[this.bottom] = undefined;
this.bottom = (this.bottom + 1) & kMask;
this._size--;
return nextItem;
}

Expand All @@ -99,10 +103,17 @@ class FixedCircularBuffer {
while (true) {
const next = (curr + 1) & kMask;
this.list[curr] = this.list[next];
if (this.list[curr] === undefined) break;
if (curr === indexToRemove) break;
if (this.list[curr] === undefined) {
break;
}
if (next === indexToRemove) {
this.list[curr] = undefined;
break;
}
curr = next;
}
this.top = (this.top - 1) & kMask;
this._size--;
}

get capacity () {
Expand Down Expand Up @@ -146,16 +157,27 @@ export default class FixedQueue implements TaskQueue {
}

remove (task: Task) {
let buffer = this.head;
let prev = null;
let buffer = this.tail;
while (true) {
if (buffer.list.includes(task)) {
buffer.remove(task);
this._size--;
break;
}
if (buffer.next === null) break;
prev = buffer;
buffer = buffer.next;
}
if (buffer.isEmpty()) {
if (prev !== null) {
prev.next = buffer.next;
} else {
if (buffer.next) {
this.tail = buffer.next;
}
}
}
}

get size () {
Expand Down