Skip to content

Refactor Leaf Node: Immutable Access, Flexible Constructors, and Algorithmic Safety#1

Open
Manas-Dikshit wants to merge 1 commit intooppia:masterfrom
Manas-Dikshit:master
Open

Refactor Leaf Node: Immutable Access, Flexible Constructors, and Algorithmic Safety#1
Manas-Dikshit wants to merge 1 commit intooppia:masterfrom
Manas-Dikshit:master

Conversation

@Manas-Dikshit
Copy link

This PR modifies the Leaf class in the binary tree data structure.

These include:

  • Immutable data access: getData() returns a read-only view to avoid making modifications unintentionally while navigating leaves in traversal and comparison.
  • Flexible initialization. Constructors to create an empty leaf or from an existing collection have been added.
    Convenience Methods:
    The size() method and isEmpty() method support constant-time queries of their results without showing their internal state.
    Improved equality/hash behavior: This retains the correct equals and hashCode methods, which combine the hashCode from the parent classes with the ordered leaf data.
  • Focus on algorithm: Leaf nodes support safe and uniform access for tree traversal, comparisons, and bulk insertions with the intention of preventing side-effects on the underlying array. There is no modification to the tree logic and are all internal to the leaf node for correctness and immutability.

Refactor Leaf class to use final data list and add new methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant