开发者

Speed of NSArray#count

开发者 https://www.devze.com 2023-02-25 12:59 出处:网络
开发者_高级运维If I do [myArray count] is it O(1) or O(n), where n is the number of elements in the array?The source code of Core Foundation collections (upon which Foundation collections are built
开发者_高级运维

If I do

[myArray count]

is it O(1) or O(n), where n is the number of elements in the array?


The source code of Core Foundation collections (upon which Foundation collections are built) is open source. If you inspect CFArray.c, you’ll see that __CFArrayGetCount() is O(1).


If it is not O(1) then you should find another array implementation :)

0

精彩评论

暂无评论...
验证码 换一张
取 消