[erlang-questions] random lookup in ets

Ulf Wiger ulf.wiger@REDACTED
Thu Aug 26 19:14:20 CEST 2010


On 26/08/2010 18:57, Pascal Chapier wrote:
>
> It is a
> funny usage of the previous function in ordered set!
>
> I would
> have bet that it produces an exception in case of
>
> non existing
> key (like it does with simple set).

But next(T,K) and prev(T,K) on an ordered set can be well defined,
as "next key in T greater than K" and "next key in T smaller than K".
This way, K doesn't actually have to be part of the set.

In a hash table, there is no defined ordering, so the next/prev
functions simply step in "slot order". What is the previous slot
of a non-existing object?

An option would be to return '$end_of_table', which would make that
return value ambiguous - it could either mean "I've stepped to the
end of the table", or "I don't know where to go". Of course, one
could invent yet another return value, but that would hardly be
an improvement.

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com


More information about the erlang-questions mailing list