| ... | @@ -11,6 +11,7 @@ const Red = Color.Red; | ... | @@ -11,6 +11,7 @@ const Red = Color.Red; |
| 11 | const Black = Color.Black; | 11 | const Black = Color.Black; |
| 12 | | 12 | |
| 13 | const ReplaceError = error{NotEqual}; | 13 | const ReplaceError = error{NotEqual}; |
| | 14 | const SortError = error{NotUnique}; // The new comparison function results in duplicates. |
| 14 | | 15 | |
| 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 rb | 17 | /// 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, |
| 136 | | 137 | |
| 137 | /// Re-sorts a tree with a new compare function | 138 | /// 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) { |