ldiff

package
v0.5.0-alpha.16 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ldiff provides a container of elements with fixed id and changeable content. Diff can calculate the difference with another diff container (you can make it remote) with minimum hops and traffic.

Index

Constants

This section is empty.

Variables

View Source
var ErrElementNotFound = errors.New("ldiff: element not found")

Functions

This section is empty.

Types

type Diff

type Diff interface {
	Remote
	// Set adds or update elements in container
	Set(elements ...Element)
	// RemoveId removes element by id
	RemoveId(id string) error
	// Diff makes diff with remote container
	Diff(ctx context.Context, dl Remote) (newIds, changedIds, removedIds []string, err error)
	// Elements retrieves all elements in the Diff
	Elements() []Element
	// Element returns an element by id
	Element(id string) (Element, error)
	// Ids retrieves ids of all elements in the Diff
	Ids() []string
	// Hash returns hash of all elements in the diff
	Hash() string
	// Len returns count of elements in the diff
	Len() int
	// DiffType returns type of diff
	DiffType() spacesyncproto.DiffType
}

Diff contains elements and can compare it with Remote diff

func New

func New(divideFactor, compareThreshold int) Diff

New creates precalculated Diff container

divideFactor - means how many hashes you want to ask for once

it must be 2 or greater
normal value usually between 4 and 64

compareThreshold - means the maximum count of elements remote diff will send directly

if elements under range will be more - remote diff will send only hash
it must be 1 or greater
normal value between 8 and 64

Less threshold and divideFactor - less traffic but more requests

type DiffContainer added in v0.3.11

type DiffContainer interface {
	DiffTypeCheck(ctx context.Context, typeChecker RemoteTypeChecker) (needsSync bool, diff Diff, err error)
	InitialDiff() Diff
	PrecalculatedDiff() Diff
	Set(elements ...Element)
	RemoveId(id string) error
}

func NewDiffContainer added in v0.3.11

func NewDiffContainer(divideFactor, compareThreshold int) DiffContainer

type Element

type Element struct {
	Id   string
	Head string
}

Element of data

type Range

type Range struct {
	From, To uint64
	Elements bool
	Limit    int
}

Range request to get RangeResult

type RangeResult

type RangeResult struct {
	Hash     []byte
	Elements []Element
	Count    int
}

RangeResult response for Range

type Remote

type Remote interface {
	// Ranges calculates given ranges and return results
	Ranges(ctx context.Context, ranges []Range, resBuf []RangeResult) (results []RangeResult, err error)
}

Remote interface for using in the Diff

type RemoteTypeChecker added in v0.3.11

type RemoteTypeChecker interface {
	DiffTypeCheck(ctx context.Context, diffContainer DiffContainer) (needsSync bool, diff Diff, err error)
}

Directories

Path Synopsis
Package mock_ldiff is a generated GoMock package.
Package mock_ldiff is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL