Zig utility library
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Document `RingBuffer` along with a minor change in it

IamPyu 208e9aac 50637e4b

+3 -1
+3 -1
src/RingBuffer.zig
··· 16 16 return Self{}; 17 17 } 18 18 19 + /// Append `item` to the ring buffer 19 20 pub fn append(self: *Self, item: T) Error!void { 20 21 if ((self.write_index + 1) % capacity == self.read_index) { 21 22 return Error.BufferFull; ··· 25 26 self.write_index = (self.write_index + 1) % capacity; 26 27 } 27 28 29 + /// Get a reference to the value being pointed by the read index 28 30 pub fn get(self: *Self) ?*T { 29 31 if (self.read_index == self.write_index) { 30 32 return null; 31 33 } 32 34 33 35 const val = &self.buffer[self.read_index]; 34 - self.read_index = (self.read_index + 1) % capacity; 35 36 return @constCast(val); 36 37 } 37 38 39 + /// Remove the value being pointed by the read index, returning the value 38 40 pub fn read(self: *Self) ?T { 39 41 if (self.read_index == self.write_index) { 40 42 return null;