Well, the two calls to subseq are unpleasant and possibly slow. I was thinking there's a way to write it as a single operation that returns three items, say (subseq s >= (dec 50)) to get the items before and after 50, but of course that doesn't work unless you know 49 is in there, and in that case why bother with subseq?
It's a bit galling, because the sorted-set *knows* how to get to where 50 should be, and how to walk in either direction from there, but in order to walk in two different directions you have to walk down from the root twice. Maybe it'd be nice to have a (get-walker s 50) that you can later pass directions to, to walk through the set in whatever order. On Sep 1, 3:36 am, Sunil S Nandihalli <sunil.nandiha...@gmail.com> wrote: > Thanks Dave, > That did it. I did not know there was rsubseq .. :) > Thanks > Sunil. > > > > > > > > On Thu, Sep 1, 2011 at 4:04 PM, David Powell <djpow...@djpowell.net> wrote: > > > On Thu, Sep 1, 2011 at 11:13 AM, Sunil S Nandihalli < > > sunil.nandiha...@gmail.com> wrote: > > >> Hi Everybody, > >> I would like to create a sorted-data-structure which would enable me to > >> efficiently > > >> 1. insert new elements into it maintaining the sorted-nature of the data > >> structure. > >> 2. query as to which element is immediately before and after a value that > >> I present. one can assume that the value that I present is guaranteed to be > >> present in the data-structure. > > >> How can I do it? what should I be using to achieve this? I tried to see if > >> finger-trees could help with my limited understanding with no success. This > >> might be pretty basic .. but some how I seem to be missing something. > > > Is this what you want? > > > user=> (def s (sorted-set 38 42 123 598 23 10 1 88)) > > > user=> (first (subseq s > 50)) > > 88 > > > (first (rsubseq s < 50)) > > 42 > > > -- > > Dave > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > > your first post. > > To unsubscribe from this group, send email to > > clojure+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en