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

subseq with sub interval missing zero length spans #1181

Open
scholtzan opened this issue Apr 23, 2019 · 1 comment
Open

subseq with sub interval missing zero length spans #1181

scholtzan opened this issue Apr 23, 2019 · 1 comment
Labels

Comments

@scholtzan
Copy link
Member

scholtzan commented Apr 23, 2019

I'm running into an odd issue with subseq when using it to get a subsequence of Spans. If the passed interval is smaller than the total length of the spans, then it's missing all the zero length spans.

I hope the following test clarifies what I am trying to describe here:

    #[test]
    fn subseq_sub_interval() {
        let mut sb = SpansBuilder::new(18);
        sb.add_span(9..9, 0);
        sb.add_span(11..12, 0);
        let spans = sb.build();

        assert_eq!(spans.iter().count(), 2);
        assert_eq!(spans.subseq(0..18).iter().count(), 2);  // all good here
        assert_eq!(spans.subseq(0..17).iter().count(), 2);  // ERROR: the 9..9 interval is missing, but the 11..12 interval is there
    }

I think this is a bug?

@cmyr
Copy link
Member

cmyr commented Apr 29, 2019

Hmm, this is interesting. I think there actually was a design decision to not include zero-length spans, because they were meaningless in the context of the original use of this data structure (syntax highlighting) and are arguably meaningless in the context of an interval tree. Maybe @raphlinus has some thoughts here? the design for annotations does rely on being able to represent annotations that are associated with zero-length spans (such as a deletion in version control) so there's a clear case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants