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;...@@ -11,6 +11,7 @@ const Red = Color.Red;
11const Black = Color.Black;11const Black = Color.Black;
1212
13const ReplaceError = error{NotEqual};13const ReplaceError = error{NotEqual};
14const SortError = error{NotUnique}; // The new comparison function results in duplicates.
1415
15/// Insert this into your struct that you want to add to a red-black tree.16/// Insert this into your struct that you want to add to a red-black tree.
16/// Do not use a pointer. Turn the *rb.Node results of the functions in rb17/// Do not use a pointer. Turn the *rb.Node results of the functions in rb
...@@ -135,7 +136,7 @@ pub const Tree = struct {...@@ -135,7 +136,7 @@ pub const Tree = struct {
135 compareFn: fn (*Node, *Node, *Tree) Order,136 compareFn: fn (*Node, *Node, *Tree) Order,
136137
137 /// Re-sorts a tree with a new compare function138 /// 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 {
139 var newTree = Tree.init(newCompareFn);140 var newTree = Tree.init(newCompareFn);
140 var node: *Node = undefined;141 var node: *Node = undefined;
141 while (true) {142 while (true) {