db

package
v0.0.0-...-9e25725 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotDir = errors.New("path is not a directory")

ErrNotDir is returned by CheckIsDir when the path is not a directory.

Functions

func CheckIsDir

func CheckIsDir(path string) error

CheckIsDir checks that the input path is a directory.

func ConfigPath

func ConfigPath() string

ConfigPath returns the path to the jump config file.

func DatabasePath

func DatabasePath() string

DatabasePath looks up the full path to the database file.

func Dump

func Dump(d Database, opts DumpOpts) interface{}

Dump returns a JSON serializable representation of the database weights.

func FindAutojumpDatabase

func FindAutojumpDatabase() string

Types

type Database

type Database interface {
	// Adjust the weight for a given path; weight can be positive or
	// negative.
	AdjustWeight(string, float64)

	// Does the database need to be saved?
	// TODO: this is a little hacky.
	Dirty() bool

	// Return the list of weights in the database.
	GetWeights() []Entry

	// Remove a path from the database.
	Remove(string)

	// Replace the current weights.
	Replace([]Entry)

	// Prune the database.
	Prune(int, []string)

	// Save the database to a writer.
	Save(io.Writer) error

	// Search for a query and find the best match.
	// TODO: allow this to return multiple results.
	Search(int, ...string) []Entry
}

Database represents the database.

func NewDatabase

func NewDatabase(r io.Reader, opts Options) Database

NewDatabase loads a database file.

type DumpOpts

type DumpOpts struct {
	Short bool // shorten output paths by abbreviating tilde
}

DumpOpts represents the dump options

type Entry

type Entry struct {
	Path      string    `json:"path"`
	Weight    float64   `json:"weight"`
	UpdatedAt time.Time `json:"time,string"`
}

Entry represents a database entry.

func LoadAutojumpDatabase

func LoadAutojumpDatabase(r io.Reader) ([]Entry, error)

LoadAutojumpDatabase loads the autojump database file

type GobDatabase

type GobDatabase struct {
	Weights weightMap // map of entry to weight
	// contains filtered or unexported fields
}

GobDatabase represents the database.

func NewGobDatabase

func NewGobDatabase(r io.Reader, opts Options) *GobDatabase

NewGobDatabase loads a database file.

func (*GobDatabase) AdjustWeight

func (d *GobDatabase) AdjustWeight(path string, weight float64)

AdjustWeight adjusts the weight of a path. The adjusted weight value is returned.

func (*GobDatabase) Dirty

func (d *GobDatabase) Dirty() bool

Dirty checks the dirty bit.

func (*GobDatabase) GetWeights

func (d *GobDatabase) GetWeights() []Entry

Dump prints the database to the specified writer.

func (*GobDatabase) Prune

func (d *GobDatabase) Prune(maxEntries int, excludePatterns []string)

Prune removes entries from the database that no longer exist.

func (*GobDatabase) Remove

func (d *GobDatabase) Remove(path string)

Remove removes a path from the database.

func (*GobDatabase) Replace

func (d *GobDatabase) Replace(entries []Entry)

Replace replaces the underlying weight map.

func (*GobDatabase) Save

func (d *GobDatabase) Save(w io.Writer) error

Save atomically saves the database.

func (*GobDatabase) Search

func (d *GobDatabase) Search(count int, needles ...string) []Entry

Search searches for the best database entry.

type Options

type Options struct {
	Debug        bool // debug setting
	TimeMatching bool // enable time matching
}

Options represent database options.

type Searcher

type Searcher struct {
	// contains filtered or unexported fields
}

Searcher implements the matching algorithm.

func NewSearcher

func NewSearcher(input weightMap, opts Options) *Searcher

NewSearcher creates a new searcher instance.

func (*Searcher) Best

func (s *Searcher) Best(count int) ([]Entry, []string)

Best returns the best matching entry that is actually a directory.

func (*Searcher) Search

func (s *Searcher) Search(needle string, cmp StringCompare, alpha float64)

Search searches for the needle in the input list using the given comparator, and modulates the weight by alpha.

type StringCompare

type StringCompare func(string, string) bool

StringCompare is a string comparison function.

type Weight

type Weight struct {
	Value     float64
	UpdatedAt time.Time
}

Weight represents a weight value with a timestamp.

func NewWeight

func NewWeight(val float64) Weight

NewWeight creates a new weight value with the current timestamp.

Jump to

Keyboard shortcuts

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