Skip to content

Addchild and fetchchild node compatiblity +grow working#41

Closed
aivillio wants to merge 20 commits into
acmpesuecc:devfrom
aivillio:addchild
Closed

Addchild and fetchchild node compatiblity +grow working#41
aivillio wants to merge 20 commits into
acmpesuecc:devfrom
aivillio:addchild

Conversation

@aivillio

@aivillio aivillio commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

PR title OR Closes {Link to issue}

Context

Why are these changes being made?

The addchild and fetch child were not compatitble for node48 and node256

Description

How have the changes been made? i.e. steps taken to solve the above issue

  • added a switch case which lets each node have their own addchild and fetchchild logic
  • lets growchild work

Changes

Technical description of the changes made

Addchild {node48}

  • grows if full
  • gets index from keys array and then makes child array point to child
  • finds free location (indexed with +1 so that we can use 0 as an indication of empty block)

Addchild {node256}

*similar functions execpt grow

fetchleaf

  • go through the child array and get the child array and get the first child

Tests

Tests ran after the changes and their results

*Ran main.go
Screenshot From 2026-04-01 01-14-15

Additional info

MERGE THIS AFTER PR37

Copilot AI review requested due to automatic review settings March 31, 2026 19:44
@aivillio aivillio changed the title Addchild and fetchchild node compatiblity Addchild and fetchchild node compatiblity +grow working Mar 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Adaptive Radix Tree (ART) implementation to correctly support addchild/findchild behavior across Node48 and Node256 (including growth from smaller node types), enabling inserts to continue working as node fanout increases.

Changes:

  • Added node-type-specific addchild logic for Node4/16, Node48, and Node256, with growth support.
  • Implemented findchild, prefix checking (checkprefix), and leaf fetching (fetchleaf) helpers used by insert/search.
  • Added search and a small CLI test harness to insert keys and print the tree.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/art/util.go Adds core ART utilities: add/find child, prefix compare, grow, and leaf fetching.
internal/art/insert.go Implements insertion logic with prefix compression and node splitting.
internal/art/search.go Implements lookup logic through prefixes and child navigation.
internal/art/node.go Defines node types, constants, and shared node structures.
internal/art/node4.go Constructs Node4 inner nodes.
internal/art/node16.go Constructs Node16 inner nodes.
internal/art/node48.go Constructs Node48 inner nodes with indirection layer.
internal/art/node256.go Constructs Node256 inner nodes with direct child map.
internal/art/leaf.go Defines leaf structure and isleaf helper.
internal/art/print_tree.go Adds a debug printer for visualizing the ART structure.
internal/art/art.go Adds a minimal public Tree API (Insert, Search, Root).
cmd/radFS/arttest/main.go Simple executable to insert sample keys and print the tree.
docs/weekly/angelo/week_4.md Weekly progress notes update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/art/search.go
Comment on lines +29 to +37
// Get the next byte to branch on at current depth.
// Returns 0 (terminator) if key is exhausted.
k := key[depth]

// Find the child corresponding to byte k and recurse deeper.
// Return nil if no child exists for this byte.
next, _ := findchild(k, n)
if next != nil {
return search(next, key, depth+1)

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

search indexes key[depth] without checking whether depth < len(key). When searching for a key that is a prefix of an existing path (or an empty key once the tree has internal nodes), this will panic with an out-of-range error. Add an early check for depth == len(key) (and return n.innerNode.leaf if it matches, otherwise nil) before reading key[depth].

Copilot uses AI. Check for mistakes.
Comment thread internal/art/insert.go Outdated
Comment thread internal/art/search.go
Comment on lines +12 to +16
if isleaf(n) {
if string(n.leaf.key) == string(key) {
return n
}
return nil

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaf key comparison converts both byte slices to strings (string(n.leaf.key) == string(key)), which performs allocations/copies on each search. Using bytes.Equal(n.leaf.key, key) avoids the extra allocations and is the conventional way to compare []byte values.

Copilot uses AI. Check for mistakes.
clamping the

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Delta18-Git

Copy link
Copy Markdown
Member

Closing in favour of #47

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.

4 participants