Skip to content

Conversation

@sentrip
Copy link
Contributor

@sentrip sentrip commented Feb 9, 2023

No description provided.

@sentrip
Copy link
Contributor Author

sentrip commented Feb 9, 2023

Ah, in the docs I renamed Heuristicx86 to x86 and didn't run tests again. I fixed it, but I guess that can be combined into the commit that renames the trait/method

@BurntSushi
Copy link
Owner

Yeah when you make changes, for a small PR like this, just keep everything in one commit. You can force push.

@BurntSushi
Copy link
Owner

Hmmm can you submit another PR with the default type parameter approach? I think I'd still prefer that route if it can be made to work. Just wanted to look at it and play with it myself.

@sentrip sentrip force-pushed the master branch 2 times, most recently from 482d61d to ebf41ed Compare February 9, 2023 16:57
@sentrip
Copy link
Contributor Author

sentrip commented Feb 9, 2023

Yes I will upload it now, and thanks for the tip!

@sentrip
Copy link
Contributor Author

sentrip commented Feb 9, 2023

All the checks seem to pass, all that is left here is the names. My favorites are RareBytes/build_with_ranker, but I will wait for you to check the implementations out. If you like this one then let me know what to change the names to.

BurntSushi pushed a commit that referenced this pull request Jul 11, 2023
This makes it possible for the caller to provide their own ranking
function for individual bytes. This can potentially speed up searches if
one has a better guess than the default for the frequency distribution
of bytes in a particular haystack.

There is a lot of ceremony here, and it basically boils down to
supporting this in no-std no-alloc configurations. I was tempted to
just require alloc for this sort of thing and ask for something like
`Arc<dyn Fn(u8) -> u8>`, but that would require some ceremony of its
own internally to deal with in the no-alloc case. And forcing an
allocation for every searcher construction that uses a customer ranker
feels like bad juju to me.

Another choice would be to just ask for a `fn(u8) -> u8`, but this makes
the case of "I analyzed a haystack at runtime to build my ranker" more
difficult. Not impossible. But annoying.

Yet another choice was to add the trait as in this commit, and then add
it as a new type parameter to `FinderBuilder`. I believe this would
work, but it requires complicating the public API even more and imposes
constraints on the trait (for example, it would want to be `Clone` at
least in order to avoid backwards incompatible changes in the
`FinderBuilder` API). There's also just generally more ceremony with
having to add a type parameter everywhere. Since we only need the
ranking function at searcher construction time, we can ask for it at the
time of construction and then get rid of it, thus avoiding it infecting
everything else.

Fixes #117, Closes #118, Closes #119
BurntSushi pushed a commit that referenced this pull request Jul 11, 2023
This makes it possible for the caller to provide their own ranking
function for individual bytes. This can potentially speed up searches if
one has a better guess than the default for the frequency distribution
of bytes in a particular haystack.

There is a lot of ceremony here, and it basically boils down to
supporting this in no-std no-alloc configurations. I was tempted to
just require alloc for this sort of thing and ask for something like
`Arc<dyn Fn(u8) -> u8>`, but that would require some ceremony of its
own internally to deal with in the no-alloc case. And forcing an
allocation for every searcher construction that uses a customer ranker
feels like bad juju to me.

Another choice would be to just ask for a `fn(u8) -> u8`, but this makes
the case of "I analyzed a haystack at runtime to build my ranker" more
difficult. Not impossible. But annoying.

Yet another choice was to add the trait as in this commit, and then add
it as a new type parameter to `FinderBuilder`. I believe this would
work, but it requires complicating the public API even more and imposes
constraints on the trait (for example, it would want to be `Clone` at
least in order to avoid backwards incompatible changes in the
`FinderBuilder` API). There's also just generally more ceremony with
having to add a type parameter everywhere. Since we only need the
ranking function at searcher construction time, we can ask for it at the
time of construction and then get rid of it, thus avoiding it infecting
everything else.

Fixes #117, Closes #118, Closes #119
BurntSushi pushed a commit that referenced this pull request Jul 11, 2023
This makes it possible for the caller to provide their own ranking
function for individual bytes. This can potentially speed up searches if
one has a better guess than the default for the frequency distribution
of bytes in a particular haystack.

There is a lot of ceremony here, and it basically boils down to
supporting this in no-std no-alloc configurations. I was tempted to
just require alloc for this sort of thing and ask for something like
`Arc<dyn Fn(u8) -> u8>`, but that would require some ceremony of its
own internally to deal with in the no-alloc case. And forcing an
allocation for every searcher construction that uses a customer ranker
feels like bad juju to me.

Another choice would be to just ask for a `fn(u8) -> u8`, but this makes
the case of "I analyzed a haystack at runtime to build my ranker" more
difficult. Not impossible. But annoying.

Yet another choice was to add the trait as in this commit, and then add
it as a new type parameter to `FinderBuilder`. I believe this would
work, but it requires complicating the public API even more and imposes
constraints on the trait (for example, it would want to be `Clone` at
least in order to avoid backwards incompatible changes in the
`FinderBuilder` API). There's also just generally more ceremony with
having to add a type parameter everywhere. Since we only need the
ranking function at searcher construction time, we can ask for it at the
time of construction and then get rid of it, thus avoiding it infecting
everything else.

Fixes #117, Closes #118, Closes #119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants