Nginx原始碼完全註釋(6)core/murmurhash
Nginx原始碼完全註釋(6)murmurhash
- 作者:柳大·Poechant(鍾超)
- 郵箱:zhongchao.ustc#gmail.com(# -> @)
- 部落格:Blog.CSDN.net/Poechant
- 日期:August 18th, 2012
MurmurHash2 was written by Austin Appleby, and is placed in the public domain. The author hereby disclaims copyright to this source code.
下面是摘自 Google Code 的 Murmurhash 開源專案主頁上的 Murmurhash2,Nginx 就是採用的這個。
uint32_t MurmurHash2 ( const void * key, int len, uint32_t seed )
{
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
const uint32_t m = 0x5bd1e995;
const int r = 24;
// Initialize the hash to a 'random' value
uint32_t h = seed ^ len;
// Mix 4 bytes at a time into the hash
const unsigned char * data = (const unsigned char *)key;
while(len >= 4)
{
uint32_t k = *(uint32_t*)data;
k *= m;
k ^= k >> r;
k *= m;
h *= m;
h ^= k;
data += 4;
len -= 4;
}
// Handle the last few bytes of the input array
switch(len)
{
case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8;
case 1: h ^= data[0];
h *= m;
};
// Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >> 13;
h *= m;
h ^= h >> 15;
return h;
}
下面是 Nginx 中 Murmurhash 的原始碼,基本與上面無異。
uint32_t
ngx_murmur_hash2(u_char *data, size_t len)
{
uint32_t h, k;
h = 0 ^ len;
while (len >= 4) {
k = data[0];
k |= data[1] << 8;
k |= data[2] << 16;
k |= data[3] << 24;
k *= 0x5bd1e995;
k ^= k >> 24;
k *= 0x5bd1e995;
h *= 0x5bd1e995;
h ^= k;
data += 4;
len -= 4;
}
switch (len) {
case 3:
h ^= data[2] << 16;
case 2:
h ^= data[1] << 8;
case 1:
h ^= data[0];
h *= 0x5bd1e995;
}
h ^= h >> 13;
h *= 0x5bd1e995;
h ^= h >> 15;
return h;
}
Reference
-
轉載請註明來自柳大Poechant(鍾超Michael)的CSDN部落格:
鍾超Michael的部落格:Blog.CSDN.net/Poechant
鍾超Michael的微博:鍾超Michael的新浪微博
-
相關文章
- Nginx原始碼完全註釋(5)core/ngx_cpuinfo.cNginx原始碼UI
- Nginx原始碼完全註釋(8)ngx_errno.cNginx原始碼
- Nginx原始碼完全註釋(9)nginx.c: ngx_get_optionsNginx原始碼
- 原始碼完全註釋:socket select原始碼
- Nginx原始碼完全註釋(1)ngx_alloc.h / ngx_alloc.cNginx原始碼
- Nginx原始碼完全註釋(7)ngx_palloc.h/ngx_palloc.cNginx原始碼
- Nginx原始碼完全註釋(4)ngx_queue.h / ngx_queue.cNginx原始碼
- Nginx原始碼完全註釋(3)ngx_list.h / ngx_list.cNginx原始碼
- Nginx原始碼完全註釋(2)ngx_array.h / ngx_array.cNginx原始碼
- Nginx 原始碼完全剖析(11)ngx_spinlockNginx原始碼
- Nginx 原始碼完全剖析(10)ngx_radix_treeNginx原始碼
- HashMap原始碼(JDK1.8)-手動註釋HashMap原始碼JDK
- Bootstrap的Model原始碼詳細註釋 (轉)boot原始碼
- nginx編譯出現的問題ngx_murmurhash.ofailedNginx編譯AI
- EventBus原始碼解讀詳細註釋(6)從事件釋出到事件處理,究竟發生了什麼!原始碼事件
- Vue2.0原始碼學習(6) - 元件註冊Vue原始碼元件
- Nginx篇--Nginx原始碼搭建Nginx原始碼
- Redux原始碼完全解讀Redux原始碼
- EF Core 原始碼分析原始碼
- bootstrap-modal.js學習筆記(原始碼註釋)bootJS筆記原始碼
- Dubbo原始碼解析之服務釋出與註冊原始碼
- 從Python原始碼註釋,自動生成API文件Python原始碼API
- 使用ehcache元註釋提高Spring 效能原始碼案例Spring原始碼
- C231n-KNN-assignment1-完全程式碼及註釋KNN
- C231n-SVM-assignment1-完全程式碼及註釋
- nginx原始碼安裝Nginx原始碼
- NGINX原始碼閱讀Nginx原始碼
- Nginx 原始碼安裝Nginx原始碼
- 原始碼安裝Nginx原始碼Nginx
- Nginx的nginx.conf配置檔案中文註釋說明Nginx
- CSS程式碼註釋CSS
- php程式碼註釋PHP
- .NET Core Session原始碼探究Session原始碼
- .NET Core HttpClient原始碼探究HTTPclient原始碼
- maven下載原始碼,解決中文註釋為亂碼的問題Maven原始碼
- DialogFragment使用到原始碼完全解析Fragment原始碼
- 發行版釋出:Fedora Core6(轉)
- ArcGIS VBA - VBA+AO入門15例完全註釋版