Movatterモバイル変換


[0]ホーム

URL:


Notice  The highest tagged major version isv5.

merkletrie

package
v4.7.0+incompatibleLatest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2018 License:Apache-2.0Imports:6Imported by:0

Details

Repository

github.com/go-git/go-git

Links

Documentation

Overview

Package merkletrie provides support for n-ary trees that are at the sametime Merkle trees and Radix trees (tries).

Git trees are Radix n-ary trees in virtue of the names of theirtree entries. At the same time, git trees are Merkle trees thanks totheir hashes.

This package defines Merkle tries as nodes that should have:

- a hash: the Merkle part of the Merkle trie

- a key: the Radix part of the Merkle trie

The Merkle hash condition is not enforced by this package though. Thismeans that the hash of a node doesn't have to take into account the hashes oftheir children, which is good for testing purposes.

Nodes in the Merkle trie are abstracted by the Noder interface. Theintended use is that git trees implements this interface, eitherdirectly or using a simple wrapper.

This package provides an iterator for merkletries that can skip wholedirectory-like noders and an efficient merkletrie comparison algorithm.

When comparing git trees, the simple approach of alphabetically sortingtheir elements and comparing the resulting lists is too slow as itdepends linearly on the number of files in the trees: When a directoryhas lots of files but none of them has been modified, this approach isvery expensive. We can do better by prunning whole directories thathave not change, just by looking at their hashes. This package providesthe tools to do exactly that.

Index

Constants

This section is empty.

Variables

View Source
var (ErrCanceled =errors.New("operation canceled"))

Functions

This section is empty.

Types

typeAction

type Actionint

Action values represent the kind of things a Change can represent:insertion, deletions or modifications of files.

const (Insert ActionDeleteModify)

The set of possible actions in a change.

func (Action)String

func (aAction) String()string

String returns the action as a human readable text.

typeChange

type Change struct {// The noder before the change or nil if it was inserted.Fromnoder.Path// The noder after the change or nil if it was deleted.Tonoder.Path}

A Change value represent how a noder has change between to merkletries.

funcNewDelete

func NewDelete(nnoder.Path)Change

NewDelete returns a new Change representing the deletion of n.

funcNewInsert

func NewInsert(nnoder.Path)Change

NewInsert returns a new Change representing the insertion of n.

funcNewModify

func NewModify(a, bnoder.Path)Change

NewModify returns a new Change representing that a has been modified andit is now b.

func (*Change)Action

func (c *Change) Action() (Action,error)

Action is convenience method that returns what Action c represents.

func (Change)String

func (cChange) String()string

String returns a single change in human readable form, using theformat: '<' + action + space + path + '>'. The contents of the filebefore or after the change are not included in this format.

Example: inserting a file at the path a/b/c.txt will return "<Inserta/b/c.txt>".

typeChanges

type Changes []Change

Changes is a list of changes between to merkletries.

funcDiffTree

func DiffTree(fromTree, toTreenoder.Noder,hashEqualnoder.Equal) (Changes,error)

DiffTree calculates the list of changes between two merkletries. Ituses the provided hashEqual callback to compare noders.

funcDiffTreeContext

func DiffTreeContext(ctxcontext.Context, fromTree, toTreenoder.Noder,hashEqualnoder.Equal) (Changes,error)

DiffTree calculates the list of changes between two merkletries. Ituses the provided hashEqual callback to compare noders.Error will be returned if context expiresProvided context must be non nil

funcNewChanges

func NewChanges()Changes

NewChanges returns an empty list of changes.

func (*Changes)Add

func (l *Changes) Add(cChange)

Add adds the change c to the list of changes.

func (*Changes)AddRecursiveDelete

func (l *Changes) AddRecursiveDelete(rootnoder.Path)error

AddRecursiveDelete adds the required changes to delete all thefile-like noders found in root, recursively.

func (*Changes)AddRecursiveInsert

func (l *Changes) AddRecursiveInsert(rootnoder.Path)error

AddRecursiveInsert adds the required changes to insert all thefile-like noders found in root, recursively.

typeIter

type Iter struct {// contains filtered or unexported fields}

Iter is an iterator for merkletries (only the trie part of themerkletrie is relevant here, it does not use the Hasher interface).

The iteration is performed in depth-first pre-order. Entries at eachdepth are traversed in (case-sensitive) alphabetical order.

This is the kind of traversal you will expect when listing ordinaryfiles and directories recursively, for example:

     Trie           Traversal order     ----           ---------------      .    / | \           c   /  |  \          d/  d   c   z   ===>  d/a / \                d/bb   a               z

This iterator is somewhat especial as you can chose to skip whole"directories" when iterating:

- The Step method will iterate normally.

- the Next method will not descend deeper into the tree.

For example, if the iterator is at `d/`, the Step method will return`d/a` while the Next would have returned `z` instead (skipping `d/`and its descendants). The name of the these two methods are based onthe well known "next" and "step" operations, quite common indebuggers, like gdb.

The paths returned by the iterator will be relative, if the iteratorwas created from a single node, or absolute, if the iterator wascreated from the path to the node (the path will be prefixed to allreturned paths).

funcNewIter

func NewIter(nnoder.Noder) (*Iter,error)

NewIter returns a new relative iterator using the provider noder asits unnamed root. When iterating, all returned paths will berelative to node.

funcNewIterFromPath

func NewIterFromPath(pnoder.Path) (*Iter,error)

NewIterFromPath returns a new absolute iterator from the noder at theend of the path p. When iterating, all returned paths will beabsolute, using the root of the path p as their root.

func (*Iter)Next

func (iter *Iter) Next() (noder.Path,error)

Next returns the path of the next node without descending deeper intothe trie and nil. If there are no more entries in the trie itreturns nil and io.EOF. In case of error, it will return nil and theerror.

func (*Iter)Step

func (iter *Iter) Step() (noder.Path,error)

Step returns the path to the next node in the trie, descending deeperinto it if needed, and nil. If there are no more nodes in the trie,it returns nil and io.EOF. In case of error, it will return nil andthe error.

Source Files

View all Source files

Directories

PathSynopsis
internal
fsnoder
Package fsnoder allows to create merkletrie noders that resemble file systems, from human readable string descriptions.
Package fsnoder allows to create merkletrie noders that resemble file systems, from human readable string descriptions.
Package noder provide an interface for defining nodes in a merkletrie, their hashes and their paths (a noders and its ancestors).
Package noder provide an interface for defining nodes in a merkletrie, their hashes and their paths (a noders and its ancestors).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp