5252 * @param <K> the key type, must extend Bytes
5353 * @param <V> the value type
5454 */
55- @ SuppressWarnings ({"rawtypes" , "ThreadPriorityCheck" })
55+ @ SuppressWarnings ({"rawtypes" , "ThreadPriorityCheck" , "unused" })
5656public class ParallelStoredMerklePatriciaTrie <K extends Bytes , V >
5757 extends StoredMerklePatriciaTrie <K , V > {
5858
@@ -189,15 +189,15 @@ private void processPendingUpdates(final Optional<NodeUpdater> maybeNodeUpdater)
189189
190190 // Convert pending updates to UpdateEntry objects with nibble paths
191191 final List <UpdateEntry <V >> entries =
192- pendingUpdates .entrySet ().stream ()
193- .map (e -> new UpdateEntry <>(bytesToPath (e .getKey ()), e .getValue ()))
194- .toList ();
195-
192+ pendingUpdates .entrySet ().stream ()
193+ .map (e -> new UpdateEntry <>(bytesToPath (e .getKey ()), e .getValue ()))
194+ .toList ();
196195
197196 final CommitCache commitCache = new CommitCache ();
198197 final boolean shouldCommit = maybeNodeUpdater .isPresent ();
199198
200- this .root = processNode (
199+ this .root =
200+ processNode (
201201 root ,
202202 Bytes .EMPTY ,
203203 0 ,
@@ -238,15 +238,16 @@ private Node<V> processNode(
238238 final Node <V > loadedNode = loadNode (node );
239239
240240 // Dispatch based on node type
241- return switch (loadedNode ) {
242- case BranchNode <V > branch -> handleBranchNode (branch , location , depth , updates , maybeCommitCache );
243- case ExtensionNode <V > ext -> handleExtension (ext , location , depth , updates , maybeCommitCache );
244- case LeafNode <V > leaf -> handleLeafNode (leaf , location , depth , updates , maybeCommitCache );
245- case NullNode <V > ignored -> handleNullNode (location , depth , updates , maybeCommitCache );
246- case null , default ->
247- // Unknown node type: fallback to sequential processing
248- applyUpdatesSequentially (loadedNode , location , updates , maybeCommitCache );
249- };
241+ return switch (loadedNode ) {
242+ case BranchNode <V > branch ->
243+ handleBranchNode (branch , location , depth , updates , maybeCommitCache );
244+ case ExtensionNode <V > ext -> handleExtension (ext , location , depth , updates , maybeCommitCache );
245+ case LeafNode <V > leaf -> handleLeafNode (leaf , location , depth , updates , maybeCommitCache );
246+ case NullNode <V > ignored -> handleNullNode (location , depth , updates , maybeCommitCache );
247+ case null , default ->
248+ // Unknown node type: fallback to sequential processing
249+ applyUpdatesSequentially (loadedNode , location , updates , maybeCommitCache );
250+ };
250251 }
251252
252253 /**
@@ -338,8 +339,8 @@ private Node<V> handleBranchNode(
338339 }
339340
340341 /**
341- * Handles updates for an extension node. Attempts to parallelize by temporarily expanding
342- * the extension into branches, processing updates, then reconstructing if beneficial.
342+ * Handles updates for an extension node. Attempts to parallelize by temporarily expanding the
343+ * extension into branches, processing updates, then reconstructing if beneficial.
343344 *
344345 * @param extensionNode the extension node to update
345346 * @param location the location of the extension node
@@ -349,11 +350,11 @@ private Node<V> handleBranchNode(
349350 * @return the updated extension or restructured node
350351 */
351352 private Node <V > handleExtension (
352- final ExtensionNode <V > extensionNode ,
353- final Bytes location ,
354- final int depth ,
355- final List <UpdateEntry <V >> updates ,
356- final Optional <CommitCache > maybeCommitCache ) {
353+ final ExtensionNode <V > extensionNode ,
354+ final Bytes location ,
355+ final int depth ,
356+ final List <UpdateEntry <V >> updates ,
357+ final Optional <CommitCache > maybeCommitCache ) {
357358
358359 final Bytes extensionPath = extensionNode .getPath ();
359360 final int pathDepth = location .size ();
@@ -365,35 +366,26 @@ private Node<V> handleExtension(
365366 final Node <V > childNode = extensionNode .getChild ();
366367
367368 final Node <V > newChild =
368- processNode (
369- childNode , newLocation , depth + extensionPath .size (), updates , maybeCommitCache );
369+ processNode (
370+ childNode , newLocation , depth + extensionPath .size (), updates , maybeCommitCache );
370371
371372 // Create new extension with updated child
372373 final Node <V > newExtension = extensionNode .replaceChild (newChild );
373374 commitOrHashNode (newExtension , location , maybeCommitCache );
374375 return newExtension ;
375376 }
376377
377- // Updates diverge: check if parallelization is worth it
378- if (updates .size () > 1 ) {
379- // Expand extension into branch structure, process in parallel, then optimize
380- return expandExtensionAndProcess (
381- extensionNode , extensionPath , location , depth , updates , maybeCommitCache );
382- }
383-
384378 // Single update or not worth parallelizing: use sequential processing
385379 return applyUpdatesSequentially (extensionNode , location , updates , maybeCommitCache );
386380 }
387381
388382 /**
389- * Expands an extension node into a branch structure to enable parallel processing.
390- * After processing, the structure is automatically optimized (may recreate extensions).
383+ * Expands an extension node into a branch structure to enable parallel processing. After
384+ * processing, the structure is automatically optimized (may recreate extensions).
391385 *
392- * Strategy:
393- * 1. Create branches for each nibble in the extension path
394- * 2. Place the extension's child at the end of this chain
395- * 3. Process all updates through this expanded structure
396- * 4. Let the trie's natural optimization (maybeFlatten) recreate extensions if needed
386+ * <p>Strategy: 1. Create branches for each nibble in the extension path 2. Place the extension's
387+ * child at the end of this chain 3. Process all updates through this expanded structure 4. Let
388+ * the trie's natural optimization (maybeFlatten) recreate extensions if needed
397389 *
398390 * @param extensionNode the extension to expand
399391 * @param extensionPath the path of the extension
@@ -404,12 +396,12 @@ private Node<V> handleExtension(
404396 * @return the processed and optimized node structure
405397 */
406398 private Node <V > expandExtensionAndProcess (
407- final ExtensionNode <V > extensionNode ,
408- final Bytes extensionPath ,
409- final Bytes location ,
410- final int depth ,
411- final List <UpdateEntry <V >> updates ,
412- final Optional <CommitCache > maybeCommitCache ) {
399+ final ExtensionNode <V > extensionNode ,
400+ final Bytes extensionPath ,
401+ final Bytes location ,
402+ final int depth ,
403+ final List <UpdateEntry <V >> updates ,
404+ final Optional <CommitCache > maybeCommitCache ) {
413405
414406 // Build a chain of branches representing the extension path
415407 // Example: extension path [3,5,7] becomes:
@@ -425,7 +417,7 @@ private Node<V> expandExtensionAndProcess(
425417 currentNode = nodeFactory .createBranch (children , Optional .empty ());
426418 }
427419
428- // The processNode call and subsequent replaceAllChildren will automatically
420+ // The processNode call and subsequent replaceAllChildren will automatically
429421 // call maybeFlatten, which will recreate extensions where beneficial
430422 return processNode (currentNode , location , depth , updates , maybeCommitCache );
431423 }
@@ -442,11 +434,11 @@ private Node<V> expandExtensionAndProcess(
442434 * @return the updated node (may be a branch if expanded)
443435 */
444436 private Node <V > handleLeafNode (
445- final LeafNode <V > leaf ,
446- final Bytes location ,
447- final int depth ,
448- final List <UpdateEntry <V >> updates ,
449- final Optional <CommitCache > maybeCommitCache ) {
437+ final LeafNode <V > leaf ,
438+ final Bytes location ,
439+ final int depth ,
440+ final List <UpdateEntry <V >> updates ,
441+ final Optional <CommitCache > maybeCommitCache ) {
450442 // Check if parallel processing would be beneficial
451443 if (updates .size () > 1 ) {
452444 // Build a branch incorporating the leaf, then process updates
@@ -457,20 +449,22 @@ private Node<V> handleLeafNode(
457449 // Sequential processing for small update sets or non-diverging updates
458450 return applyUpdatesSequentially (leaf , location , updates , maybeCommitCache );
459451 }
452+
460453 /**
461454 * Handles updates for a null node (empty position). If there are enough updates that diverge,
462455 * builds a branch structure directly, then processes in parallel.
463- * @param location the location of the node
464- * @param depth the current depth in the trie
465- * @param updates the updates to apply
456+ *
457+ * @param location the location of the node
458+ * @param depth the current depth in the trie
459+ * @param updates the updates to apply
466460 * @param maybeCommitCache optional commit cache for storing nodes
467461 * @return the updated node (may be a branch if expanded)
468462 */
469463 private Node <V > handleNullNode (
470- final Bytes location ,
471- final int depth ,
472- final List <UpdateEntry <V >> updates ,
473- final Optional <CommitCache > maybeCommitCache ) {
464+ final Bytes location ,
465+ final int depth ,
466+ final List <UpdateEntry <V >> updates ,
467+ final Optional <CommitCache > maybeCommitCache ) {
474468
475469 // Check if parallel processing would be beneficial
476470 if (updates .size () > 1 ) {
0 commit comments