From 7655b549b88d60276fd80459dea0b1865db05db4 Mon Sep 17 00:00:00 2001 From: Simon Fell Date: Sun, 23 Feb 2025 15:22:23 -0800 Subject: [PATCH] fix for bounds panic in n16 delete --- art_test.go | 11 ++++++++++- node16.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/art_test.go b/art_test.go index 79ecfcf..fde7f1d 100644 --- a/art_test.go +++ b/art_test.go @@ -68,9 +68,18 @@ func Test_GrowNode(t *testing.T) { // test that the node is grown to the relevant type {1, &Stats{Keys: 1}}, {2, &Stats{Node4s: 1, Keys: 2}}, - {12, &Stats{Node16s: 1, Keys: 12}}, + {3, &Stats{Node4s: 1, Keys: 3}}, + {4, &Stats{Node4s: 1, Keys: 4}}, + {5, &Stats{Node16s: 1, Keys: 5}}, + {14, &Stats{Node16s: 1, Keys: 14}}, + {15, &Stats{Node16s: 1, Keys: 15}}, + {16, &Stats{Node16s: 1, Keys: 16}}, + {17, &Stats{Node48s: 1, Keys: 17}}, {40, &Stats{Node48s: 1, Keys: 40}}, + {48, &Stats{Node48s: 1, Keys: 48}}, + {49, &Stats{Node256s: 1, Keys: 49}}, {200, &Stats{Node256s: 1, Keys: 200}}, + {256, &Stats{Node256s: 1, Keys: 256}}, } for _, tc := range cases { t.Run(fmt.Sprintf("children %d", tc.children), func(t *testing.T) { diff --git a/node16.go b/node16.go index afa8520..4f6aede 100644 --- a/node16.go +++ b/node16.go @@ -131,9 +131,9 @@ func (n *node16[V]) removeChild(k byte) { } copy(n.key[idx:], n.key[idx+1:int(n.childCount)]) copy(n.children[idx:], n.children[idx+1:int(n.childCount)]) + n.childCount-- n.key[int(n.childCount)] = 0 n.children[int(n.childCount)] = nil - n.childCount-- } func (n *node16[V]) shrink() node[V] {