iPhone很难计算和缓存 [英] iPhone hard computation and caching

查看:115
本文介绍了iPhone很难计算和缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题。我有数据库是 500K 记录。各唱片店的纬度,经度,动物的物种,观察日期。我必须提请格(15×10)以上mapkit认为,这表明在这个网格单元物种的浓度。每个单元为32×32盒。

如果我计算运行时间,它是很。 可有人知道如何缓存它?在内存或数据库中。

数据结构:

观察:

  • 天气预报
  • 经度
  • 日期
  • 树种
  • 在其他一些不重要的数据

屏幕示例:

每个红框opocasity呈现出品种在这一地区计数。

code,我现在使用: 数据 - >从数据库中选择,它是所有观测地图区域

 的(INT行= 0;行<排;排++)
 {
  对于(INT列= 0;柱<列;列++)
  {
   speciesPerBox = 0;
   明=盒[行] [列] .longitude;
   如果(柱!=列-1){
    maxG =盒[行] [列+ 1] .longitude;
   } 其他 {
    maxG = buttomRight.longitude;
   }

   maxL =盒[行] [列] .latitude;
   如果(行!=行-1){
    MINL =盒[行+ 1] [列] .latitude;
   } 其他 {
    MINL = buttomRight.latitude;
   }

   的for(int i = 0; I< sightingCount;我++){
    L =数据[I] .latitude;
    G =数据[I] .longitude;

    如果(L> = MINL和放大器;&安培; L< maxL和放大器;&放大器; G> =明和放大器;&放大器; G< maxG){
     对于(INT J = 0; J< speciesPerBox; J ++){
       如果(speciesCountArray [J] ==数据[I] .specie){
        hasSpecie = YES;
       }
      }

      如果(hasSpecie == NO){
       speciesCountArray [speciesPerBox] =数据[I] .specie;
       speciesPerBox ++;
      }

      hasSpecie = NO;


     }
    }
   }


   mapData [行] [列] .Count之间= speciesPerBox;
  }
 }
 

解决方案

既然你的数据是静态的,你可以pre-计算每个品种每个网格,并将其存储在数据库中,而不是所有的位置坐标。

既然你有15×10 = 150细胞,你会拥有150 * [物种NUM]记录在数据库中,这应该是一个更小的数字。

此外,还要确保你有适当的列的索引。否则,你的查询将要扫描的每一个记录了一遍又一遍。

I have problem. I have database with 500k records. Each record store latitude, longitude, specie of animal,date of observation. I must draw grid(15x10) above mapkit view, that show the concentration of specie in this grid cell. Each cell is 32x32 box.

If I calculate in run-time it is very slow. Have somebody idea how to cache it?In memory or in database.

Data structure:

Observation:

  • Latitude
  • Longitude
  • Date
  • Specie
  • some other unimportant data

Screen sample:

Each red box opocasity show count of species in this region.

Code that i use now: data -> select from database, it is all observation in map region

for (int row = 0; row < rows; row++)
 { 
  for (int column = 0; column < columns; column++)
  {
   speciesPerBox=0;
   minG=boxes[row][column].longitude;
   if (column!=columns-1) {
    maxG=boxes[row][column+1].longitude;
   } else {
    maxG=buttomRight.longitude;
   }

   maxL=boxes[row][column].latitude;
   if (row!=rows-1) {
    minL=boxes[row+1][column].latitude;
   } else {
    minL=buttomRight.latitude;
   }

   for (int i=0; i<sightingCount; i++) {
    l=data[i].latitude;
    g=data[i].longitude;

    if (l>=minL&&l<maxL&&g>=minG&&g<maxG) {
     for (int j=0; j<speciesPerBox; j++) {
       if (speciesCountArray[j]==data[i].specie) {
        hasSpecie=YES;
       }
      }

      if (hasSpecie==NO) {
       speciesCountArray[speciesPerBox]=data[i].specie;
       speciesPerBox++;
      }

      hasSpecie=NO;


     }
    }
   }


   mapData[row][column].count = speciesPerBox;
  }
 }

解决方案

Since you data is static, you can pre-compute each species for each grid and store it in the database instead of all the location coordinates.

Since you have 15 x 10 = 150 cells, you'll end up with 150 * [num of species] records in the database, which should be a much smaller number.

Also, make sure you have indexes on the proper columns. Otherwise, your queries will have to scan every single record over and over again.

这篇关于iPhone很难计算和缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆