Mnesia query: less or equal than given key

Erik Reitsma (RY/ETM) erik.reitsma@REDACTED
Mon Sep 19 16:06:06 CEST 2005


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