Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the LinkedList equivalent in iOS frameworks?

In java, one can make use of the generic LinkedList to improve the efficiency when objects are often added to the front of the list. What is its equivalent in the iOS frameworks?

like image 988
Lopper Avatar asked Aug 11 '11 02:08

Lopper


3 Answers

You need to understand that in Foundation classes like NSArray, etc, is not what you learned as an array, etc in your beginning programming class. In particular, it doesn't have the performance characteristics you would normally associate to an array.

On this point, there are many nice blog posts, e.g. one by Ridiculous Fish and another by Cocoa with Love

So, as everybody else said, just use NSMutableArray.

like image 139
Yuji Avatar answered Nov 15 '22 19:11

Yuji


NSMutableArray is closest to this. Despite the name, it's closer to a list than an array. However, "appending to and removing elements from either end take constant time", according to this.

Also, what about this, a third-party implementation: https://github.com/mschettler/NSLinkedList

like image 34
Chris Dennett Avatar answered Nov 15 '22 20:11

Chris Dennett


There is no direct equivalent. Writing a linked list yourself is pretty easy, but I doubt that you will gain a lot of performance compared to NSMutableArray.

There are a couple of different linked list implementations in the open source CHDataStructures.

like image 4
omz Avatar answered Nov 15 '22 20:11

omz