indexing

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrReachedChainEnd = errors.NotFound.With("reached the end of the chain")
View Source
var ErrReachedChainStart = errors.NotFound.With("reached the start of the chain")
View Source
var ErrTargetDoesNotExist = errors.NotFound.With("target does not exist")

Functions

func GetDataEntry

func GetDataEntry(batch *database.Batch, txnHash []byte) (protocol.DataEntry, *url.TxID, *url.TxID, error)

func LoadIndexEntryFromEnd

func LoadIndexEntryFromEnd(c *database.Chain2, offset uint64) (*protocol.IndexEntry, error)

LoadIndexEntryFromEnd loads the Nth-to-last entry from an index chain. LoadIndexEntryFromEnd will panic if the offset is zero. If the offset is greater than the chain height, LoadIndexEntryFromEnd returns nil, nil.

func LoadLastTwoIndexEntries

func LoadLastTwoIndexEntries(chain *database.Chain2) (last, nextLast *protocol.IndexEntry, err error)

LoadLastTwoIndexEntries loads the last and next to last entries of the index chain.

func ReceiptForAccountState

func ReceiptForAccountState(partition config.NetworkUrl, batch *database.Batch, account *database.Account) (block *protocol.IndexEntry, receipt *merkle.Receipt, err error)

func ReceiptForChainEntry

func ReceiptForChainEntry(net *config.Describe, batch *database.Batch, account *database.Account, hash []byte, entry *database.TransactionChainEntry) (*protocol.IndexEntry, *merkle.Receipt, error)

func ReceiptForChainIndex

func ReceiptForChainIndex(partition config.NetworkUrl, batch *database.Batch, c *database.Chain2, index int64) (*protocol.IndexEntry, uint64, *merkle.Receipt, error)

func SearchIndexChain

func SearchIndexChain(chain *database.Chain, index uint64, mode MatchMode, find IndexChainSearchFunction) (uint64, *protocol.IndexEntry, error)

SearchIndexChain searches along an index chain using the given search function. The search starts from the given index and proceeds forwards or backwards along the chain depending on the result of the search function.

func SearchIndexChain2 added in v1.2.10

func SearchIndexChain2(chain *database.Chain2, index uint64, mode MatchMode, find IndexChainSearchFunction) (uint64, *protocol.IndexEntry, error)

SearchIndexChain2 is a wrapper for SearchIndexChain that accepts database.Chain2.

Types

type DataIndexer

type DataIndexer struct {
	*database.AccountData
	// contains filtered or unexported fields
}

func Data

func Data(batch *database.Batch, account *url.URL) *DataIndexer

func (*DataIndexer) Count

func (d *DataIndexer) Count() (uint64, error)

func (*DataIndexer) Entry

func (d *DataIndexer) Entry(i uint64) ([]byte, error)

Entry returns the entry hash for the given index.

func (*DataIndexer) GetLatest

func (d *DataIndexer) GetLatest() (index uint64, entryHash, txnHash []byte, err error)

GetLatest returns the last entry.

func (*DataIndexer) GetLatestEntry

func (d *DataIndexer) GetLatestEntry() (protocol.DataEntry, *url.TxID, *url.TxID, error)

func (*DataIndexer) Put

func (d *DataIndexer) Put(entryHash, txnHash []byte) error

func (*DataIndexer) Transaction

func (d *DataIndexer) Transaction(entryHash []byte) ([]byte, error)

Transaction returns the transaction hash for the given entry hash.

type DirectoryIndexer

type DirectoryIndexer struct {
	values.Set[*url.URL]
}

func Directory

func Directory(batch *database.Batch, account *url.URL) *DirectoryIndexer

func (*DirectoryIndexer) Count

func (d *DirectoryIndexer) Count() (uint64, error)

func (*DirectoryIndexer) Get

func (d *DirectoryIndexer) Get(i uint64) (*url.URL, error)

type IndexChainSearchFunction

type IndexChainSearchFunction func(*protocol.IndexEntry) SearchDirection

IndexChainSearchFunction determines the direction an index chain search should proceed.

func SearchIndexChainByAnchorBounds

func SearchIndexChainByAnchorBounds(lowerBound, upperBound uint64) IndexChainSearchFunction

SearchIndexChainByAnchorBounds returns a search function that searches an index chain for an entry with an anchor in the given bounds (inclusive).

func SearchIndexChainByBlock

func SearchIndexChainByBlock(blockIndex uint64) IndexChainSearchFunction

SearchIndexChainByBlock returns a search function that searches an index chain for the given block index.

func SearchIndexChainByRootIndexIndex

func SearchIndexChainByRootIndexIndex(targetRootIndexIndex uint64) IndexChainSearchFunction

SearchIndexChainByRootIndexIndex returns a search function that searches an index chain for the given RootIndexIndex.

func SearchIndexChainBySource

func SearchIndexChainBySource(targetSource uint64) IndexChainSearchFunction

SearchIndexChainBySource returns a search function that searches an index chain for the given source.

type MatchMode

type MatchMode int

MatchMode determines how results are returned from a search.

const (
	// MatchExect returns only an exact match.
	MatchExact MatchMode = iota

	// MatchBefore returns the element before the target if the target cannot be
	// found.
	MatchBefore

	// MatchAfter returns the element after the target if the target cannot be
	// found.
	MatchAfter
)

type SearchDirection

type SearchDirection int

SearchDirection represents a direction to search along a linear index.

const (
	// SearchComplete is returned when the search is complete.
	SearchComplete SearchDirection = iota

	// SearchForward is returned when the search should proceed forwards along
	// the index.
	SearchForward

	// SearchBackward is returned when the search should proceed backwards along
	// the index.
	SearchBackward
)

type TransactionChainIndexer

type TransactionChainIndexer struct {
	values.Set[*database.TransactionChainEntry]
}

TransactionChainIndexer indexes account chains against a transaction.

func TransactionChain

func TransactionChain(batch *database.Batch, txid []byte) *TransactionChainIndexer

TransactionChain returns a transaction chain indexer.

Jump to

Keyboard shortcuts

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