Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been looking into this on Google and read the Collections entry in the SDK documentation, and turned up nothing. Is there a BST (any of its variants) implementation available out of the box with the iOS SDK?

It seems odd that something so basic would be missing from a major development platform. Is their hash implementation just that magical? Or do the devs assume no one is going to do inserts/deletes on things that have an order?

I can use NSSet for now, as I know most of us (myself included) aren't really writing anything with tons of computation on iOS that need a guaranteed access time, but it's still gnawing at me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
747 views
Welcome To Ask or Share your Answers For Others

1 Answer

CFBinaryHeap looks pretty promising and useful, but it might not be exactly what you want, as it's not really a binary search tree but a heap. They are similar, but not the same, so I feel like Core Foundation's CFTree class might be a little better. Here's a description from the CFTree class reference:

You use CFTree to create tree structures that represent hierarchical organizations of information. In such structures, each tree node has exactly one parent tree (except for the root tree, which has no parent) and can have multiple children.

If you're not comfortable with C (Core Foundation is C, not Objective-C), you can use the JKPTree library which is an Objective-C wrapper of CFTree. You can download it here.

UPDATE:

I just found another library called CHDataStructures that simplifies the creation of a wide variety of data structures. It supports the following data structures (and many other unlisted ones):

  • AVL Tree
  • Abstract Binary Search Tree
  • Andersson Tree
  • Linked List
  • Search Tree
  • Red Black Tree
  • Unbalanced Tree
  • Queue
  • Heap

    You can download CHDataStructures here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...