[#1642] tree: Introduce Cursor type

* Use `Cursor` as parameter for `TreeSortedByFilename`

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2025-02-20 11:05:11 +03:00 committed by Evgenii Stratonikov
parent a405fb1f39
commit a11b2d27e4
9 changed files with 40 additions and 20 deletions

View file

@ -37,7 +37,7 @@ type Forest interface {
TreeGetChildren(ctx context.Context, cid cidSDK.ID, treeID string, nodeID Node) ([]NodeInfo, error)
// TreeSortedByFilename returns children of the node with the specified ID. The nodes are sorted by the filename attribute..
// Should return ErrTreeNotFound if the tree is not found, and empty result if the node is not in the tree.
TreeSortedByFilename(ctx context.Context, cid cidSDK.ID, treeID string, nodeID MultiNode, last *string, count int) ([]MultiNodeInfo, *string, error)
TreeSortedByFilename(ctx context.Context, cid cidSDK.ID, treeID string, nodeID MultiNode, last *Cursor, count int) ([]MultiNodeInfo, *Cursor, error)
// TreeGetOpLog returns first log operation stored at or above the height.
// In case no such operation is found, empty Move and nil error should be returned.
TreeGetOpLog(ctx context.Context, cid cidSDK.ID, treeID string, height uint64) (Move, error)
@ -79,6 +79,27 @@ const (
AttributeVersion = "Version"
)
// Cursor keeps state between function calls for traversing nodes.
// It stores the attributes associated with a previous call, allowing subsequent operations
// to resume traversal from this point rather than starting from the beginning.
type Cursor struct {
// Last traversed filename.
filename string
}
func NewCursor(filename string) *Cursor {
return &Cursor{
filename: filename,
}
}
func (c *Cursor) GetFilename() string {
if c == nil {
return ""
}
return c.filename
}
// CIDDescriptor contains container ID and information about the node position
// in the list of container nodes.
type CIDDescriptor struct {