-
Notifications
You must be signed in to change notification settings - Fork 18
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 tables.mgetOrPutLazy #52
base: master
Are you sure you want to change the base?
Conversation
loc = val | ||
loc | ||
|
||
setter(mgetOrPut(t, key, default(R))) |
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.
this looks pretty odd - ie if B
is an array[10000, uint64]
, this will.. zero-init such an array, zeroinit another such array (default(R)
) then compare all those values?
type R = B | ||
|
||
proc setter(loc: var R): var R = | ||
if loc == default(R): |
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.
so if the collection had a value that was all zeroes (as opposed to not having a value), this will update it to val
which doesn't seem to be the intent
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.
Yes, this version of code comes with a number of caveats, but the idea of having a shim is that it allows us to capture the intention of the user until a more general and efficient version of the API is added to the tables
module (as a template similar to withValue
).
At the moment it's reasonable to use mostly with tables with ref
values that don't need to store nil
. The default
function for the type should be cheap and not a valid value in the usage context.
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.
well, the that's the point a bit - my intent is not to set if the value is the default - it's to set / create only if it's not in the collection already
No description provided.