vgteam / libhandlegraph

Library for the Handle Graph abstraction
MIT License
21 stars 5 forks source link

Empty handle #22

Open glennhickey opened 5 years ago

glennhickey commented 5 years ago

This is probably a dumb question, but what's the best way to check if a handle is empty? This comes up, for example, when replacing code of the type

Node* node = nullptr;
// do some stuff
if (node != nullptr) {
   // more stuff
}

Obviously, I can do the same thing with a handle_t*, but that's pretty ugly. I'd rather use handle_t directly. Is there a way to do this?

ekg commented 5 years ago

There aren't really empty handles. In my context I'm using the entire namespace. 0 is a valid handle. You might want to do something different.

On Thu, May 23, 2019, 18:18 Glenn Hickey notifications@github.com wrote:

This is probably a dumb question, but what's the best way to check if a handle is empty? This comes up, for example, when replacing code of the type

Node* node = nullptr; // do some stuff if (node != nullptr) { // more stuff }

Obviously, I can do the same thing with a handle_t*, but that's pretty ugly. I'd rather use handle_t directly. Is there a way to do this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vgteam/libhandlegraph/issues/22?email_source=notifications&email_token=AABDQEJZTC42GW7SO7GXVMTPW27WVA5CNFSM4HPIGHWKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GVQG7MQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDQEMM3N53DRLVNM5WD2LPW27WVANCNFSM4HPIGHWA .

glennhickey commented 5 years ago

Any suggestions? Can I switch from handles to id's and assume id==0 is a null id?

On Thu, May 23, 2019 at 12:56 PM Erik Garrison notifications@github.com wrote:

There aren't really empty handles. In my context I'm using the entire namespace. 0 is a valid handle. You might want to do something different.

On Thu, May 23, 2019, 18:18 Glenn Hickey notifications@github.com wrote:

This is probably a dumb question, but what's the best way to check if a handle is empty? This comes up, for example, when replacing code of the type

Node* node = nullptr; // do some stuff if (node != nullptr) { // more stuff }

Obviously, I can do the same thing with a handle_t*, but that's pretty ugly. I'd rather use handle_t directly. Is there a way to do this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/vgteam/libhandlegraph/issues/22?email_source=notifications&email_token=AABDQEJZTC42GW7SO7GXVMTPW27WVA5CNFSM4HPIGHWKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GVQG7MQ , or mute the thread < https://github.com/notifications/unsubscribe-auth/AABDQEMM3N53DRLVNM5WD2LPW27WVANCNFSM4HPIGHWA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vgteam/libhandlegraph/issues/22?email_source=notifications&email_token=AAG373WTK7ZCDLO2UU7A6JDPW3EDRA5CNFSM4HPIGHWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWC25OY#issuecomment-495300283, or mute the thread https://github.com/notifications/unsubscribe-auth/AAG373U5SJ6U7HV24FYEWNLPW3EDRANCNFSM4HPIGHWA .

glennhickey commented 5 years ago

I'll just add, this seems like a hole in the interface. Is it unreasonable to have a null_handle constant value somewhere and ask all implementations to never use it for a valid handle? Adding this wouldn't affect existing client code nor, I suspect, most graph implementations.

ekg commented 5 years ago

I guess that's fine. What would produce it?

It's kind of like the one past end step iterator things we have. There, we need a way to signal that a path is done.

On Thu, May 23, 2019, 19:18 Glenn Hickey notifications@github.com wrote:

I'll just add, this seems like a hole in the interface. Is it unreasonable to have a null_handle constant value somewhere and ask all implementations to never use it for a valid handle? Adding this wouldn't affect existing client code nor, I suspect, most graph implementations.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vgteam/libhandlegraph/issues/22?email_source=notifications&email_token=AABDQELRRM6OA3PVWEN5HODPW3GWNA5CNFSM4HPIGHWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWC4XGY#issuecomment-495307675, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDQEJ3UEPL74SNG35APB3PW3GWNANCNFSM4HPIGHWA .

glennhickey commented 5 years ago

I think the fact that we can declare all these handles without initializing them means we should be able to check if they're null/empty. For regular handle's I was just thinking something simple as #23.