Differences between nsarray and nsset in objective-C

Source: Internet
Author: User

Nsarray and nsset actually implement similar basic functions. This is very different from other languages such as Java. nsarray's data storage method is continuous, the latter data is stored in the memory followed by the previous data, while the nsset does not need a continuous memory during storage. It is possible that the first data is stored in this place, the second data is separated from the first data. When I store the second data, I just find a place where I can put it down and save it.

So what are the benefits of doing so?

Because nsset is implemented using the hash idea at the underlying layer, it ensures that the objects stored in it must be unique, while Arrays can store the same objects.

Because nsset is implemented using hash, it makes it faster to query, but we cannot put a certain object after the first few elements and other related script operations.

Arrays can be used for script operations, but the query speed is slightly slower.

For example, why is the nsset query speed faster than nsarray?

When we are looking for a certain element A, in nsset, we can directly find the storage location of a through the hash value, instead, nsarray needs to traverse all the elements in front of a before finding them.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.