-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add support for non-throwing get
method like standard dict
.
#6
Conversation
@@ -29,6 +29,12 @@ cdef class BaseTrie: | |||
def __len__(self): | |||
return (<hattrie_t_*> self._trie).m | |||
|
|||
def get(self, bytes key, int value=-1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think default value shouldn't be limited to int. It is an unnecessary type check, and it even has a small performance cost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it would be weird to allow it to be non-int since the current Trie type only allows int values.
I'd be happy to change it if you want to allow storing arbitrary types in the Trie. I actually mentioned this as a desirable feature in #7. If you go ahead and merge this PR, I'd be happy to work towards getting full non-int functionality in a separate PR; although, I may need a little help as I'm not that familiar with Cython.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it is a bit weird to return non-int, but should we pay a performance cost to actively prevent users from doing this? We can still have -1 as a default, but allow users to use any other value (e.g. None) if they want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you just want me to drop the type declaration, that sounds fine.
+1 to this feature. |
Ok, I dropped the |
Thanks! |
Add support for non-throwing `get` method like standard `dict`.
No description provided.