Skip to content

Commit

Permalink
Use wildcard matches to avoid match on #leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
s-and-witch committed Oct 16, 2024
1 parent 86b876f commit bdca721
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/PersistentOrderedMap.mo
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,13 @@ module {
public func map<K, V1, V2>(rbMap : Map<K, V1>, f : (K, V1) -> V2) : Map<K, V2> {
func mapRec(m : Map<K, V1>) : Map<K, V2> {
switch m {
case (#leaf) { #leaf };
case (#red(l, xy, r)) {
#red(mapRec l, (xy.0, f xy), mapRec r)
};
case (#black(l, xy, r)) {
#black(mapRec l, (xy.0, f xy), mapRec r)
};
case _ { #leaf };
}
};
mapRec(rbMap)
Expand Down Expand Up @@ -507,7 +507,7 @@ module {
case (#black(l, _, r)) {
size(l) + size(r) + 1
};
case (#leaf) { 0 }
case _ { 0 }
}
};

Expand Down Expand Up @@ -545,7 +545,6 @@ module {
) : Accum
{
switch (rbMap) {
case (#leaf) { base };
case (#red(l, (k, v), r)) {
let left = foldLeft(l, base, combine);
let middle = combine(k, v, left);
Expand All @@ -555,7 +554,8 @@ module {
let left = foldLeft(l, base, combine);
let middle = combine(k, v, left);
foldLeft(r, middle, combine)
}
};
case _ { base };
}
};

Expand Down Expand Up @@ -593,7 +593,6 @@ module {
) : Accum
{
switch (rbMap) {
case (#leaf) { base };
case (#red(l, (k, v), r)) {
let right = foldRight(r, base, combine);
let middle = combine(k, v, right);
Expand All @@ -603,7 +602,8 @@ module {
let right = foldRight(r, base, combine);
let middle = combine(k, v, right);
foldRight(l, middle, combine)
}
};
case _ { base };
}
};

Expand Down Expand Up @@ -647,7 +647,7 @@ module {
case (#greater) { get(r, compare, x) }
}
};
case (#leaf) { null }
case _ { null }
}
};

Expand Down Expand Up @@ -742,7 +742,7 @@ module {
}
}
};
case (#leaf) {
case _ {
#red(#leaf, (key,val), #leaf)
}
};
Expand Down Expand Up @@ -909,7 +909,7 @@ module {
case (#black(left, xy, right)) {
delNode(left, xy, right)
};
case (#leaf) {
case _ {
tree
}
};
Expand Down

0 comments on commit bdca721

Please sign in to comment.