guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string vs list processing


From: Jorgen 'forcer' Schaefer
Subject: Re: string vs list processing
Date: 17 Apr 2001 22:55:27 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Martin Grabmueller <address@hidden> writes:

> If you want that to be fast, check out my SRFI-13 (string
> library) implementation, where a call to
> `reverse-string-concatenate' only costs you two traversals over
> the list, one malloc() and one memcpy() of each element string.
> I think this is as fast as you can get.

You could spare one of the traversals if you'd record the length
of the total string while building up the list.  If you already
know you're going to concatenate the whole thing, this might be a
very worthwhile thing to do.

It's difficult to abstract this away into a seperate functional
data type, since this would require at least another cons for
each element.

The only sensible thing for an abstract datatype is to use
imperative style:

(define (make-string-list)
  (vector '() 0))

(define (string-list-cons str slis)
  (vector-set! slis 0 (cons str (vector-ref slis 0)))
  (vector-set! slis 1 (+ (string-length str) (vector-ref slis 1))))

or something along these lines.

Of course, one could always just pass the length along in the
recursion.  :)

Greetings,
        -- jorgen

-- 
((email . "address@hidden")       (www . "http://forcix.cx/";)
 (irc   . "address@hidden (IRCnet)") (gpg .    "1024D/028AF63C"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]