0

I need to have data structure, each element in which is accessible by pair of (x,y) (like nspoint).

I can store them in NSDictionary with keys like @"8,10", but I'm looking for more elegant and efficient solution (I don't want to have two dimensional array cause I want to have O(1) access to elements by coordinate)

4

1 回答 1

2

您可以使用NSValueas 键(+NSValue valueWithCGPoint:请参阅此链接),可能有点“轻”。否则,如果值是 x 和 y 对有一些限制,例如 x 为 256,y 为 256,您可以使用位掩码,其中前 8 位表示 x 值,后 8 位表示 y 值(因为 256 = 2^8)。

于 2012-04-07T07:56:41.157 回答