LCOV - code coverage report
Current view: top level - src/leveldb/util - hash.cc (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 24 24
Test Date: 2026-06-13 06:51:50 Functions: 100.0 % 1 1
Branches: 100.0 % 6 6

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
       2                 :             : // Use of this source code is governed by a BSD-style license that can be
       3                 :             : // found in the LICENSE file. See the AUTHORS file for names of contributors.
       4                 :             : 
       5                 :             : #include "util/hash.h"
       6                 :             : 
       7                 :             : #include <string.h>
       8                 :             : 
       9                 :             : #include "util/coding.h"
      10                 :             : 
      11                 :             : namespace leveldb {
      12                 :             : 
      13                 :    20782850 : uint32_t Hash(const char* data, size_t n, uint32_t seed) {
      14                 :             :   // Similar to murmur hash
      15                 :    20782850 :   const uint32_t m = 0xc6a4a793;
      16                 :    20782850 :   const uint32_t r = 24;
      17                 :    20782850 :   const char* limit = data + n;
      18                 :    20782850 :   uint32_t h = seed ^ (n * m);
      19                 :             : 
      20                 :             :   // Pick up four bytes at a time
      21         [ +  + ]:    51653877 :   while (limit - data >= 4) {
      22                 :    30871027 :     uint32_t w = DecodeFixed32(data);
      23                 :    30871027 :     data += 4;
      24                 :    30871027 :     h += w;
      25                 :    30871027 :     h *= m;
      26                 :    30871027 :     h ^= (h >> 16);
      27                 :             :   }
      28                 :             : 
      29                 :             :   // Pick up remaining bytes
      30   [ +  +  +  + ]:    20782850 :   switch (limit - data) {
      31                 :       62107 :     case 3:
      32                 :       62107 :       h += static_cast<uint8_t>(data[2]) << 16;
      33                 :     1304676 :       [[fallthrough]];
      34                 :     1304676 :     case 2:
      35                 :     1304676 :       h += static_cast<uint8_t>(data[1]) << 8;
      36                 :    17776127 :       [[fallthrough]];
      37                 :    17776127 :     case 1:
      38                 :    17776127 :       h += static_cast<uint8_t>(data[0]);
      39                 :    17776127 :       h *= m;
      40                 :    17776127 :       h ^= (h >> r);
      41                 :    17776127 :       break;
      42                 :             :   }
      43                 :    20782850 :   return h;
      44                 :             : }
      45                 :             : 
      46                 :             : }  // namespace leveldb
        

Generated by: LCOV version 2.0-1