kaspanet / kaspad

Kaspad was the reference full node Kaspa implementation written in Go (golang), now rewritten in Rust: https://github.com/kaspanet/rusty-kaspa
ISC License
471 stars 229 forks source link

Standardize the way iterators work #1443

Open stasatdaglabs opened 3 years ago

stasatdaglabs commented 3 years ago

We have the following iterators:

Database cursors, when they're first created, are in a "-1st" position. That is to say, both of the following loops will produce the same output: for cursor.Next() { fmt.Println(cursor.Get()) } for ok := cursor.First(); ok; ok = cursor.Next() { fmt.Println(cursor.Get()) }

Unfortunately, if the cursor needs to be reused, there's no way to reset it to the "-1st" position. This opens us up to bugs.

elichai commented 3 years ago

Maybe with generics we could make a generic iterator type (maybe even the standard library will include one)

elichai commented 3 years ago

About a day of work