Commit 2e2d1cf
Release Manager
gh-39945: Fixing high complexity canonical_labelling for OrderedTree and BinaryTree
Added canonical_labelling overwrite to OrderedTree, modified the same
method in BinaryTree, so that the complexity is linear, instead of
quadratic in the original implementation.
This solves the issue #35930, which arises when using Sagemath to do
linear-time random generation of large tree-like structures based on
OrderedTree or BinaryTree when a canonical labelling is needed, in which
case the quadratic nature of the original algorithm slows down a linear
random generator.
This is done by using a "boxed" value to keep track of already-assigned
labels, instead of computing the number of nodes at each time for the
shifting. The precise implementation takes care so that the canonical
labellings given in the examples are not changed.
Comments are also updated.
### 📝 Checklist
<!-- Put an `x` in all the boxes that apply. -->
- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.
### ⌛ Dependencies
#35930: This PR solves the given issue.
URL: #39945
Reported by: fwjmath
Reviewer(s): fwjmath, Travis Scrimshaw
2 files changed
+91
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1198 | 1198 | | |
1199 | 1199 | | |
1200 | 1200 | | |
1201 | | - | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
1202 | 1212 | | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
1206 | 1220 | | |
1207 | | - | |
1208 | | - | |
| 1221 | + | |
| 1222 | + | |
1209 | 1223 | | |
1210 | 1224 | | |
1211 | 1225 | | |
| |||
1518 | 1532 | | |
1519 | 1533 | | |
1520 | 1534 | | |
1521 | | - | |
1522 | | - | |
1523 | | - | |
1524 | | - | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
1528 | 1543 | | |
1529 | 1544 | | |
1530 | 1545 | | |
| |||
2181 | 2196 | | |
2182 | 2197 | | |
2183 | 2198 | | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
2184 | 2234 | | |
2185 | 2235 | | |
2186 | 2236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
822 | 822 | | |
823 | 823 | | |
824 | 824 | | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
831 | 842 | | |
832 | 843 | | |
833 | 844 | | |
| |||
838 | 849 | | |
839 | 850 | | |
840 | 851 | | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | | - | |
847 | | - | |
848 | | - | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
849 | 863 | | |
850 | 864 | | |
851 | 865 | | |
| |||
0 commit comments