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

Set UNIQUE property into index objects #849

Merged
merged 3 commits into from
Aug 19, 2021
Merged

Conversation

LaurentiuCristofor
Copy link
Contributor

@LaurentiuCristofor LaurentiuCristofor commented Aug 19, 2021

Basic functionality here is that the unique property is now set into index objects for later querying.

Some cleanup:

  • I moved all "pre-commit" code into the pre-commit method. An assert was also moved there so it doesn't have to be repeated in multiple places.
  • I removed some redundant fields from the index_t class which could just be inherited from base_index_t.
  • I changed the factory method to take an index_view_t object so that we don't have to pass multiple index properties one by one.
  • Some minor editing changes for breaking long lines and such.

{
case catalog::index_type_t::range:
return get_indexes()->emplace(
index_id,
std::make_shared<range_index_t, gaia_id_t>(static_cast<gaia_id_t&&>(index_id)))
std::make_shared<range_index_t, gaia_id_t, bool>(
static_cast<gaia_id_t&&>(index_id), static_cast<bool&&>(is_unique)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you need to move a bool? (I see the same thing happens for gaia_id_t)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it's make_shared's way of taking ownership of the arguments. I've tried to not do the casts and got conversion errors about not knowing how to implicitly convert to bool&&.

This is C++ supposed to make things robust and easy to understand, I guess. ;) Very powerful, but easy to get wrong.

At least this error was easy, but I was getting a bunch of confusing errors that were actually coming from missing that include in the header file. It's only after trying to fix them several times that I realized that at the end they were complaining of not knowing what index_view_t was. But before they kept complaining about the definition of this method not matching any declaration. Now I understand that they defaulted the unknown type to something else and then they couldn't match the definition, but they should have reported the unknown type first, not the result of their assumptions. Even simple stuff is made complicated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I guess that make_shared needs a "universal reference" which looks like &&, but is apparently not to be confused with an "rvalue reference", which looks exactly the same! Simplicity FTW! Even though I guess I should know this stuff, I'm just not sure how many brain cells I want to devote to this trivia.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW here's a good article on universal references:
https://eli.thegreenplace.net/2014/perfect-forwarding-and-universal-references-in-c

And also an item in Effective Modern C++, but I don't know how to find it online.

Copy link
Contributor

Choose a reason for hiding this comment

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

Getting on my Rust soapbox, I would never call Rust a simple language, but I don't think it has the same degree of accidental complexity as C++ (as shown here), and it has much better error messages!

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's make_shared's way of taking ownership of the arguments. I've tried to not do the casts and got conversion errors about not knowing how to implicitly convert to bool&&.

Anyway, could you try using std::forward() here instead of the explicit casts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, perfect forwarding! I did read about that when I was messing with templates. Yes, I think that std::forward will make it much clearer. Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. Thanks for the reference.

Copy link

@yiwen-wong yiwen-wong left a comment

Choose a reason for hiding this comment

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

LGTM

@LaurentiuCristofor LaurentiuCristofor merged commit 4971fdd into master Aug 19, 2021
@LaurentiuCristofor LaurentiuCristofor deleted the laur_index_unique branch August 19, 2021 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants