Mnesia query: less or equal than given key

chandru chandrashekhar.mullaparthi@REDACTED
Mon Sep 19 17:13:01 CEST 2005


>From the man page for mnesia

       dirty_prev(Tab, Key) -> Key | exit({aborted, Reason})

              This  function works exactly mnesia:dirty_next/2 but returns the
              previous object in Erlang term order for the  ordered_set  table
              type.  For  all  other table types, mnesia:dirty_next/2 and mne-
              sia:dirty_prev/2 are synonyms.


On 19/09/05, Erik Reitsma (RY/ETM) <erik.reitsma@REDACTED> 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