How to do sparse array in Cocoa

前端 未结 4 920
不知归路
不知归路 2020-12-09 21:38

I have an undetermined size for a dataset based on unique integer keys.

I would like to use an NSMutableArray for fast lookup since all my keys are inte

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 22:01

    As in Jason's answer, an NSMutableDictionary seems to be the best approach. It adds the overhead of converting the index values to and from NSNumbers, but this is a classic space/time trade off.

    In my implementation I also included an NSIndexSet to make traversing the sparse array much simpler.

    See https://github.com/LavaSlider/DSSparseArray

提交回复
热议问题