Skip to content

gaps documentation is ambiguous w/r/t empty ranges #38

@acully-vmware

Description

@acully-vmware

The documentation says:

    /// Gets an iterator over all the maximally-sized ranges
    /// contained in `outer_range` that are not covered by
    /// any range stored in the map.

This indicates that gaps will find holes in the range-map that intersect outer_range... We had an engineer check if a range was completely covered by the RangeMap by if range_map.gaps(&check_range).next().is_none() {...}, which seems like it should work (based on the documentation), but broke in our case, because the gaps iterator can return empty ranges:

    #[test]
    fn adjacent_no_coalesce() {
        let mut range_map: RangeMap<u32, bool> = RangeMap::new();
        range_map.insert(2..5, false);
        range_map.insert(5..8, true);
        let outer_range = 2..8;
        let mut gaps = range_map.gaps(&outer_range);
        // Should yield an empty range.
        let gap = gaps.next();
        assert_eq!(gap, Some(5..5));
        assert_eq!(gap.unwrap().is_empty(), true);
    }

I think the current behavior is good, but the documentation could be improved to better indicate that gaps can return empty ranges.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions