Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add interface describing iteration #228

Merged
merged 3 commits into from
Sep 10, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions v2/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
internalio "github.com/ipld/go-car/v2/internal/io"

"github.com/multiformats/go-multicodec"
"github.com/multiformats/go-multihash"

"github.com/multiformats/go-varint"

Expand Down Expand Up @@ -58,6 +59,22 @@ type (
// ErrNotFound is returned.
GetAll(cid.Cid, func(uint64) bool) error
}

// IterableIndex extends Index in cases where the Index is able to
// provide an iterator for getting the list of all entries in the
// index.
IterableIndex interface {
Index

// ForEach takes a callback function that will be called
// on each entry in the index. The arguments to the callback are
// the multihash of the element, and the offset in the car file
// where the element appears.
//
// If the callback returns a non-nil error, the iteration is aborted,
// and the ForEach function returns the error to the user.
ForEach(func(multihash.Multihash, uint64) error) error
}
)

// GetFirst is a wrapper over Index.GetAll, returning the offset for the first
Expand Down