dictionary

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package dictionary represents storage for keeping an index vocabulary

Index

Constants

View Source
const (
	// NilValue is a value, that returns when an entry with the given
	// key doesn't exist
	NilValue = "<nil/>"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dictionary

type Dictionary interface {
	Iterable
	// Get returns value associated with a particular key
	Get(key Key) (Value, error)
	// Size returns the size of the dictionary
	Size() int
}

Dictionary is an abstract data type composed of a collection of (key, value) pairs

func BuildCDBDictionary

func BuildCDBDictionary(iterator Iterable, destinationPath string) (Dictionary, error)

BuildCDBDictionary is a helper for building a CDB dictionary from the sourcePath Saves the dictionary to destinationPath

func NewCDBDictionary

func NewCDBDictionary(r io.ReaderAt) (Dictionary, error)

NewCDBDictionary creates new instance of cdbDictionary

func NewInMemoryDictionary

func NewInMemoryDictionary(words []string) Dictionary

NewInMemoryDictionary creates new instance of inMemoryDictionary

func OpenCDBDictionary

func OpenCDBDictionary(path string) (Dictionary, error)

OpenCDBDictionary opens a dictionary from cdb file

func OpenRAMDictionary

func OpenRAMDictionary(path string) (dict Dictionary, err error)

OpenRAMDictionary opens a dictionary from the given path and stores items in RAM

type Iterable

type Iterable interface {
	// Iterate walks through each kv pair and calls iterator on it
	Iterate(iterator Iterator) error
}

Iterable tells that an implementation might be an object of for loop

type Iterator

type Iterator func(docID Key, word Value) error

Iterator is a callback that is called on each pair of the dictionary Returned error means that Iterable object should stop handling and start propagating the error upper

type Key

type Key = uint32

Key represents a key of an item

type Value

type Value = string

Value represents a value of an item

Jump to

Keyboard shortcuts

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