{"action":"created","issue":{"url":"https://api.github.com/repos/raywenderlich/swift-algorithm-club/issues/296","repository_url":"https://api.github.com/repos/raywenderlich/swift-algorithm-club","labels_url":"https://api.github.com/repos/raywenderlich/swift-algorithm-club/issues/296/labels{/name}","comments_url":"https://api.github.com/repos/raywenderlich/swift-algorithm-club/issues/296/comments","events_url":"https://api.github.com/repos/raywenderlich/swift-algorithm-club/issues/296/events","html_url":"https://github.com/raywenderlich/swift-algorithm-club/issues/296","id":190445388,"number":296,"title":"Which data structure should I use for lots of insertions, and lots of reads, if reads must access the data in an ordered fashion?","user":{"login":"ugultopu","id":9937444,"avatar_url":"https://avatars.githubusercontent.com/u/9937444?v=3","gravatar_id":"","url":"https://api.github.com/users/ugultopu","html_url":"https://github.com/ugultopu","followers_url":"https://api.github.com/users/ugultopu/followers","following_url":"https://api.github.com/users/ugultopu/following{/other_user}","gists_url":"https://api.github.com/users/ugultopu/gists{/gist_id}","starred_url":"https://api.github.com/users/ugultopu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ugultopu/subscriptions","organizations_url":"https://api.github.com/users/ugultopu/orgs","repos_url":"https://api.github.com/users/ugultopu/repos","events_url":"https://api.github.com/users/ugultopu/events{/privacy}","received_events_url":"https://api.github.com/users/ugultopu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-18T23:20:41Z","updated_at":"2016-11-23T19:06:43Z","closed_at":null,"body":"I can't find what data structure should I use to most efficiently handle my app's functionality. Here's the scenario:\r\n\r\nI am making a tracking app. In the app, clients continuously send their location (a CLLocationCoordinate2D) and the timestamp associated with this location to a server. And the server continuously distributes this data to trackers.\r\n\r\nAs an example, let's say Alice, Bob, Mike and Mary are users of this app. The app continuously sends the aforementioned data to the server. Let's say Alice tracks Bob and Mary. Then server distributes the data which it received from Bob and Mary to Alice.\r\n\r\nWhen the app at Alice's device receives this data, it:\r\n1) Groups them by user (that is, partitions the data as Bob's and Mary's data).\r\n2) Sorts them according to their timestamp.\r\n3) Draws a custom overlay (a line) on the map which shows where the respective users have been.\r\n\r\nAs you can observe, there is a continuous insertion of data. And there is also a continuous read of this data, because the overlay will continuously be (re)drawn on the map.\r\n\r\nConsidering there will be a constant read of data (because the overlay will continuously be redrawn on the map), I have thought that the most efficient way of doing this is using a data structure which keeps an order at all times. This way, each new element will be inserted at the correct place and be simply drawn without any further sorting operation.\r\n\r\nFor this, I have checked out Ordered Array and Ordered Set. However, both of them state that if insertions are common, these data structures may not be the most suitable ones. However, I am not sure if using a plain array and sorting the array at each redraw (which will happen _constantly_) would be more efficient. To me, it feels like it would be _a lot_ more inefficient. Hence, I feel like I should use a data structure which maintains the order at all times.\r\n\r\nWhat kind of solution should I follow here?\r\n\r\nThank you very much"},"comment":{"url":"https://api.github.com/repos/raywenderlich/swift-algorithm-club/issues/comments/262604371","html_url":"https://github.com/raywenderlich/swift-algorithm-club/issues/296#issuecomment-262604371","issue_url":"https://api.github.com/repos/raywenderlich/swift-algorithm-club/issues/296","id":262604371,"user":{"login":"hollance","id":346853,"avatar_url":"https://avatars.githubusercontent.com/u/346853?v=3","gravatar_id":"","url":"https://api.github.com/users/hollance","html_url":"https://github.com/hollance","followers_url":"https://api.github.com/users/hollance/followers","following_url":"https://api.github.com/users/hollance/following{/other_user}","gists_url":"https://api.github.com/users/hollance/gists{/gist_id}","starred_url":"https://api.github.com/users/hollance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hollance/subscriptions","organizations_url":"https://api.github.com/users/hollance/orgs","repos_url":"https://api.github.com/users/hollance/repos","events_url":"https://api.github.com/users/hollance/events{/privacy}","received_events_url":"https://api.github.com/users/hollance/received_events","type":"User","site_admin":false},"created_at":"2016-11-23T19:06:43Z","updated_at":"2016-11-23T19:06:43Z","body":"I would try the simplest approach that works first (a regular array probably). If that is a slow solution, I'd try to find a faster one. But often the simple approach is fast enough."}}
{"actor":{"display_login":"hollance"}}