Skip to content

levenshtein: LevenshteinState, usize input distance#99

Open
MartinKavik wants to merge 1 commit intoBurntSushi:masterfrom
MartinKavik:lev-state
Open

levenshtein: LevenshteinState, usize input distance#99
MartinKavik wants to merge 1 commit intoBurntSushi:masterfrom
MartinKavik:lev-state

Conversation

@MartinKavik
Copy link

Motivation

  • Get distance while using Map::search_with_state.

Breaking changes

  • Levenshtein::new(query: &str, distance: u32) changed to distance: usize.
  • Original automaton state wrapped into LevenshteinState.

Tests

  • cargo test --features levenshtein
  • New code integrated into the WIP search library I'm working on.

Copy link
Owner

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Unfortunately, I don't think I will be merging breaking changes any time soon. :-(

pub fn new(
query: &str,
distance: u32,
distance: usize,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please say why? This seems trivial to me, and there is no way i'm going to put out a breaking change release for something like this given that I just released 0.4.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense in combination with the main change - LevenshteinState - to make all distance types consistent.


impl Automaton for Levenshtein {
type State = Option<usize>;
type State = Option<LevenshteinState>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but I'm not putting out a 0.5 release for this. :-(

Other ideas:

  • Keep this PR on hold until I'm ready for another breaking change release.
  • Create a new levenshtein automaton type.
  • Put this automaton in a new crate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would choose 1. option - on hold.
I can inline updated automaton into my project - I don't need it in the official fst release. So merge it when you want and I think this PR can be used also as an example when other users want to use automaton states.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks for understanding.

src/set.rs Outdated
("fozb".to_string(), Some(83)),
("foo".to_string(), Some(LevenshteinState { state_idx: 183, distance: Some(0) })),
("foob".to_string(), Some(LevenshteinState { state_idx: 123, distance: Some(1) })),
("fozb".to_string(), Some(LevenshteinState { state_idx: 83, distance: Some(2) })),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap lines to 79 columns inclusive.

Copy link
Author

@MartinKavik MartinKavik Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make all changed lines shorter.

FYI: When you add error_on_line_overflow = true and error_on_unformatted = true into rustfmt.toml and run cargo +nightly fmt --all, it reports 36 errors.

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