Skip to content

Commit e18c7a7

Browse files
committed
fix: Fix merge conflict in conftest
2 parents 6b27396 + 1e4f882 commit e18c7a7

File tree

11 files changed

+419
-368
lines changed

11 files changed

+419
-368
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Added
9+
- BaseNode: Add diameter property.
910
- Misc: Testing to include benchmark timings for tree creation, compare benchmark tests across commits, reject pull request if benchmark tests fails.
1011
- Misc: Documentation to include benchmark results.
1112
### Changed
1213
- Misc: Documentation to enable zooming in of images, add navigation section headers, remove some meta tags.
14+
- Misc: Split up testing into multiple conftest files.
1315

1416
## [0.16.2] - 2024-02-06
1517
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Related Links:
1313
- [Issues](https://github.com/kayjan/bigtree/issues)
1414
/ [Discussions](https://github.com/kayjan/bigtree/discussions)
1515
/ [Changelog](https://github.com/kayjan/bigtree/blob/master/CHANGELOG.md)
16-
/ [Contributing](https://bigtree.readthedocs.io/en/latest/others/contributing.html)
16+
/ [Contributing](https://bigtree.readthedocs.io/en/latest/contributing/)
1717
- Package
1818
- [PyPI](https://pypi.org/project/bigtree/)
1919
/ [Conda](https://anaconda.org/conda-forge/bigtree)

bigtree/node/basenode.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import copy
4+
import heapq
45
from typing import Any, Dict, Generator, Iterable, List, Optional, Set, Tuple, TypeVar
56

67
from bigtree.globals import ASSERTIONS
@@ -92,8 +93,9 @@ class BaseNode:
9293
2. ``is_root``: Get indicator if self is root node
9394
3. ``is_leaf``: Get indicator if self is leaf node
9495
4. ``root``: Get root node of tree
95-
5. ``depth``: Get depth of self
96-
6. ``max_depth``: Get maximum depth from root to leaf node
96+
5. ``diameter``: Get diameter of self
97+
6. ``depth``: Get depth of self
98+
7. ``max_depth``: Get maximum depth from root to leaf node
9799
98100
**BaseNode Methods**
99101
@@ -502,6 +504,37 @@ def root(self: T) -> T:
502504
return self
503505
return self.parent.root
504506

507+
@property
508+
def diameter(self) -> int:
509+
"""Get diameter of tree or subtree, the length of longest path between any two nodes
510+
511+
Returns:
512+
(int)
513+
"""
514+
diameter = 0
515+
516+
if self.is_leaf:
517+
return diameter
518+
519+
def _recursive_diameter(node: T) -> int:
520+
"""Recursively iterate through node and its children to get diameter of node
521+
522+
Args:
523+
node (Node): current node
524+
525+
Returns:
526+
(int)
527+
"""
528+
nonlocal diameter
529+
if node.is_leaf:
530+
return 1
531+
child_length = [_recursive_diameter(child) for child in node.children]
532+
diameter = max(diameter, sum(heapq.nlargest(2, child_length)))
533+
return 1 + max(child_length)
534+
535+
_recursive_diameter(self)
536+
return diameter
537+
505538
@property
506539
def depth(self) -> int:
507540
"""Get depth of self, indexing starts from 1

docs/benchmarks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ hide:
77
# ⏰ Benchmarks
88

99
<div>
10-
<iframe onload="resizeIframe(this)" style="width:100vw; border:none" src="../dev/bench/index.html"></iframe>
10+
<iframe onload="resizeIframe(this)" scrolling="no" style="width:100vw; border:none" src="../dev/bench/index.html"></iframe>
1111
</div>

docs/demo/tree.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ Below are the tables of attributes available to `BaseNode` and `Node` classes.
425425
|:------------------------------------:|--------------------|----------------------------|
426426
| Check if root | `root.is_root` | True |
427427
| Check if leaf node | `root.is_leaf` | False |
428+
| Check diameter of tree | `node_b.diameter` | 3 |
428429
| Check depth of node | `node_b.depth` | 2 |
429430
| Check depth of tree | `node_b.max_depth` | 4 |
430431
| Get root of tree | `node_b.root` | Node(/a, ) |

docs/dev/bench/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@
130130
const data = window.BENCHMARK_DATA;
131131

132132
// Render footer (repository)
133-
const date = Date(data.lastUpdate).split(" ").slice(0, 4).join(" ");
134-
document.getElementById('last-update').textContent = date;
133+
const date = new Date(data.lastUpdate);
134+
const date_str = date.toLocaleDateString("en-sg", {weekday:"short", day:"2-digit", month:"short", year:"numeric"});
135+
document.getElementById('last-update').textContent = date_str;
135136

136137
const repoResultURL = 'https://kayjan.github.io/bigtree-benchmark/dev/bench/';
137138
const repoResult = document.getElementById('repository-result');

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ theme:
8080
name: Switch to dark mode
8181
- media: "(prefers-color-scheme: dark)"
8282
scheme: slate
83-
primary: green
83+
primary: teal
8484
accent: yellow
8585
toggle:
8686
icon: material/weather-night

0 commit comments

Comments
 (0)