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

refactor(common): 3879 change return types for insert and remove in numerated intervals tree #4454

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ecol-master
Copy link
Contributor

Resolves #3879

  • added boolean returns types for IntervalTree methods insert and remove
  • insert: return false if interval is non-empty and for each pintervalpself, In other cases - true
  • remove: return false if interval is not empty and for each pintervalpself. In other cases - true
  • modify tests for these methods

@grishasobol

@grishasobol grishasobol added the A0-pleasereview PR is ready to be reviewed by the team label Jan 20, 2025
@grishasobol grishasobol added A4-insubstantial Not too important PR Q1-easy and removed A4-insubstantial Not too important PR labels Jan 20, 2025
@grishasobol grishasobol changed the title 3879 change return types for insert and remove in numeratedintervalstree refactor(common): 3879 change return types for insert and remove in numerated intervals tree Jan 20, 2025
Copy link
Member

@grishasobol grishasobol left a comment

Choose a reason for hiding this comment

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

Fine, but consider to change a little the behaviour in case of empty intervals

pub fn insert<I: Into<IntervalIterator<T>>>(&mut self, interval: I) {
///
/// Returns:
/// - false: if `interval` is non-empty and for each `p` ∈ `interval` ⇒ `p` ∈ `self`
Copy link
Member

Choose a reason for hiding this comment

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

append info that it's before insertion

let Some((start, end)) = Self::into_start_end(interval) else {
// Empty interval - nothing to insert.
return;
return true;
Copy link
Member

Choose a reason for hiding this comment

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

I think (may be I'm not right) that it's simplier to define the return as:

Returns whether at least one point was added in `self`.

In that case we should return false here because of trying to add empty interval.

let Some((start, end)) = Self::into_start_end(interval) else {
// Empty interval - nothing to remove.
return;
return true;
Copy link
Member

Choose a reason for hiding this comment

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

The same as in insert - may be better to define return as:

Returns whether at least one point was removed from `self`.

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe better for both insert and remove:

Returns whether `self` has been changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In core/src/memory.rs we will return InvalidFree error if remove method returns false:

if page < self.static_pages || page >= self.max_pages || !self.allocations.remove(page){
    Err(AllocError::InvalidFree(page))
}

But in my opinion empty free empty free is allowed (like free(NULL) in C). If it is not allows i will agree to change the functions behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

we also allow to remove empty interval. But return in that case that nothing has been removed . free in C does not return anything anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-pleasereview PR is ready to be reviewed by the team Q1-easy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change return types for insert and remove in numerated::IntervalsTree
2 participants