authorgravatar for shawn@git.icuShawn Landden <shawn@git.icu> 2020-01-19 23:35:56+04:00
committergravatar for shawn@git.icuShawn Landden <shawn@git.icu> 2020-01-19 23:35:56+04:00
logad15a73240324fce93a659fbee9dab7be24dfbb0
treea77dc093e4758766d6bf4194cc5254656a8a6a71
parent4ab9678b9553d77bc0683ee69a8936524f6a7808

rb: type Tree.sort with SortError


1 files changed, 2 insertions(+), 1 deletions(-)

lib/std/rb.zig+2-1
......@@ -11,6 +11,7 @@ const Red = Color.Red;
1111const Black = Color.Black;
1212
1313const ReplaceError = error{NotEqual};
14const SortError = error{NotUnique}; // The new comparison function results in duplicates.
1415
1516/// Insert this into your struct that you want to add to a red-black tree.
1617/// Do not use a pointer. Turn the *rb.Node results of the functions in rb
......@@ -135,7 +136,7 @@ pub const Tree = struct {
135136 compareFn: fn (*Node, *Node, *Tree) Order,
136137
137138 /// Re-sorts a tree with a new compare function
138 pub fn sort(tree: *Tree, newCompareFn: fn (*Node, *Node, *Tree) Order) !void {
139 pub fn sort(tree: *Tree, newCompareFn: fn (*Node, *Node, *Tree) Order) SortError!void {
139140 var newTree = Tree.init(newCompareFn);
140141 var node: *Node = undefined;
141142 while (true) {