rtable

package
v0.0.0-...-80327fb Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKBucketNotExist = errors.New("kbucket: no such node")
	ErrKBucketFull     = errors.New("kbucket: bucket full")
	ErrKBucketEmpty    = errors.New("kbucket: bucket empty")
)

Standard errors a KBucket can give.

View Source
var (
	ErrRTableFull   = errors.New("rtable: table full")
	ErrRTableClosed = errors.New("rtable: closed")
)

Standard errors a RTable can give.

Functions

This section is empty.

Types

type KBucket

type KBucket interface {
	// Load node by ID. If no node exists with that ID in the bucket, return
	// ErrKBucketNotFound.
	Load(id []byte) (*core.NodeTriple, error)

	// Store or update node. If the bucket is full, return ErrKBucketFull.
	Store(n *core.NodeTriple) error

	// Load oldest node in bucket.
	Oldest() (*core.NodeTriple, error)

	// Remove node by ID.
	Remove(id []byte) error

	// Append bucket contents to slice s, in order of most recent first,
	// until s is at most length n.
	Append(s []*core.NodeTriple, n int) ([]*core.NodeTriple, error)

	// Close the KBucket.
	io.Closer
}

KBucket stores nodes in an LRU cache. KBucket is not safe for concurrent use.

func NewKBucket

func NewKBucket(file string, k int) (KBucket, error)

NewKBucket constructs a SQLite3-backed KBucket.

type RTable

type RTable interface {
	// Store a node. If the RTable is full, return ErrRTableFull.
	Store(n *core.NodeTriple) error

	// Oldest node in the id's corresponding bucket.
	Oldest(id []byte) (*core.NodeTriple, error)

	// Replace replace the oldest node with n.
	ReplaceOldest(n *core.NodeTriple) error

	// Closest finds at most k closest, unequal nodes to id.
	Closest(id []byte, k int) ([]*core.NodeTriple, error)

	// Close the RTable. All future operations return ErrRtableClosed.
	io.Closer
}

RTable stores nodes. RTable is safe for concurrent use.

func NewRTable

func NewRTable(self []byte, k int, dir string) (RTable, error)

NewRTable creates a file-based RTable.

Jump to

Keyboard shortcuts

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