• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 3  文章 - 2  trackbacks - 0
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            stdext::hash_map使用字符串(const char*)做key的話,不是只指定一個compare函數難么簡單,要給定一個結構體,其包括hash函數,compare函數,以及“桶設定”

            struct StringCompare 
            {
            //define hash function for strings 
                enum 
                { 
                    //parameters for hash table 
                    bucket_size = 4,  // 一個桶4byte長度(因為sizeof(char*)=4)
                    min_buckets = 8 // 最少存在8個桶
                };
                size_t operator()(const char* str) const 
                { 
                    unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
            unsigned int hash = 0;
            while (*str)
            {
            hash = hash * seed + (*str++);
            }
            return (hash & 0x7FFFFFFF);
                }
                bool operator()(const char *s1, const char* s2) const 
                {    
                    if (strcmp(s1, s2) == 0)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                } 
            }; 

            然后

            stdext::hash_map<const char*, Your Data Type, StringCompare>

            posted @ 2012-08-14 20:40 寰子 閱讀(439) | 評論 (0)編輯 收藏


            得分第一:

            // BKDR Hash Function
            unsigned int BKDRHash(char *str)
            {
                unsigned 
            int seed = 131// 31 131 1313 13131 131313 etc..
                unsigned int hash = 0;
             
                
            while (*str)
                
            {
                    hash 
            = hash * seed + (*str++);
                }

             
                
            return (hash & 0x7FFFFFFF);
            }


            得分第二:

            // AP Hash Function
            unsigned int APHash(char *str)
            {
                unsigned 
            int hash = 0;
                
            int i;
             
                
            for (i=0*str; i++)
                
            {
                    
            if ((i & 1== 0)
                    
            {
                        hash 
            ^= ((hash << 7^ (*str++^ (hash >> 3));
                    }

                    
            else
                    
            {
                        hash 
            ^= (~((hash << 11^ (*str++^ (hash >> 5)));
                    }

                }

             
                
            return (hash & 0x7FFFFFFF);
            }


            得分第三:

            // DJB Hash Function
            unsigned int DJBHash(char *str)
            {
                unsigned 
            int hash = 5381;
             
                
            while (*str)
                
            {
                    hash 
            += (hash << 5+ (*str++);
                }

             
                
            return (hash & 0x7FFFFFFF);
            }


            得分第四:

            // JS Hash Function
            unsigned int JSHash(char *str)
            {
                unsigned 
            int hash = 1315423911;
             
                
            while (*str)
                
            {
                    hash 
            ^= ((hash << 5+ (*str+++ (hash >> 2));
                }

             
                
            return (hash & 0x7FFFFFFF);
            }


             

            另外,此處也有一篇文章,其中提及了另外幾種效率也頗高的hash算法

            http://programmers.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed/145633#145633 


             

            posted @ 2012-08-14 20:32 寰子 閱讀(386) | 評論 (1)編輯 收藏

             

            double CCarNaviView::CalculateRotateAngle(CPoint pntBegin,CPoint pntNext)
            {
                CPoint pntFirst(pntBegin);
                CPoint pntSecond(pntNext);

                
            double dRotateAngle = atan2(fabs(pntBegin.x-pntNext.x),fabs(pntBegin.y-pntNext.y));
             
                
            //如果下一點的橫坐標大于前一點(在第一和第四象限)
                if (pntNext.x>=pntFirst.x)
                
            {
                    
            //在第一象限(0<=dRotateAngle<=90)
                    if (pntNext.y>=pntFirst.y)
                    
            {
                        
            //不做任何處理
                        dRotateAngle=dRotateAngle;
                    }

                    
            else
                    
            {
                        dRotateAngle
            =PI-dRotateAngle;
                    }

                }

                
            else//(在第二和第三象限)
                {
                    
            //第二象限
                    if (pntNext.y>=pntFirst.y)
                    
            {
                        dRotateAngle
            =2*PI-dRotateAngle;
                    }

                    
            else//第三象限
                    {
                        dRotateAngle
            =PI+dRotateAngle;
                    }

                }

                dRotateAngle 
            = dRotateAngle * 180 / PI;
                
            return dRotateAngle;
            }

            posted @ 2012-08-14 20:28 寰子 閱讀(1471) | 評論 (1)編輯 收藏
            僅列出標題  
            91精品国产综合久久婷婷| 亚洲?V乱码久久精品蜜桃 | 亚洲天堂久久精品| 国产成人99久久亚洲综合精品 | 久久亚洲精精品中文字幕| 国产99精品久久| 青青热久久国产久精品 | 婷婷久久综合九色综合98| 精品久久久久久久久久中文字幕| 久久亚洲视频| 国内精品久久国产大陆| 久久精品国产2020| 久久九色综合九色99伊人| 精品蜜臀久久久久99网站| 久久亚洲国产精品五月天婷| 久久66热人妻偷产精品9| 色婷婷狠狠久久综合五月| 久久综合久久综合九色| 人人狠狠综合久久88成人| 欧美久久综合九色综合| 国产免费久久精品丫丫| 久久福利青草精品资源站| 久久综合给合久久狠狠狠97色69 | 国产美女亚洲精品久久久综合| 久久国产精品-久久精品| 久久久国产99久久国产一| 青青青青久久精品国产| 久久国产精品无码一区二区三区| 老男人久久青草av高清| 人妻系列无码专区久久五月天| 中文字幕亚洲综合久久| 99麻豆久久久国产精品免费| 少妇高潮惨叫久久久久久| yy6080久久| 伊人色综合久久天天人手人婷| 精品久久久久久无码不卡| 亚洲一级Av无码毛片久久精品| 久久精品无码av| 伊人久久大香线蕉精品不卡| 久久免费视频1| 久久久久久综合网天天|