From 3008b416baab8093df86c82f94cf25ea3fbc7ec3 Mon Sep 17 00:00:00 2001 From: Toru Maesaka Date: Fri, 22 Nov 2024 21:35:12 -0800 Subject: [PATCH] arc: remove impossible insertion code path --- arc.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/arc.go b/arc.go index cb6cdad..6bd8118 100644 --- a/arc.go +++ b/arc.go @@ -194,27 +194,23 @@ func (a *Arc) insert(key []byte, value []byte, overwrite bool) error { newNode.setKey(key) - // Reached the deepest level of the tree for the given key. + // No existing path matches the remaining key portion. The new record + // will be inserted as a leaf node. At this point, current's key must + // fully match the key prefix because: + // + // 1. "No common prefix" cases are handled earlier in the function + // 2. Partial prefix match would have triggered splitNode() if nextNode == nil { if current == a.root { if a.root.key == nil || prefixLen == len(a.root.key) { a.root.addChild(newNode) - a.numNodes++ - } else { - // Make current and newNode siblings by creating a new root. - a.root = &node{key: prefix} - a.root.addChild(current) - a.root.addChild(newNode) - - // Increment by 2 for the new root node and newNode. - a.numNodes += 2 } } else { // Simple case where newNode becomes a child of the leaf node. current.addChild(newNode) - a.numNodes++ } + a.numNodes++ a.numRecords++ return nil }