mirror of
https://github.com/rdmsr/zag.git
synced 2026-11-02 08:08:21 +00:00
fix(rtl): use const in more places
This commit is contained in:
+4
-4
@@ -15,7 +15,7 @@ pub var nil: Node = .{
|
|||||||
|
|
||||||
/// Base struct for binary search trees.
|
/// Base struct for binary search trees.
|
||||||
/// This should be used as a field in other types that are based on binary search trees, such as red-black trees or AVL trees.
|
/// This should be used as a field in other types that are based on binary search trees, such as red-black trees or AVL trees.
|
||||||
pub fn BST(comptime cmp: fn (*Node, *Node) std.math.Order) type {
|
pub fn BST(comptime cmp: fn (*const Node, *const Node) std.math.Order) type {
|
||||||
return struct {
|
return struct {
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
@@ -153,9 +153,9 @@ const MyNode = struct {
|
|||||||
value: u32,
|
value: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn node_cmp(a: *Node, b: *Node) std.math.Order {
|
fn node_cmp(a: *const Node, b: *const Node) std.math.Order {
|
||||||
const a_node: *MyNode = @fieldParentPtr("node", a);
|
const a_node: *const MyNode = @fieldParentPtr("node", a);
|
||||||
const b_node: *MyNode = @fieldParentPtr("node", b);
|
const b_node: *const MyNode = @fieldParentPtr("node", b);
|
||||||
if (a_node.value < b_node.value) return .lt;
|
if (a_node.value < b_node.value) return .lt;
|
||||||
if (a_node.value > b_node.value) return .gt;
|
if (a_node.value > b_node.value) return .gt;
|
||||||
return .eq;
|
return .eq;
|
||||||
|
|||||||
+4
-4
@@ -14,7 +14,7 @@ fn set_color(node: *bst.Node, color: u2) void {
|
|||||||
node.parent.set_tag(color);
|
node.parent.set_tag(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn RBTree(comptime cmp: fn (*bst.Node, *bst.Node) std.math.Order) type {
|
pub fn RBTree(comptime cmp: fn (*const bst.Node, *const bst.Node) std.math.Order) type {
|
||||||
return struct {
|
return struct {
|
||||||
tree: bst.BST(cmp),
|
tree: bst.BST(cmp),
|
||||||
|
|
||||||
@@ -273,9 +273,9 @@ const TestNode = struct {
|
|||||||
value: i32,
|
value: i32,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn cmp_test_node(a: *bst.Node, b: *bst.Node) std.math.Order {
|
fn cmp_test_node(a: *const bst.Node, b: *const bst.Node) std.math.Order {
|
||||||
const a_node: *TestNode = @fieldParentPtr("node", a);
|
const a_node: *const TestNode = @fieldParentPtr("node", a);
|
||||||
const b_node: *TestNode = @fieldParentPtr("node", b);
|
const b_node: *const TestNode = @fieldParentPtr("node", b);
|
||||||
|
|
||||||
if (a_node.value < b_node.value) return .lt;
|
if (a_node.value < b_node.value) return .lt;
|
||||||
if (a_node.value > b_node.value) return .gt;
|
if (a_node.value > b_node.value) return .gt;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub fn TaggedPtr(comptime T: type) type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the pointer with the tag bits masked out.
|
/// Return the pointer with the tag bits masked out.
|
||||||
pub fn get_ptr(self: *Self) *T {
|
pub fn get_ptr(self: *const Self) *T {
|
||||||
return @ptrFromInt(self.value & ~mask);
|
return @ptrFromInt(self.value & ~mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ pub fn TaggedPtr(comptime T: type) type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the tag bits.
|
/// Return the tag bits.
|
||||||
pub fn get_tag(self: *Self) u2 {
|
pub fn get_tag(self: *const Self) u2 {
|
||||||
return @as(u2, @truncate(self.value & mask));
|
return @as(u2, @truncate(self.value & mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user