From 78a21016a5f6239b055c617064adcc8c45103803 Mon Sep 17 00:00:00 2001 From: Karl Gaissmaier Date: Sat, 1 Feb 2025 10:40:06 +0100 Subject: [PATCH] again, clarify the empty interface as child --- node.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/node.go b/node.go index 7d065dc..1cf4004 100644 --- a/node.go +++ b/node.go @@ -40,15 +40,27 @@ type node[V any] struct { // with the help of the baseIndex function from the ART algorithm. prefixes sparse.Array[V] - // children, recursively spans the trie with a branching factor of 256 - // the generic child as empty interface{} is a node (recursive) or + // Sorry, here we have to use a mixture of generics and interfaces: + // + // children, recursively spans the trie with a branching factor of 256. + // + // Without path compression, the definition would naturally be: + // children sparse.Array[*node[V]] + // + // ... but with path compression the child can now be a node (recursive) or // a path compressed leaf (prefix and value). // - // The empty interface{} is by intention instead of a e.g. - // type noder interface { isLeaf() bool } + // With path compression we could define: + // type noder[V any] interface { + // isLeaf[V]() bool + // } + // + // and + // children sparse.Array[noder[V]] // + // But we use the empty interface{} instead, by intention! // The empty interface{} consumes less memory and type assertions are faster than - // indirect method calls e.g. node.isLeaf() + // indirect method calls like node.isLeaf() children sparse.Array[interface{}] }