hashicorp/go-immutable-radix

Get All Keys in the Radix Tree

vivekpatani opened this issue · 0 comments

Is there a native way to get all the keys in the tree?

Here's what I've tried so far

func GetAObjs() (objs []*treeObj) {
	it := tree.Root().Iterator()
	for _, val, ok := it.Next(); ok; _, val, ok = it.Next() {
		if val != nil {
			objs = append(objs, val.(*treeObj))
		}
	}
	return objs
}

For some reason, it responds wit exactly 1 object, I read in another issue that this was the case, would you happen to have any suggestions what could be a good way to return all items.

I saw that the go-radix(https://pkg.go.dev/github.com/armon/go-radix#Tree.ToMap) has a toMap function which (I'm assuming) returns a map of the tree. Thanks.

Update: it was my misunderstanding, the above example is valid now, I miswrote the function, it was incorrect, now corrected. Closing because no problem.