Re: GSList speed



There was once some documentation somewhere that said this (Or maybe it
was in a comment in some long forgotten code, but still I read it once):
g_(s)list_append() is O(n) as it must traverse to the end of the list
for each insert; for most list operations g_(s)list_prepend() is the
prefered, O(1) solution.

--Shahms

On Wed, 2002-08-07 at 06:44, Harring Figueiredo wrote:
 You might want to check g_slist_prepend

Harring
--- Scott Barron <sb125499 ohiou edu> wrote:
On Wed, Aug 07, 2002 at 02:47:39PM +0200, Janus N. Tøndering wrote:
Hi,

I was wondering, since it isn't mentioned in the API reference, how fast
GSList is? Does g_slist_append() run in constant time? Or does it search
for the last item each time? And how about the other functions that
manipulate lists?

Thank you.

Regards,
Janus N. Tøndering
-- 
Janus Nørgaard Tøndering  
email: j nus person dk or u011014 daimi au dk

"Would you buy a car with the hood welded shut?"
-Phil Hughes, Linux Journal Magazine


Hi,

If you check out glib/gslist.c and glib/glist.c you'll see that the
append functions call g_slist_last and g_list_last (respectively for
GSList and GList) which loop through each element making appending
linear time.  For the rest of the functions just check out the source,
the lists are simple and pretty easy to follow.

-Scott

-- 
We are not humanity.
-B
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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