turbofish-org / orga

State machine engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Iteration API for `collections::Map`

mappum opened this issue · comments

It's not 100% obvious how this should be best implemented - iterating though all recursive child entries would be too expensive for children with many descendant entries.

Can we somehow seek to the next key prefix by simply incrementing the last byte and seeking to the next entry from there? (This may be incorrect for some encodings - we may need some generic way of incrementing keys).

We could maybe keep track of a next_key field for each entry by wrapping its root encoding, then we can always cheaply seek forward from an entry we have read. This adds some write overhead since an insert will now also write to the root entry of the preceding value, and do a seek to the following value.

The best way is probably to create a trait called something like Next for types where we can derive the next possible value (e.g. adding 1 for number types, incrementing the last value for length-prefixed byte vecs/numeric arrays, etc.).

Then to iterate, we simply call get(key.next()), or get_next(key.next()) if the first call does not exist.

Closed in #46