feat(buffers): add buffer switcher

This commit is contained in:
CJ van den Berg 2025-01-21 22:29:39 +01:00
parent efb3ab42fd
commit 3f06f6b19c
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
4 changed files with 55 additions and 4 deletions

View file

@ -51,15 +51,15 @@ pub fn retire(_: *Self, buffer: *Buffer) void {
buffer.update_last_used_time();
}
pub fn list(self: *Self, allocator: std.mem.Allocator) error{OutOfMemory}![]*const Buffer {
var buffers: std.ArrayListUnmanaged([]*const Buffer) = .{};
pub fn list_most_recently_used(self: *Self, allocator: std.mem.Allocator) error{OutOfMemory}![]*Buffer {
var buffers: std.ArrayListUnmanaged(*Buffer) = .{};
var i = self.buffers.iterator();
while (i.next()) |kv|
(try buffers.addOne()).* = kv.value_ptr.*;
(try buffers.addOne(allocator)).* = kv.value_ptr.*;
std.mem.sort(*Buffer, buffers.items, {}, struct {
fn less_fn(_: void, lhs: *Buffer, rhs: *Buffer) bool {
return lhs.mtime > rhs.mtime;
return lhs.utime > rhs.utime;
}
}.less_fn);