[erlang-questions] Question about ETS documentation
Soup
zachary.hueras@REDACTED
Mon Mar 31 05:14:30 CEST 2014
Pos refers to a position in the stored tuple. ets:lookup_element returns
only one of the values from the tuple, as opposed to ets:lookup which
returns the tuple in its entirety (in a list for compatibility with
bag-type tables).
One reason you might prefer lookup_element as opposed to lookup is that
it's slightly cheaper to copy from the table (as you're not copying as much
data), but it's also generally useful as a shorthand for retrieving one
piece of the stored tuple so you don't have to bind the entire return value.
If I recall correctly, lookup_element, update_element, and update_counter
only work with tables of type set or ordered_set.
~Soup
On Sun, Mar 30, 2014 at 6:45 PM, Yves S. Garret
<yoursurrogategod@REDACTED>wrote:
> Hello,
>
> I've been reading this documentation:
> http://www.erlang.org/doc/man/ets.html#lookup_element-3
>
> What I have a hard time figuring out is what the Pos means. Why would it
> be needed at all? I'm looking at this code:
>
> ...
> Cx_PId = ets:lookup_element(IdsNPIds, Cx#cortex.id, 2),
> ...
>
> And I have no idea what this and why have it there. I've already
> specified the element that we're searching for, why the position? Does the
> position refer to the element that's located inside of the return value?
> As in, I want the 2nd element from the return value?
>
> Thanks in advance.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140330/d45c2ea9/attachment.htm>
More information about the erlang-questions
mailing list