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

Add tables.mgetOrPutLazy #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add tables.mgetOrPutLazy #52

wants to merge 1 commit into from

Conversation

zah
Copy link
Contributor

@zah zah commented Aug 7, 2020

No description provided.

loc = val
loc

setter(mgetOrPut(t, key, default(R)))
Copy link
Member

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):
Copy link
Member

@arnetheduck arnetheduck Aug 8, 2020

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

Copy link
Contributor Author

@zah zah Aug 8, 2020

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.

Copy link
Member

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

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.

2 participants