Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FmIndex breaks if text is empty string #22

Open
faassen opened this issue Jan 9, 2025 · 3 comments
Open

FmIndex breaks if text is empty string #22

faassen opened this issue Jan 9, 2025 · 3 comments

Comments

@faassen
Copy link
Collaborator

faassen commented Jan 9, 2025

FmIndex currently breaks with an error if the text supplied is the empty string (an underflow error).

I also tried with a string just with a \0 in it but had a different error:

sampling level L must satisfy 2^L < text_len (L = 2, text_len = 4)

@faassen
Copy link
Collaborator Author

faassen commented Jan 9, 2025

The failing test is this:

    #[test]
    fn test_empty() {
        let text = "".to_string().into_bytes();
        let fm_index = FMIndex::new(
            text,
            IdConverter::new(256),
            SuffixOrderSampler::new().level(2),
        );
        assert_eq!(fm_index.search_backward("").count(), 0);
    }

I notice that if I set level to 0, it does work. As I asked in #23, I don't really understand level or how to set it to a sane number.

@faassen
Copy link
Collaborator Author

faassen commented Jan 9, 2025

Oh, wait, it doesn't work if I set it to empty with level(0), as I get the underflow error described originally.

@faassen
Copy link
Collaborator Author

faassen commented Jan 10, 2025

For my use case an empty string is okay to ignore, as I always end them with \0 anyway. But I think we should give better feedback if it's used that way.

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

No branches or pull requests

1 participant