LCOV - code coverage report
Current view: top level - src - hash_functions.cc (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 12 21 57.1 %
Date: 2015-01-12 15:17:13 Functions: 2 4 50.0 %
Branches: 4 4 100.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
       2                 :            : /*
       3                 :            :  * Hash Functions
       4                 :            :  * (C) 2013  Jung-Sang Ahn <jungsang.ahn@gmail.com>
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "hash_functions.h"
       8                 :            : #include "common.h"
       9                 :            : 
      10                 :            : // djb2 hashing using last LEN digits in VALUE
      11                 :         35 : uint32_t hash_djb2(uint8_t *value, int len)
      12                 :            : {
      13                 :         35 :     unsigned hash = 5381;
      14         [ +  + ]: 1073742151 :     while(len--){
      15                 : 1073742116 :         hash = ((hash << 5) + hash) + *((uint8_t*)value + len);
      16                 :            :     }
      17                 :         35 :     return hash;
      18                 :            : }
      19                 :            : 
      20                 :          4 : uint32_t hash_djb2_last8(uint8_t *value, int len)
      21                 :            : {
      22                 :          4 :     int min = MIN(len, 8), c;
      23                 :          4 :     unsigned hash = 5381;
      24                 :          4 :     c = min;
      25         [ +  + ]:         36 :     while(c--){
      26                 :         32 :         hash = ((hash << 5) + hash) + *((uint8_t*)value + (len - min) + c);
      27                 :            :     }
      28                 :          4 :     return hash;
      29                 :            : }
      30                 :            : 
      31                 :          0 : uint32_t hash_uint_modular(uint64_t value, uint64_t mod)
      32                 :            : {
      33                 :          0 :     return value % mod;
      34                 :            : }
      35                 :            : 
      36                 :          0 : uint32_t hash_shuffle_2uint(uint64_t a, uint64_t b)
      37                 :            : {
      38                 :            :     uint32_t c;
      39                 :            : 
      40                 :          0 :     a ^= bitswap64(a ^ UINT64_C(0xffffffffffffffff));
      41                 :          0 :     b ^= bitswap64(b ^ UINT64_C(0xffffffffffffffff));
      42                 :            : 
      43                 :            :     a = (a & 0xffff) ^ ((a & 0xffff0000) >> 16) ^
      44                 :            :         ((a & UINT64_C(0xffff00000000)) >> 32) ^
      45                 :          0 :         ((a & UINT64_C(0xffff000000000000)) >> 48);
      46                 :            :     b = (b & 0xffff) ^ ((b & 0xffff0000) >> 16) ^
      47                 :            :         ((b & UINT64_C(0xffff00000000)) >> 32) ^
      48                 :          0 :         ((b & UINT64_C(0xffff000000000000)) >> 48);
      49                 :            : 
      50                 :            :     c = (((a & 0x0000000f) << 0) |
      51                 :            :         ((b & 0x0000000f) << 4) |
      52                 :            :         ((a & 0x000000f0) << 4) |
      53                 :            :         ((b & 0x000000f0) << 8) |
      54                 :            :         ((a & 0x00000f00) << 8) |
      55                 :            :         ((b & 0x00000f00) << 12) |
      56                 :            :         ((a & 0x0000f000) << 12) |
      57                 :          0 :         ((b & 0x0000f000) << 16));
      58                 :            : 
      59                 :          0 :     return (((c << 5) + c) << 5) + c;
      60                 :            : }
      61                 :            : 

Generated by: LCOV version 1.11