Re: use of subseq on a vector which I know is already sorted

2011-07-19 Thread Sunil S Nandihalli
thanks Miekel, Bennyand Ken for your responses.. Sunil. On Mon, Jul 18, 2011 at 7:15 PM, Sunil S Nandihalli < sunil.nandiha...@gmail.com> wrote: > Hi everybody, > > I have a situation where I know that the sequence I have at hand is sorted > but does not implement the Sorted interface. How can I

Re: use of subseq on a vector which I know is already sorted

2011-07-18 Thread Ken Wesson
If the input is always going to be sorted, consider using a sorted-set or similar collection type to hold it in the first place. If you're going to need to refer to a particular subsequence repeatedly, and it's held in a vector, you might also consider using subvec after using loop/recur to find t

Re: use of subseq on a vector which I know is already sorted

2011-07-18 Thread Benny Tsai
On Monday, July 18, 2011 9:12:05 AM UTC-6, Meikel Brandmeyer wrote: > > Hi, > > *snip* > > However with a different performance promise, I believe. > Hi Meikel, I took a look at the source for subseq, and you're right. To be specific, when the comparison operation is either > or >=, seqFrom all

Re: use of subseq on a vector which I know is already sorted

2011-07-18 Thread Meikel Brandmeyer
Hi, Am Montag, 18. Juli 2011 16:59:40 UTC+2 schrieb Benny Tsai: If you know that the input sequence is already sorted, then you can use > take-while and drop-while in lieu of subseq. > > (subseq (sorted-set 1 2 3 4) < 3) -> (take-while #(< % 3) [1 2 3 4]) > (subseq (sorted-set 1 2 3 4) <= 3) ->

Re: use of subseq on a vector which I know is already sorted

2011-07-18 Thread Benny Tsai
Hi Sunil, If you know that the input sequence is already sorted, then you can use take-while and drop-while in lieu of subseq. (subseq (sorted-set 1 2 3 4) < 3) -> (take-while #(< % 3) [1 2 3 4]) (subseq (sorted-set 1 2 3 4) <= 3) -> (take-while #(<= % 3) [1 2 3 4]) (subseq (sorted-set 1 2 3 4)