Add wl_list implementation

This commit is contained in:
Isaac Freund
2020-10-05 13:29:23 +02:00
parent ee5ffdbba8
commit 3340f8831f
+43
View File
@@ -23,6 +23,49 @@ pub const Array = extern struct {
data: *c_void,
};
pub const List = extern struct {
prev: *List,
next: *List,
pub fn init(list: *List) void {
list.* = .{ .prev = list, .next = list };
}
pub fn insert(list: *List, elm: *List) void {
elm.prev = list;
elm.next = list.next;
list.next = elm;
elm.next.prev = elm;
}
pub fn remove(elm: *elm) void {
elm.prev.next = elm.next;
elm.next.prev = elm.prev;
elm = undefined;
}
pub fn length(list: *const List) usize {
var count: usize = 0;
var current = list.next;
while (current != list) : (current = current.next) {
count += 1;
}
return count;
}
pub fn empty(list: *const List) bool {
return list.next == list;
}
pub fn insertList(list: *List, other: *List) void {
if (other.empty()) return;
other.next.prev = list;
other.prev.next = list.next;
list.next.prev = other.prev;
list.next = other.next;
}
};
pub const Fixed = extern enum(i32) {
_,