Transpiled version (70L) is out of date.
1 | persistable sclass SynchronizedCircularBuffer<A> { |
2 | A[] buffer; |
3 | long base; // elements dropped due to overcapacity |
4 | int size; // elements actually contained |
5 | |
6 | *(int capacity) { |
7 | buffer = (A[]) new O[capacity]; |
8 | } |
9 | |
10 | synchronized void add(A a) { |
11 | if (size == buffer.length) { |
12 | --size; |
13 | ++base; |
14 | } |
15 | buffer[(int) ((base+size) % buffer.length)] = a; |
16 | ++size; |
17 | } |
18 | |
19 | synchronized A get(long pos) { |
20 | if (pos < base || pos >= base+size) null; |
21 | ret buffer[(int) (pos % buffer.length)]; |
22 | } |
23 | |
24 | synchronized int size() { |
25 | ret size; |
26 | } |
27 | |
28 | synchronized int capacity() { |
29 | ret buffer.length; |
30 | } |
31 | |
32 | synchronized bool isFull() { |
33 | ret size() == capacity(); |
34 | } |
35 | |
36 | synchronized long getBase() { |
37 | ret base; |
38 | } |
39 | } |
Began life as a copy of #1026626
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036465 |
Snippet name: | SynchronizedCircularBuffer - duplicate of SimpleCircularBuffer |
Eternal ID of this version: | #1036465/5 |
Text MD5: | 19c62f0bdc3a2be929c53801af2cbe85 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-12-16 05:15:41 |
Source code size: | 797 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 147 / 202 |
Version history: | 4 change(s) |
Referenced in: | [show references] |