Re: help with pctrie

From: Lexi Winter <ivy_at_freebsd.org>
Date: Sun, 03 Aug 2025 22:18:04 UTC
Mark Johnston:
> On Sun, Aug 03, 2025 at 08:22:43PM +0100, Lexi Winter wrote:
> > i'm trying to use <sys/pctrie.h> and running into a problem i don't
> > really understand.  since it's largely undocumented, this is probably
> > something i'm doing wrong rather than bug, but i can't work out what.
 
> I think the problem there is that you're missing a
> FDB_PCTRIE_ITER_LOOKUP() to return the value at the current position in
> the iterator.  The general pattern should be something like:

thanks to Mark's explanation (+ discussion on IRC) i worked out what's
wrong: to iterate all entries in a pctrie, you need to start by calling
xxx_PCTRIE_ITER_LOOKUP_GE(iter, 0), then for each iteration, call
xxx_PCTRIE_ITER_STEP_GE(iter).

xxx_PCTRIE_ITER_NEXT was named to confuse C++ programmers and actually
means "add 1 to the current node and return that or NULL", so we should
never use that.