| 2740 | |
| 2741 | constructor(buffer: ReplayBuffer<A>) { |
| 2742 | this.buffer = buffer |
| 2743 | this.remaining = buffer.size |
| 2744 | this.slideIndex = buffer.index |
| 2745 | this.values = new Array(this.remaining) |
| 2746 | let node = buffer.head |
| 2747 | for (let i = 0; i < this.remaining; i++) { |
| 2748 | this.values[i] = node.value as A |
| 2749 | this.newestIndex = node.index |
| 2750 | node = node.next! |
| 2751 | } |
| 2752 | } |
| 2753 | close(): void { |
| 2754 | this.values.length = 0 |
| 2755 | this.remaining = 0 |
| 2756 | } |
| 2757 | sync(): void { |
| 2758 | const slides = this.buffer.index - this.slideIndex |
| 2759 | if (slides === 0 || this.remaining === 0) { |
| 2760 | return |
| 2761 | } |
| 2762 | const count = Math.min(slides, this.buffer.capacity) |
| 2763 | const start = this.buffer.index - count |
| 2764 | for (let i = 0; i < count; i++) { |
| 2765 | const entry = this.buffer.slideValues[(start + i) % this.buffer.capacity] |
| 2766 | if (entry.index > this.newestIndex) { |
| 2767 | this.index = (this.index + 1) % this.values.length |
| 2768 | this.values[(this.index + this.remaining - 1) % this.values.length] = entry.value |
| 2769 | this.newestIndex = entry.index |
| 2770 | } |
| 2771 | } |
| 2772 | this.slideIndex = this.buffer.index |
| 2773 | } |
| 2774 | take(): A | undefined { |
| 2775 | if (this.remaining === 0) { |
| 2776 | return undefined |
| 2777 | } |
| 2778 | this.sync() |
| 2779 | const value = this.values[this.index] |
| 2780 | this.values[this.index] = AbsentValue as unknown as A |
| 2781 | this.index = (this.index + 1) % this.values.length |
| 2782 | this.remaining-- |
| 2783 | if (this.remaining === 0) { |
| 2784 | this.close() |
| 2785 | } |
| 2786 | return value as A |
| 2787 | } |
| 2788 | takeN(n: number): Array<A> { |
| 2789 | const len = Math.min(n, this.remaining) |
| 2790 | const items = new Array(len) |
| 2791 | for (let i = 0; i < len; i++) { |
| 2792 | items[i] = this.take()! |
| 2793 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…