Mnesia query: less or equal than given key
Sean Hinde
sean.hinde@REDACTED
Mon Sep 19 16:52:05 CEST 2005
Hi,
You could try first looking up the exact key, and if not found then
do a mnesia:dirty_prev/2 to get the next smallest. You would need to
be careful of transaction safety..
Sean
On 19 Sep 2005, at 15:06, Erik Reitsma (RY/ETM) wrote:
> Hi all,
>
> Using mnesia, is there an efficient way to find the smallest entry
> in a table with a key equal to or less than a given key?
>
> So suppose that I have keys 10, 23, 33, 34, 56, 100 and I look for
> 26, I want to get 23 back. If I look for 23, I should get 23.
>
> I could select all entries smaller than or equal to my key, and
> then take the largest of those, but it seems like I would get an
> intermediate list that may consist of the entire table (i.e. if my
> key is larger than the largest key in the table).
>
> I could make my own binary search (the keys are integers anyway),
> but I wondered if there would be a more elegant way.
>
> Regards,
> *Erik.
>
>
More information about the erlang-questions
mailing list