Archived

This forum has been archived. Please start a new discussion on GitHub.

Freeze Map bidirectional iterator?

Is it possible to traverse a Freeze Map backwards? Reverse/bidirectional iterators don't seem to be implemented.

A related question: how to to get the last entry in a Freeze Map (without operator-- cannot step back one entry from the end() )

thanks, alex

Comments

  • bernard
    bernard Jupiter, FL
    Hi Alex,

    Currently Freeze provides only forward iterators; it should be easy to add bidirectional operators, since the underlying feature (Berkeley DB cursors) is bidirectional.

    I don't see a good way to get the last element of a map (which is meaningful for a sorted map). With bidirectional iterators, I am not sure end()-- would be correct; however you could use rbegin().

    Cheers,
    Bernard
  • Hi Bernard,
    Currently Freeze provides only forward iterators; it should be easy to add bidirectional operators, since the underlying feature (Berkeley DB cursors) is bidirectional.

    Easy for you or for me? :) Can I add it myself? I guess not easily since it needs to talk to Berkeley DB.
    I think it'd be useful. Here's my application as an example. I have a map of timestamped data and want to retrieve a "window" around a particular point. I could define the window in terms of time and look for the boundaries but for what I want to it's more natural to define this window in terms of samples.
    I don't see a good way to get the last element of a map (which is meaningful for a sorted map). With bidirectional iterators, I am not sure end()-- would be correct; however you could use rbegin().

    Finding the end and stepping back one record would do the trick. Of course, a reverse iterator would also work but it also seems not to be implemented Freeze::Map. Is it true?

    thanks for you help,
    alex
  • bernard
    bernard Jupiter, FL
    In general, adding features to Freeze depends very much on what the underlying database system provides. In this case, Freeze iterators map to Berkeley DB cursors; since Berkeley DB cursors are bidirectional, I don't see any difficulty in adding this feature to Freeze Maps. It won't require lots of code, but naturally adding such feature requires some understanding of the Freeze Map implementation and some new Berkeley DB API calls.

    Currently, Freeze provides only forward iterators for Freeze dictionaries: no operator-- and no reverse iterators.

    Cheers,
    Bernard