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






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