1//ported from Emulator/Utilities/RingBuffer.h and speed optimized for Javascript mithrendal 2class RingBuffer { 3 constructor(capacity) { 4 this.capacity = capacity+1; 5 this.capacity_usable = capacity; 6 this.r = 0; 7 this.w = 0; 8 this.elements = new ArrayBuffer(this.capacity); 9 } 10 11 clear(){ 12 this.r = 0; 13 this.w = 0; 14 for (let i = 0; i < this.capacity; i++) { this.elements[i] = null; } 15 } 16 17 align(offset) { 18 this.w = (this.r + offset) % this.capacity; 19 } 20 21 count() { 22 return (this.capacity + this.w - this.r) % this.capacity; 23 } 24 free() { return this.capacity - this.count() - 1; } 25 fillLevel() { return this.count() / this.capacity; } 26 isEmpty() { return this.r == this.w; } 27 isFull() { return this.count() == this.capacity - 1; } 28 29 begin() { return this.r; } 30 end() { return this.w; } 31 next(i) { return i < this.capacity - 1 ? i + 1 : 0; } 32 prev(i) { return i > 0 ? i - 1 : this.capacity - 1; } 33 34 read() 35 { 36// console.assert(!this.isEmpty(), "Ringbuffer.read() -> !isEmpty()"); 37 38 let oldr = this.r; 39 //this.r = this.next(this.r); 40 this.r = this.r < this.capacity_usable ? this.r + 1 : 0; 41 return this.elements[oldr]; 42 } 43 44 write(element) 45 { 46// console.log("write "+element) 47// console.assert(!this.isFull(), "Ringbuffer.write() -> !isFull()"); 48 49 this.elements[this.w] = element; 50 //this.w = this.next(this.w); 51 this.w = this.w < this.capacity_usable ? this.w + 1 : 0; 52 } 53 54 skip() 55 { 56 this.r = this.next(this.r); 57 } 58 59 skip(n) 60 { 61 this.r = (this.r + n) % this.capacity; 62 } 63 64 current(offset) 65 { 66 return this.elements[(this.r + offset) % this.capacity]; 67 } 68} 69
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.