We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c541d15 commit 7f13d0fCopy full SHA for 7f13d0f
src/RootedTrees.jl
@@ -306,6 +306,13 @@ one with lexicographically biggest level sequence.
306
See also [`canonical_representation`](@ref).
307
"""
308
function canonical_representation!(t::RootedTree, buffer=similar(t.level_sequence))
309
+ # Since we use a recursive implementation, it is useful to exit early for
310
+ # small trees. If there are at most 3 vertices in a valid rooted tree, its
311
+ # level sequence must already be in canonical representation.
312
+ if order(t) <= 3
313
+ return RootedTree(t.level_sequence, true)
314
+ end
315
+
316
# First, sort all subtrees recursively. Here, we use `view`s to avoid memory
317
# allocations.
318
# TODO: Assume 1-based indexing in the following
0 commit comments