开发者

Compare values with values from a file?

What would be the best way to do this?

I have an application that gets two values about each and every 10th second (when user touches the screen). From this i get two values, latitude and longitude of a sphere object that the user has touched.

Now I would like to compare thoose values to values from a file, with the real latitude longitude of a location and then compare thoose values and se how far away the user was.

My file will be built up with two values and one key (location) in each index.

What would be the best way to do this, would it be to read the whole file in the beggining with a bufferedInputStreamReader and store thoose in a

HashMap<Stri开发者_高级运维ng, List<Float>>

or would i be better of using some kind of database structure like SqlLite?

Since Im doing this on a mobile platform performance is quite important and that's mainly why i ask this question.


Depending on the size of the data you need to compare against, you could either look up each time against a database (slower) or do a binary search in memory (faster).

If you store in a HashMap (for the in memory method), then you will need to sort and implement a binary search for maximum speed. Otherwise you will be searching linearly (iterating) throughout the collection of values (that might be acceptable to you).

I would say if you have a few thousands entries, then do it in memory, if you have more then go down the database route.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜