Of course, O(log n), not O(1) - maybe next Christmas :).

subseq works like a charm and does everything I need, I prefer the
usability of it much over the 5 (or so in total) distinct methods in
java that basically do the same, albeit a bit clunkier.

Haven't verified the performance characteristics, but as the doc says
"sc must be a sorted collection", I assume it will do at least a
binary search, if it doesn't use the map directly.

Thanks all for the replies, the versatility of all these small clojure
functions surprises me every day.

On Jan 31, 9:43 am, Chouser <chou...@gmail.com> wrote:
> On Sat, Jan 30, 2010 at 7:31 PM, Rowdy Rednose <rowdy.redn...@gmx.net> wrote:
> > I want to have it in O(1). That's why I use a tree map in the first
> > place.
>
> > On Jan 31, 9:15 am, Sean Devlin <francoisdev...@gmail.com> wrote:
> >> If you can live with an O(n) operation, take/drop-with will do the
> >> job.
>
> >> Sean
>
> >> On Jan 30, 6:59 pm, Rowdy Rednose <rowdy.redn...@gmx.net> wrote:
>
> >> > How would I do something like these 3 TreeMap operations with
> >> > clojure's sorted-map?
>
> >> > The goal is to narrow down a map to include only keys with a given
> >> > prefix.
>
> Items in a sorted map cannot be found, added, or removed in O(1).
> Those operations are O(log2 n) on sorted maps and sets.
>
> (first m) will return the lowest-sorted item in a sorted map,
> O(log2 n).
>
> (dissoc (key (first m))) will return a map with that first item
> removed, O(log2 n),
>
> The subseq function can be used for efficiently walking various
> sorted slices of a sorted map.
>
> Hope that helps,
> --Chouserhttp://joyofclojure.com/

-- 
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

Reply via email to