• <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年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            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 寰子 閱讀(452) | 評論 (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 寰子 閱讀(403) | 評論 (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 寰子 閱讀(1481) | 評論 (1)編輯 收藏
            僅列出標題  
            久久精品中文字幕无码绿巨人| 伊人久久无码中文字幕| 亚洲精品国产成人99久久| 伊人色综合久久天天| 亚洲性久久久影院| 久久午夜羞羞影院免费观看| 久久国产精品一区二区| 久久久亚洲精品蜜桃臀| 久久精品人人做人人爽电影蜜月| 99久久国产综合精品成人影院| 三级三级久久三级久久| 久久美女人爽女人爽| 色婷婷综合久久久久中文 | 久久久久亚洲AV片无码下载蜜桃| 老色鬼久久亚洲AV综合| 久久男人AV资源网站| 久久综合丁香激情久久| 久久成人国产精品免费软件| 精品久久久久久无码中文字幕 | 日日噜噜夜夜狠狠久久丁香五月| 精品久久久无码中文字幕天天| 97久久精品午夜一区二区| 久久精品国产清自在天天线| 久久五月精品中文字幕| 久久本道伊人久久| 国产精品久久久久久| 久久精品www人人爽人人| 日韩久久久久久中文人妻| 日韩欧美亚洲综合久久| 伊人久久大香线蕉精品不卡 | 久久精品国产99久久无毒不卡 | 狠狠色噜噜色狠狠狠综合久久| 久久人妻少妇嫩草AV蜜桃| 久久久精品波多野结衣| 精品久久久久久无码中文野结衣| 九九热久久免费视频| 国产激情久久久久影院老熟女| 亚洲一区二区三区日本久久九| 亚洲国产精品人久久| 精品久久久久久无码中文字幕 | 久久国产精品免费一区二区三区|