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

fix issue 17519 - RedBlackTree doesn't like const/immutable elements #5492

Merged
merged 1 commit into from Jun 18, 2017

Conversation

aG0aep6G
Copy link
Contributor

No description provided.

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
17519 RedBlackTree doesn't like const/immutable elements

@aG0aep6G aG0aep6G changed the base branch from master to stable June 17, 2017 22:01
@aG0aep6G aG0aep6G force-pushed the rbtree-immutable branch 4 times, most recently from 200ac35 to f90767f Compare June 17, 2017 22:52
Copy link
Member

@PetarKirov PetarKirov left a comment

Choose a reason for hiding this comment

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

Overall LGTM. After adding one line to the unittest, I'd be ok with merging.

@@ -1190,7 +1187,8 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
else
{
assert(ts.length == 5);
assert(ts.stableInsert(cast(Elem[])[7, 8, 6, 9, 10, 8]) == 5);
Elem[] elems = [7, 8, 6, 9, 10, 8];
assert(ts.stableInsert(elems) == 5);
Copy link
Member

Choose a reason for hiding this comment

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

This is only a stylistic change, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only a stylistic change, right?

It does the same, but the old version wasn't @safe.

Copy link
Member

Choose a reason for hiding this comment

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

I see (I missed the cast(Elem[]) last time).

@@ -801,9 +800,7 @@ if (is(typeof(binaryFun!less(T.init, T.init))))

static private Node allocate(Elem v)
{
auto result = allocate();
Copy link
Member

Choose a reason for hiding this comment

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

As far as I can see, the idea behind allocate() is to abstract the allocation mechanism. However, in practice it doesn't offer any flexibility, so we can even remove it. But that's better left for another PR.

Copy link
Member

Choose a reason for hiding this comment

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

The idea actually comes from the original library, where I had allocators.

Since this is inside the abstraction for allocation, it is OK, as once std.experimental.allocators is ready, this will get noticed.

Thanks for reviewing, I just logged in this morning to do so and approve, but you beat me to it.

Copy link
Member

Choose a reason for hiding this comment

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

I thought as much. Yeah, allocate immediately ringed a bell about plugging std.experimental.allocators in there to me too ;)

No problem, I'm glad that I can now effectively help :)

import std.algorithm.iteration : map;
static struct S { int* p; }
auto t3 = new RedBlackTree!(immutable S, (a, b) => *a.p < *b.p);
t3.insert([1, 2, 3].map!(x => immutable S(new int(x))));
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test that verifies that front can be fetched?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you add a test that verifies that front can be fetched?

Added an assert.

@PetarKirov
Copy link
Member

PetarKirov commented Jun 18, 2017

I've rebased the PR in order to squash the last commit and to restart CircleCI.

@PetarKirov
Copy link
Member

We're good on all testing fronts, so I'll go ahead and merge this.

@dlang-bot dlang-bot merged commit 173ccd8 into dlang:stable Jun 18, 2017
@aG0aep6G aG0aep6G deleted the rbtree-immutable branch June 18, 2017 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants