Make Tree no longer extend HashMap#3448
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3448 +/- ##
============================================
+ Coverage 76.35% 76.43% +0.07%
- Complexity 13424 13659 +235
============================================
Files 1012 1024 +12
Lines 60341 61675 +1334
Branches 7075 7208 +133
============================================
+ Hits 46076 47141 +1065
- Misses 11548 11680 +132
- Partials 2717 2854 +137 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| |`tree.containsKey(key)` |`tree.hasChild(key)` | ||
| |`tree.keySet()` |`tree.rootNodes()` | ||
| |`tree.size()` |`tree.rootNodes().size()` for root entries, or `tree.nodeCount()` for total nodes | ||
| |`getObjectsAtDepth(d)` |`getNodesAtDepth(d)` (now 0-based: depth 0 returns the roots) |
There was a problem hiding this comment.
i know we wanted more tree terminology so we moved from "Objects" to "Node", but it just occurred to me that the return here isn't exactly a "node", is it? I wonder if that will be confusing.
There was a problem hiding this comment.
I agree that it's not exactly a "node" however, renaming to "objects" may make other tree functions not very tree-like. For example, nodeCount() would have to be objectCount() and rootNodes() would have to be rootObjects(). I think it would be more conducive for tree users to keep "node".
Determines whether a PR's changed files form one coherent change or multiple disconnected clusters. Uses the OLAP 'a' traversal source with connectedComponent() step. Tested on PR apache#3448: correctly identifies 21-file main cluster (Tree + serializers + tests) and a 2-file satellite cluster (test infrastructure with minor cascading changes).
|
VOTE +1 |
1 similar comment
|
VOTE +1 |
Assisted-by: Kiro: Claude Opus 4.8
Assisted-by: Kiro: Claude Opus 4.8
Assisted-by: Kiro: Claude Opus 4.8
Summary
Changes
Treefromextends HashMap<T, Tree<T>>to afinalclass thatholds a
Mapinternally and exposes a tree-shaped public API.Treeis nolonger a
Map, which removes inheritedMapmethods whose behavior did notalign with tree semantics (e.g.
size()returned root-entry count, not totalnodes;
containsKeyonly checked immediate children).Per the dev-list discussion: https://lists.apache.org/thread/o0nqh6kmrkdht531655p351ldjll045d
This is a breaking change targeted at TinkerPop 4.0.0.
Changes
Treenow exposes:rootNodes(),childAt(key)(throws if absent),hasChild(key),contains(value)(recursive),findSubtree(key)(recursive,Optional),getOrCreateChild(key)(construction primitive).isLeaf(),nodeCount(),getNodesAtDepth(int),getTreesAtDepth(int),getLeafNodes(),getLeafTrees().addTree(),splitParents(),prettyPrint(),structural
equals/hashCode/toString.Behavior fixes that fall out of the rewrite:
isLeaf()returnstrueon an empty tree instead of throwing.getNodesAtDepth(0)returns the root nodes (now 0-based).Internal callers migrated off the removed
Mapsurface:TreeStep/TreeSideEffectStepusegetOrCreateChildduring construction.TreeSerializerand GraphSONTreeJacksonSerializer/Deserializer(V1–V4) iterate viarootNodes()/childAt()and rebuild viagetOrCreateChild()+addTree().DetachedFactory/ReferenceFactorygained an explicitTreebranch(previously handled via the
instanceof Mappath).Breaking changes
Treeas aMap(assignment toMap,instanceof Map,get/put/keySet/entrySet/size) no longer compiles.Treewas aMap(select(keys),count(local),unfold()on a tree) no longer compose; process the resultclient-side after
next()or reshape the upstream traversal.Speed and Memory
Analytical estimates (not benchmarked); the backing
HashMaptable and entriesare identical before and after.
Treenow holds aHashMapinstead ofbeing one, adding one wrapper object per node. The map itself is unchanged.
getOrCreateChildis1–2 map ops vs. the old 3);
childAtis one op slower (collapsible to one).Wire-format encoding is unchanged.
Testing
TreeTestrewritten against the new API (navigation, recursivecontainment/search, depth queries, leaf detection, null keys, structural
equality,
toString, pretty-print);TreeSupplierTestupdated.Assisted-by: Kiro: Claude Opus 4.8