isnan和hash_map使用问题解决方法

                                                isnan和hash_map使用问题解决方法

                                                              by wangsh 2011-11-15

 

isnan问题:在GIS开发中,我们计算两点之间距离之后,需要判断距离是否isnan(

double dist = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371.0;)。

并不是所有的编译器都有isnan,vs2008中没有isnan,在合适的地方加入:

 

inline bool isnan(double v)

{

        return v!=v;

}

这时候完整代码段为:

       /* Return distance in km */

double fast_distance_rad(double lat1, double lon1, double lat2, double lon2)

{

    double dist = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371.0;

    if(isnan(dist))

    {

         dist = 0;

    }

 

    return dist;

}

 

hash_map的使用:hash_map基于hash table,其最大优点是降低数据存储与查找消耗时间,可近似为常数时间;而代价仅是消耗较多内存。而在当前可利用内存越来越多的情况下,用空间换时间的做法是值得的。(具体参考1和2)

使用hash_map例:

#include <hash_map>

using namespace std;

using namespace stdext;

 

typedef stdext::hash_map<int, GPSCoordinate>::value_type hashGPS;

 

参考资料

1.     Blog  http://www.cppblog.com/woaidongmao/archive/2008/10/15/64014.html

2.     介绍 http://blog.csdn.net/ztj111/article/details/1895200

3.  性能比较 http://hi.baidu.com/lujunqianglw/blog/item/9f7fbc549233cd063b293582.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值