Re:Linked lists in C, with open source ADT
by spinlocked on Saturday January 19, 2013 @09:53PM
(#5085788)
"insertions to the end of a variable-length array are very fast"
really tptacek? its O(1) ammortized over time, and when N grows it becomes really slow because it involves reallocation and a linear copy of all elements.
Re:Linked lists in C, with open source ADT
by marshray on Saturday January 19, 2013 @10:28PM
(#5085875)
You have a magic allocator for your list nodes that does better than O(1) amortized?
Re:Linked lists in C, with open source ADT
by shrughes on Saturday January 19, 2013 @11:11PM
(#5085972)
Being better than O(n) worst case is the target here, not O(1) amortized. For example, O(1) amortized and O(log n) worst case is a thing.
Re:Linked lists in C, with open source ADT
by spinlocked on Saturday January 19, 2013 @10:54PM
(#5085940)
Do you need magic to create an O(1) allocator for a pool of fixed size objects?
Re:Linked lists in C, with open source ADT
by marshray on Saturday January 19, 2013 @11:39PM
(#5086026)
Yes, when (as in the general case of std::list) the number of objects is not known in advance.
Re:Linked lists in C, with open source ADT
by spinlocked on Sunday January 20, 2013 @12:29AM
(#5086102)
true. however, libstdc++ implements __pool_alloc for a reason.
Re:Linked lists in C, with open source ADT
by afhof on Saturday January 19, 2013 @09:16PM
(#5085693)
Someone wants to know about linked lists, and your comment is to use some other data structure that has a different purpose?
Re:Linked lists in C, with open source ADT
by tptacek on Saturday January 19, 2013 @09:39PM
(#5085749)
Different purpose?
Re:Linked lists in C, with open source ADT
by afhof on Saturday January 19, 2013 @09:45PM
(#5085763)
Linked lists are good for adding and removing elements. Variable length arrays are good for allocating a known amount of space at runtime.
Re:Linked lists in C, with open source ADT
by tptacek on Saturday January 19, 2013 @09:46PM
(#5085768)
The "variable" in "variable length" describes the fact that you don't know how much space you need, and insertions to the end of a variable-length array are very fast. I can see why you thought my comment was weird, now.
You are, for whatever it's worth, better off defaulting to a variable-length array than to a linked list.