GumpacG opened a new pull request, #3448:
URL: https://github.com/apache/tinkerpop/pull/3448
## Summary
Changes `Tree` from `extends HashMap<T, Tree<T>>` to a `final` class that
holds a `Map` internally and exposes a tree-shaped public API. `Tree` is no
longer a `Map`, which removes inherited `Map` methods whose behavior did
not
align with tree semantics (e.g. `size()` returned root-entry count, not
total
nodes; `containsKey` only 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
`Tree` now exposes:
- Navigation: `rootNodes()`, `childAt(key)` (throws if absent),
`hasChild(key)`,
`contains(value)` (recursive), `findSubtree(key)` (recursive,
`Optional`),
`getOrCreateChild(key)` (construction primitive).
- Structure: `isLeaf()`, `nodeCount()`, `getNodesAtDepth(int)`,
`getTreesAtDepth(int)`, `getLeafNodes()`, `getLeafTrees()`.
- Composition/output: `addTree()`, `splitParents()`, `prettyPrint()`,
structural `equals`/`hashCode`/`toString`.
Behavior fixes that fall out of the rewrite:
- `isLeaf()` returns `true` on an empty tree instead of throwing.
- `getNodesAtDepth(0)` returns the root nodes (now 0-based).
Internal callers migrated off the removed `Map` surface:
- `TreeStep` / `TreeSideEffectStep` use `getOrCreateChild` during
construction.
- GraphBinary `TreeSerializer` and GraphSON `TreeJacksonSerializer`/
`Deserializer` (V1–V4) iterate via `rootNodes()`/`childAt()` and rebuild
via
`getOrCreateChild()` + `addTree()`.
- `DetachedFactory` / `ReferenceFactory` gained an explicit `Tree` branch
(previously handled via the `instanceof Map` path).
## Breaking changes
- Code treating a `Tree` as a `Map` (assignment to `Map`, `instanceof Map`,
`get`/`put`/`keySet`/`entrySet`/`size`) no longer compiles.
- Gremlin patterns that worked only because `Tree` was a `Map`
(`select(keys)`,
`count(local)`, `unfold()` on a tree) no longer compose; process the
result
client-side after `next()` or reshape the upstream traversal.
## Speed and Memory
Analytical estimates (not benchmarked); the backing `HashMap` table and
entries
are identical before and after.
- **Memory:** ~16 B more per node — `Tree` now holds a `HashMap` instead of
being one, adding one wrapper object per node. The map itself is
unchanged.
- **Speed:** comparable. Construction is slightly faster
(`getOrCreateChild` is
1–2 map ops vs. the old 3); `childAt` is one op slower (collapsible to
one).
Wire-format encoding is unchanged.
## Testing
- `TreeTest` rewritten against the new API (navigation, recursive
containment/search, depth queries, leaf detection, null keys, structural
equality, `toString`, pretty-print); `TreeSupplierTest` updated.
- `mvn -pl gremlin-core test -Dtest=TreeTest,TreeSupplierTest` passes.
Assisted-by: Kiro: Claude Opus 4.8
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]