2010-11-19 2 views
2
1. static inline ulong zend_inline_hash_func(char *arKey, uint nKeyLength) 
    2. { 
    3.  register ulong hash = 5381; 
    4. 
    5.  /* variant with the hash unrolled eight times */ 
    6.  for (; nKeyLength >= 8; nKeyLength -= 8) { 
    7.   hash = ((hash << 5) + hash) + *arKey++; 
    8.   hash = ((hash << 5) + hash) + *arKey++; 
    9.   hash = ((hash << 5) + hash) + *arKey++; 
    10.   hash = ((hash << 5) + hash) + *arKey++; 
    11.   hash = ((hash << 5) + hash) + *arKey++; 
    12.   hash = ((hash << 5) + hash) + *arKey++; 
    13.   hash = ((hash << 5) + hash) + *arKey++; 
    14.   hash = ((hash << 5) + hash) + *arKey++; 
    15.  } 
    16.  switch (nKeyLength) { 
    17.   case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ 
    18.   case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ 
    19.   case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ 
    20.   case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ 
    21.   case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ 
    22.   case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ 
    23.   case 1: hash = ((hash << 5) + hash) + *arKey++; break; 
    24.   case 0: break; 
    25. EMPTY_SWITCH_DEFAULT_CASE() 
    26.  } 
    27.  return hash; 
    28. } 

답변

4

모든 해시 테이블은 해시 알고리즘을 사용합니다. PHP의 해시 테이블은 예를 들어 배열과 기호 테이블을 구현하는 데 사용됩니다. 에서 지적한 알고리즘은 DJBX33A (Daniel J. Bernstein, Times 33 with Addition)입니다.

+0

PHP 사용자를위한 api가 없기 때문에 PHP 내부에서만 사용됩니다. – ajx

+1

나는 이것에 대해서도 답할 것이지만, 확실하지 않고 소스를 찾기 위해 길을 잃었다. 확인한 것처럼 보입니다. +1 – BoltClock

+0

@ajx 사용자 영역에 대한 API는 없습니다. – Artefacto

관련 문제