Re: utlist new feature - sorted insertion macros

45 views
Skip to first unread message

Arthur O'Dwyer

unread,
Jan 16, 2017, 3:01:13 PM1/16/17
to Jeffrey Lovitz, uth...@googlegroups.com
Hi Jeffrey,

I think a lot (maybe all) of this functionality is already in the library under poor/unexpected names. For example, your DL_INSERT_AFTER(old,new) looks equivalent to the existing macro DL_APPEND_ELEM(list,old,new). Admittedly the existing one is poorly named.

Some style nits:
- I'd think _INORDER_ would be a better name than _SORTED_, since there are already _INORDER_ macros in uthash.h.
- Several of the raw assignments in your code (e.g. on line 4) should use _CASTASGN for portability.
- Should there be an LL_INSERT_INORDER, LL_INSERT_AFTER?
- Should there be CDL_ versions? My kneejerk reaction would be "no, it makes no sense to sort a circular list", but I don't know.

Do you have the ability to submit a pull request to https://github.com/troydhanson/uthash?

Thanks,
Arthur


On Mon, Jan 16, 2017 at 6:55 AM, Jeffrey Lovitz <jeffrey...@gmail.com> wrote:
Hi Arthur,

I have written a series of macros to extend the functionality of utlist that I would like to submit for review in the hopes of adding them to the core library.

The function that I felt was lacking was the ability to maintain a linked list's sort order while inserting a new element.  The library as it stands holds prepend and append functions as well as a sort function, so this seems like a potentially useful enhancement to me.

The main macro I've added, [LL]_SORTED_INSERT, takes as arguments the head of a linked list, the node to be added, and a comparator function.  Behind the scenes, two more macros are called: one to find the position at which to insert the new node, and one to perform the insertion.  These macros stand alone and could be used for user-determined insertions or searches.

Here is the code I have written for DL insertion: http://pastebin.com/rqF0yKhn

Let me know if you have any questions or criticisms of this proposal.  Thank you for your time!

- Jeffrey Lovitz

Reply all
Reply to author
Forward
0 new messages