Re: comments on g_list_slice / g_list_splice
On Wed, 30 Nov 2005 00:57:42 -0500 ANDREW PAPROCKI, BLOOMBERG/ 731 LEXIN [EMAIL PROTECTED] wrote: GList * g_list_slice(GList *list, GList *link, gint n_links); GList * g_list_remove_slice(GList *list, GList *link, gint n_links); GList * g_list_splice(GList *list, GList *splice_list, gint position); GList * g_list_splice_before(GList *list, GList *splice_list, GList *sibling); I added myself GPtrArray* g_ptr_array_slice(const GPtrArray* orig, guint first, gint last); I have found it more useful to pass offset indexes. For arrays this is the only sensible choice, but for lists it's somewhat harder to say what is the correct way of indexing them. Offset count, or link node pointer? Either way, the presence of functions which do that job, sound very useful. -- Paul LeoNerd Evans [EMAIL PROTECTED] ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/ signature.asc Description: PGP signature ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list
Fwd: Re: comments on g_list_slice / g_list_splice
I just realized that all of the APIs need to return the original list because it can be modified. The way I'm playing with it now, the slice calls would simply unlink 'link' and it is up to the caller to reuse the same 'link' pointer as the newly separated list.. - Original Message - From: Paul Leonerd Evans [EMAIL PROTECTED] At: 11/30 5:49 On Wed, 30 Nov 2005 00:57:42 -0500 ANDREW PAPROCKI, BLOOMBERG/ 731 LEXIN [EMAIL PROTECTED] wrote: GList * g_list_slice(GList *list, GList *link, gint n_links); GList * g_list_remove_slice(GList *list, GList *link, gint n_links); GList * g_list_splice(GList *list, GList *splice_list, gint position); GList * g_list_splice_before(GList *list, GList *splice_list, GList *sibling); I added myself GPtrArray* g_ptr_array_slice(const GPtrArray* orig, guint first, gint last); I have found it more useful to pass offset indexes. For arrays this is the only sensible choice, but for lists it's somewhat harder to say what is the correct way of indexing them. Offset count, or link node pointer? Either way, the presence of functions which do that job, sound very useful. -- Paul LeoNerd Evans [EMAIL PROTECTED] ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/ ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list signatur.asc Description: Binary data ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list
comments on g_list_slice / g_list_splice
Does anyone have any comments on the possibility of creating g_list_slice and g_list_splice functions? I find myself needing to remove/add contiguous sections of a GList, and believe these functions might be useful to others. The idea would be: GList * g_list_slice(GList *list, GList *link, gint n_links); GList * g_list_remove_slice(GList *list, GList *link, gint n_links); GList * g_list_splice(GList *list, GList *splice_list, gint position); GList * g_list_splice_before(GList *list, GList *splice_list, GList *sibling); g_list_slice() would return a newly allocated GList as a copy of the segment of 'list' beginning with 'link' and extending 'n_links'. g_list_remove_slice() would function similar g_list_remove_link(), except it would remove 'n_links' from 'list' and the returned list would consist of the removed links. g_list_splice()/g_list_splice_before() would do the reverse and function similar to g_list_insert()/g_list_insert_before(), except they would take the 'splice_list' and fully insert it into 'list' instead of a inserting a single piece of data. Is this useful to anyone else? There are some details that could work in a few ways. The splice calls could either insert by copying 'splice_list' or insert by taking ownership of 'splice_list', for instance. My use for these calls is to pull out a section of a GList and move it somewhere else in the list, so I would primarily be looking for remove_slice and splice calls that take ownership. Comments? Andrew Paprocki Bloomberg LP ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list