Author:
Hash:
Timestamp:
+28 -0 +/-1 browse
Kevin Schoon [me@kevinschoon.com]
201df742d798b07595ba6a0e6e729aa17f3a9eaf
Tue, 22 Apr 2025 13:14:40 +0000 (1 month ago)
1 | diff --git a/src/tree.rs b/src/tree.rs |
2 | index 3181ccc..debcb74 100644 |
3 | --- a/src/tree.rs |
4 | +++ b/src/tree.rs |
5 | @@ -8,6 +8,32 @@ pub struct Node { |
6 | pub children: Vec<Node>, |
7 | } |
8 | |
9 | + impl Eq for Node {} |
10 | + |
11 | + impl PartialEq for Node { |
12 | + fn eq(&self, other: &Self) -> bool { |
13 | + self.name.eq(&other.name) |
14 | + } |
15 | + } |
16 | + |
17 | + impl PartialOrd for Node { |
18 | + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { |
19 | + Some(self.name.cmp(&other.name)) |
20 | + } |
21 | + } |
22 | + |
23 | + impl Ord for Node { |
24 | + fn cmp(&self, other: &Self) -> std::cmp::Ordering { |
25 | + self.name.cmp(&other.name) |
26 | + } |
27 | + } |
28 | + |
29 | + impl Node { |
30 | + pub fn sort(&mut self) { |
31 | + self.children.sort(); |
32 | + } |
33 | + } |
34 | + |
35 | /// Builder creates a new root node with all decending paths within |
36 | pub struct Builder { |
37 | separator: String, |
38 | @@ -66,6 +92,8 @@ impl Builder { |
39 | |
40 | if !keys.is_empty() { |
41 | Builder::reduce(keys.as_slice(), root) |
42 | + } else { |
43 | + root.sort(); |
44 | } |
45 | } |
46 |