Package no.digipost.util.bisect
Class BisectSearch<T>
java.lang.Object
no.digipost.util.bisect.BisectSearch<T>
- Type Parameters:
T- the type of the values/objects which are searched for
Implementation of bisection search algorithm, which can be used
to find objects having any quantifiable properties one would evaluate
as approaching a certain ideal target value. This can e.g. be the binary/serialized
size
of an image generated from different dimensions, or a document with differenct amount of pages.
To specify a search, one starts by defining the "source" of the search space,
using the from(Suggester) method.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> BisectSearch.Builder<T>Define the "source" of the search, how to generate suggested values which will be evaluated.maximumAttempts(int maxAttempts) Specify how many suggestions the search should attempt before yielding a result.Perform a search for a value using a givenEvaluator
-
Method Details
-
from
Define the "source" of the search, how to generate suggested values which will be evaluated.- Parameters:
suggester- theSuggestiongenerator function- Returns:
- a new builder which is used for further specification of the search
-
maximumAttempts
Specify how many suggestions the search should attempt before yielding a result.- Parameters:
maxAttempts- the amount of suggestions to attempt- Returns:
- the new
BisectSearchinstance
-
searchFor
Perform a search for a value using a givenEvaluator- Parameters:
evaluator- evaluates if a suggested value istoo low,too high, orfound.- Returns:
- the resulting value from the search, which has not necessarily been evaluated as
found, but was the last suggested value before reaching themaximum allowed attempts.
-