Make Tree no longer extend HashMap#3448
Conversation
Assisted-by: Kiro: Claude Opus 4.8
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3448 +/- ##
============================================
- Coverage 76.35% 76.32% -0.04%
- Complexity 13424 13541 +117
============================================
Files 1012 1017 +5
Lines 60341 61014 +673
Branches 7075 7147 +72
============================================
+ Hits 46076 46571 +495
- Misses 11548 11639 +91
- Partials 2717 2804 +87 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Assisted-by: Kiro: Claude Opus 4.8
| tree['marko'] | ||
| tree['marko']['josh'] | ||
| tree.getObjectsAtDepth(3) | ||
| tree.childAt('marko') |
There was a problem hiding this comment.
would be nice if we didn't lose the groovy syntax. childAt is better than the Java alternative but less so for Groovy. a bit of Groovy sugar would bring that back.
There was a problem hiding this comment.
I've updated it to include tree in the SugarLoader to include support the old syntax. Docs will just have the old syntax in the comment as an option with the sugar plugin.
| |`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).
Assisted-by: Kiro: Claude Opus 4.8
|
VOTE +1 |
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