Re: explode string

2010-07-02 Thread Chas Emerick
On Jul 1, 2010, at 9:21 AM, Martin DeMello wrote: On Thu, Jul 1, 2010 at 6:42 PM, Martin DeMello > wrote: I haven't benchmarked yet, but it's called frequently enough that it's probably worth making it efficient. (This is in code that converts a dictionary to a trie) Actually, it just str

Re: explode string

2010-07-01 Thread Martin DeMello
On Thu, Jul 1, 2010 at 7:19 PM, Nicolas Oury wrote: > > Random advices for speed or simplicity: > 1. don't split the string but loop on the index of the string in the code > that insert it in the trie That's a nice idea. Will give it a go. > 2. Use transients for the nodes of your tries Never u

Re: explode string

2010-07-01 Thread Nicolas Oury
On Thu, Jul 1, 2010 at 2:12 PM, Martin DeMello wrote: > I haven't benchmarked yet, but it's called frequently enough that it's > probably worth making it efficient. (This is in code that converts a > dictionary to a trie) > Random advices for speed or simplicity: 1. don't split the string but loo

Re: explode string

2010-07-01 Thread Martin DeMello
On Thu, Jul 1, 2010 at 6:42 PM, Martin DeMello wrote: > > I haven't benchmarked yet, but it's called frequently enough that it's > probably worth making it efficient. (This is in code that converts a > dictionary to a trie) Actually, it just struck me that the main reason I'm trying so hard to op

Re: explode string

2010-07-01 Thread Martin DeMello
On Thu, Jul 1, 2010 at 6:06 PM, Laurent PETIT wrote: > 2010/7/1 Martin DeMello : >> Anything more efficient than (map str (seq string)) ? > > I cannot think of another hof-like version that may be more efficient. > > If you want to avoid at all cost the creation of intermediate Seq elements: > > (

Re: explode string

2010-07-01 Thread Martin DeMello
On Thu, Jul 1, 2010 at 6:11 PM, Chouser wrote: > (next (.split #"(?=)" string)) > > But why do you one-char strings instead of just a seq of chars? Good question :) I was working with code that wanted one character strings, but since I'm trying to squeeze cycles anyway, it might be more worthwhil

Re: explode string

2010-07-01 Thread Laurent PETIT
2010/7/1 Nicolas Oury : > > > On Thu, Jul 1, 2010 at 1:36 PM, Laurent PETIT > wrote: >> >> If you want to avoid at all cost the creation of intermediate Seq >> elements: >> >> (defn explode-string [^String string] >>  (loop [i (int 0) v (transient [])] >>    (if (== i (.length string)) >>      (pe

Re: explode string

2010-07-01 Thread Nicolas Oury
On Thu, Jul 1, 2010 at 1:36 PM, Laurent PETIT wrote: > If you want to avoid at all cost the creation of intermediate Seq elements: > > (defn explode-string [^String string] > (loop [i (int 0) v (transient [])] >(if (== i (.length string)) > (persistent! v) > (recur (inc i) (conj! v

Re: explode string

2010-07-01 Thread Chouser
(next (.split #"(?=)" string)) But why do you one-char strings instead of just a seq of chars? --Chouser http://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

Re: explode string

2010-07-01 Thread Laurent PETIT
2010/7/1 Martin DeMello : > Anything more efficient than (map str (seq string)) ? I cannot think of another hof-like version that may be more efficient. If you want to avoid at all cost the creation of intermediate Seq elements: (defn explode-string [^String string] (loop [i (int 0) v (transie