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

docs(iroh-bytes): Improve range-spec docs #1372

Merged
merged 14 commits into from
Aug 23, 2023
Merged

docs(iroh-bytes): Improve range-spec docs #1372

merged 14 commits into from
Aug 23, 2023

Conversation

flub
Copy link
Contributor

@flub flub commented Aug 17, 2023

Description

This attempts to improve the range-spec docs to be a bit more verbose.

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates if relevant.
  • Tests if relevant.

This attempts to improve the range-spec docs to be a bit more verbose.
@flub flub marked this pull request as ready for review August 17, 2023 15:13
@flub
Copy link
Contributor Author

flub commented Aug 17, 2023

Now ready for full review. Please check correctness (some examples have changed!) and how easy it is to understand.

@divagant-martian divagant-martian self-assigned this Aug 17, 2023
Copy link
Contributor Author

@flub flub left a comment

Choose a reason for hiding this comment

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

LGTM I think, but let's wait for @rklaehn

@divagant-martian
Copy link
Contributor

divagant-martian commented Aug 21, 2023

for the record I tried to make the examples doc test ones, but gave up trying to compare the objects. Something like

use range_collections::range_set::RangeSetRange;
let spec = RangeSpec::from([2, 5, 3, 1]);
let ranges = spec.to_chunk_ranges();
let first_range: RangeSet2<_> = (ChunkNum(2)..ChunkNum(7)).into();
let second_range: RangeSet2<_> = (ChunkNum(10)..ChunkNum(11)).into();
let mut iter = ranges.iter();
assert_eq!(iter.next(), Some(first_range)); // didn't find a way to create two comparable objects
assert_eq!(iter.next(), Some(second_range)); // so gave up on that 
assert_eq!(iter.next(), None);

I think the current state is a really good improvement tbh, a doc test would make it clearer but it's not necessary

@@ -97,27 +112,45 @@ impl fmt::Debug for RangeSpec {
}
}

/// A compressed sequence of range specs
/// A chunk range specification for a collection of blobs.
Copy link
Contributor

Choose a reason for hiding this comment

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

"sequence of blobs"? You could use this for specifying ranges for any sequence of blobs, and calling it a sequence makes it clear why the thing is called RangeSpec Seq ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

///
/// default is what to use if the children of this RequestRangeSpec are empty.
/// The first item yielded is the [`RangeSpec`] for the first blob in the collection, the
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not correct. The first item yielded is the RangeSpec for the collection itself.

This is needed e.g. when you already have the collection and don't want to download it again.

But as I mentioned above, I think it is best to leave out the notion of collections and just describe this as a sequence of RangeSets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so i agree that "sequence of blobs" is probably a better description since when using "collection" you already are assuming special treatment of the first item/blob in the collection, which is not what I intended. I fear "sequence of RangeSets" is a bit too abstract.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, how about this: we remove collection / children from both the docs and the API, and then add another section where we describe where a RangeSpecSeq is used in the case of collections and children (in a subsequent PR)?

I also would like to make the canonical repr mandatory. Without that you can't have structural equality. But better in the next PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good

@rklaehn
Copy link
Contributor

rklaehn commented Aug 21, 2023

I think we should probably make a note somewhere why the thing is called RangeSet2. So basically in a few places we accept generic RangeSets. RangeSet2 is just a RangeSet that can contain up to 2 boundaries without allocating.

@flub
Copy link
Contributor Author

flub commented Aug 21, 2023

I think we should probably make a note somewhere why the thing is called RangeSet2. So basically in a few places we accept generic RangeSets. RangeSet2 is just a RangeSet that can contain up to 2 boundaries without allocating.

this would be great to add!

@flub
Copy link
Contributor Author

flub commented Aug 22, 2023

@rklaehn one question not yet answered is the RangeSpecSeq::single API (this was only mentioned in chat). Why does it return an offset if it checks that this offset is 0 anyway?

@rklaehn
Copy link
Contributor

rklaehn commented Aug 23, 2023

@rklaehn one question not yet answered is the RangeSpecSeq::single API (this was only mentioned in chat). Why does it return an offset if it checks that this offset is 0 anyway?

I think it is just a bug. It should return the offset of the single non-zero element, instead it only returns Some only if the offset of the single non-zero element is 0, which makes it redundant.

But maybe merge this and we can do a second pass?

@flub flub enabled auto-merge August 23, 2023 13:22
@flub flub added this pull request to the merge queue Aug 23, 2023
Merged via the queue into main with commit 2076bfb Aug 23, 2023
@flub flub deleted the flub/rangespec-docs branch August 23, 2023 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants