Movatterモバイル変換


[0]ホーム

URL:


Notice  The highest tagged major version isv5.

noder

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:4Imported by:0

Details

Repository

github.com/go-git/go-git

Links

Documentation

Overview

Package noder provide an interface for defining nodes in amerkletrie, their hashes and their paths (a noders and itsancestors).

The hasher interface is easy to implement naively by elements thatalready have a hash, like git blobs and trees. More sophisticatedimplementations can implement the Equal function in exotic waysthough: for instance, comparing the modification time of directoriesin a filesystem.

Index

Constants

This section is empty.

Variables

View Source
var NoChildren = []Noder{}

NoChildren represents the children of a noder without children.

Functions

This section is empty.

Types

typeEqual

type Equal func(a, bHasher)bool

Equal functions take two hashers and return if they are equal.

These functions are expected to be faster than reflect.Equal orreflect.DeepEqual because they can compare just the hash of theobjects, instead of their contents, so they are expected to be O(1).

typeHasher

type Hasher interface {Hash() []byte}

Hasher interface is implemented by types that can tell youtheir hash.

typeNoder

type Noder interface {Hasherfmt.Stringer// for testing purposes// Name returns the name of an element (relative, not its full// path).Name()string// IsDir returns true if the element is a directory-like node or// false if it is a file-like node.IsDir()bool// Children returns the children of the element.  Note that empty// directory-like noders and file-like noders will both return// NoChildren.Children() ([]Noder,error)// NumChildren returns the number of children this element has.//// This method is an optimization: the number of children is easily// calculated as the length of the value returned by the Children// method (above); yet, some implementations will be able to// implement NumChildren in O(1) while Children is usually more// complex.NumChildren() (int,error)}

The Noder interface is implemented by the elements of a Merkle Trie.

There are two types of elements in a Merkle Trie:

- file-like nodes: they cannot have children.

- directory-like nodes: they can have 0 or more children and theirhash is calculated by combining their children hashes.

typePath

type Path []Noder

Path values represent a noder and its ancestors. The root goes firstand the actual final noder the path is referring to will be the last.

A path implements the Noder interface, redirecting all the interfacecalls to its final noder.

Paths build from an empty Noder slice are not valid paths and shouldnot be used.

func (Path)Children

func (pPath) Children() ([]Noder,error)

Children returns the children of the final noder in the path.

func (Path)Compare

func (pPath) Compare(otherPath)int

Compare returns -1, 0 or 1 if the path p is smaller, equal or biggerthan other, in "directory order"; for example:

"a" < "b""a/b/c/d/z" < "b""a/b/a" > "a/b"

func (Path)Hash

func (pPath) Hash() []byte

Hash returns the hash of the final noder of the path.

func (Path)IsDir

func (pPath) IsDir()bool

IsDir returns if the final noder of the path is a directory-likenoder.

func (Path)Last

func (pPath) Last()Noder

Last returns the final noder in the path.

func (Path)Name

func (pPath) Name()string

Name returns the name of the final noder of the path.

func (Path)NumChildren

func (pPath) NumChildren() (int,error)

NumChildren returns the number of children the final noder of thepath has.

func (Path)String

func (pPath) String()string

String returns the full path of the final noder as a string, using"/" as the separator.

Source Files

View all Source files

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