开发者

What is the best data structure to store location information?

I am building a simple app that all is does is storing the 'locat开发者_JAVA技巧ion' from CLLocation every hout. I am very new to objective C, and just wanted to know which structure would be ideal for this purpose.

Thanks!


It depends by what you have to do with that:

  • if you have to have them ordered (by the timestamp, for example) an array is good
  • if you have to retrieve them using a sort of key, a dictionary is good
  • if you have only to collect them, a set is better (think of NSSet)

Keep in mind that NSArray, NSDictionary and NSSet only store objects.


Of course, for 2D coordinates CLLocationCoordinate2D, or if you want altitude also you can use this:

typedef struct {
  CLLocationCoordinate2D ground,
  double altitude;
} CLLocationCoordinate2DWithAltitude;


Is there any point to having these locations? Are you going to be implementing any specific algorithm with them?

If all I was doing was storing arbitrary locations, I would probably wrap them with a "location" object, and then store the location object within a linked list or array.

If you are going to try to resolve the locations to logical addresses, then you may want to store them in an adjacency matrix or list (two dimensional array) so you can perform graph operations on them (such as shortest path algorithms).

Linked list implementation can be found here: http://www.cocoadev.com/index.pl?LinkedList

This isn't an array, it is a more advanced data structure. It is very commonly used, because there is no limit to the size of the data structure.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜