parallelsearch

package
v0.0.0-...-a2d27ab Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParallelSearch

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

ParallelSearch implements a breadth-first search of a tree of searchable "nodes" This is done in parallel using a FIFO worker pool.

func New

func New(poolSize int, depthLimit int, searchLimit int) *ParallelSearch

New creates a new parallel search. The poolSize determines the number of simultaneous workers looking for search results. The depthLimit restricts how deep we allow the breadth-first search to proceed. The searchLimit determines how many results we are looking for before stopping.

func (*ParallelSearch) Start

func (self *ParallelSearch) Start(searchables ...Searchable)

Start will initiate a new search with the given starting "node" or "nodes". It will announce the completion of each depth/layer as it proceeds. NOTE: This method should only be called once to avoid duplicate depth announcement.

func (*ParallelSearch) WaitForFound

func (self *ParallelSearch) WaitForFound() []Searchable

WaitForFound will wait until either we have found searchLimit results or we have reached the depthLimit with no more "nodes" to consider. Either way the results found (if any) will be sorted by score and returned.

type Searchable

type Searchable interface {
	Search(onNext func(Searchable))
	IsFound() bool
	Score() int
}

Searchable is a "node" in a search tree in which we are looking for something.

Jump to

Keyboard shortcuts

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