• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 15923993233

27 Jun 2025 10:20AM UTC coverage: 65.637% (-0.02%) from 65.656%
15923993233

Pull #15735

github

web-flow
Merge 883aec59c into ecbd3685b
Pull Request #15735: lmdb-safe: Improve the scalability of transaction maps

41581 of 91868 branches covered (45.26%)

Branch coverage included in aggregate %.

44 of 56 new or added lines in 1 file covered. (78.57%)

4906 existing lines in 99 files now uncovered.

126844 of 164732 relevant lines covered (77.0%)

6073148.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.4
/pdns/burtle.hh
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22

23
#pragma once
24

25
#include <cinttypes>
26

27
inline void burtlemix(uint32_t& a, uint32_t& b, uint32_t& c)
28
{
74,739,565✔
29
  a -= b;
74,739,565✔
30
  a -= c;
74,739,565✔
31
  a ^= (c >> 13);
74,739,565✔
32
  b -= c;
74,739,565✔
33
  b -= a;
74,739,565✔
34
  b ^= (a << 8);
74,739,565✔
35
  c -= a;
74,739,565✔
36
  c -= b;
74,739,565✔
37
  c ^= (b >> 13);
74,739,565✔
38
  a -= b;
74,739,565✔
39
  a -= c;
74,739,565✔
40
  a ^= (c >> 12);
74,739,565✔
41
  b -= c;
74,739,565✔
42
  b -= a;
74,739,565✔
43
  b ^= (a << 16);
74,739,565✔
44
  c -= a;
74,739,565✔
45
  c -= b;
74,739,565✔
46
  c ^= (b >> 5);
74,739,565✔
47
  a -= b;
74,739,565✔
48
  a -= c;
74,739,565✔
49
  a ^= (c >> 3);
74,739,565✔
50
  b -= c;
74,739,565✔
51
  b -= a;
74,739,565✔
52
  b ^= (a << 10);
74,739,565✔
53
  c -= a;
74,739,565✔
54
  c -= b;
74,739,565✔
55
  c ^= (b >> 15);
74,739,565✔
56
}
74,739,565✔
57

58
inline uint32_t burtle(const unsigned char* k, uint32_t length, uint32_t initval)
59
{
10,437,914✔
60
  uint32_t a, b, c, len;
10,437,914✔
61

62
  /* Set up the internal state */
63
  len = length;
10,437,914✔
64
  a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
10,437,914✔
65
  c = initval; /* the previous hash value */
10,437,914✔
66

67
  /*---------------------------------------- handle most of the key */
68
  while (len >= 12) {
10,477,483✔
69
    a += (k[0] + ((uint32_t)k[1] << 8) + ((uint32_t)k[2] << 16) + ((uint32_t)k[3] << 24));
39,569✔
70
    b += (k[4] + ((uint32_t)k[5] << 8) + ((uint32_t)k[6] << 16) + ((uint32_t)k[7] << 24));
39,569✔
71
    c += (k[8] + ((uint32_t)k[9] << 8) + ((uint32_t)k[10] << 16) + ((uint32_t)k[11] << 24));
39,569✔
72
    burtlemix(a, b, c);
39,569✔
73
    k += 12;
39,569✔
74
    len -= 12;
39,569✔
75
  }
39,569✔
76

77
  /*------------------------------------- handle the last 11 bytes */
78
  c += length;
10,437,914✔
79
  switch (len) { /* all the case statements fall through */
10,437,914✔
UNCOV
80
  case 11:
38✔
UNCOV
81
    c += ((uint32_t)k[10] << 24);
38✔
82
    /* fall-through */
83
  case 10:
3,552,323✔
84
    c += ((uint32_t)k[9] << 16);
3,552,323✔
85
    /* fall-through */
86
  case 9:
3,552,334✔
87
    c += ((uint32_t)k[8] << 8);
3,552,334✔
88
    /* the first byte of c is reserved for the length */
89
    /* fall-through */
90
  case 8:
3,552,375✔
91
    b += ((uint32_t)k[7] << 24);
3,552,375✔
92
    /* fall-through */
93
  case 7:
3,553,842✔
94
    b += ((uint32_t)k[6] << 16);
3,553,842✔
95
    /* fall-through */
96
  case 6:
3,553,861✔
97
    b += ((uint32_t)k[5] << 8);
3,553,861✔
98
    /* fall-through */
99
  case 5:
3,553,861!
100
    b += k[4];
3,553,861✔
101
    /* fall-through */
102
  case 4:
7,710,367✔
103
    a += ((uint32_t)k[3] << 24);
7,710,367✔
104
    /* fall-through */
105
  case 3:
7,736,444✔
106
    a += ((uint32_t)k[2] << 16);
7,736,444✔
107
    /* fall-through */
108
  case 2:
7,764,799✔
109
    a += ((uint32_t)k[1] << 8);
7,764,799✔
110
    /* fall-through */
111
  case 1:
10,516,016✔
112
    a += k[0];
10,516,016✔
113
    /* case 0: nothing left to add */
114
  }
10,437,914✔
115
  burtlemix(a, b, c);
10,458,524✔
116
  /*-------------------------------------------- report the result */
117
  return c;
10,458,393✔
118
}
10,437,914✔
119

120
inline uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t initval)
121
{
35,957,767✔
122
  uint32_t a, b, c, len;
35,957,767✔
123

124
  /* Set up the internal state */
125
  len = length;
35,957,767✔
126
  a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
35,957,767✔
127
  c = initval; /* the previous hash value */
35,957,767✔
128

129
  /*---------------------------------------- handle most of the key */
130
  while (len >= 12) {
64,209,990✔
131
    a += (dns_tolower(k[0]) + ((uint32_t)dns_tolower(k[1]) << 8) + ((uint32_t)dns_tolower(k[2]) << 16) + ((uint32_t)dns_tolower(k[3]) << 24));
28,252,223✔
132
    b += (dns_tolower(k[4]) + ((uint32_t)dns_tolower(k[5]) << 8) + ((uint32_t)dns_tolower(k[6]) << 16) + ((uint32_t)dns_tolower(k[7]) << 24));
28,252,223✔
133
    c += (dns_tolower(k[8]) + ((uint32_t)dns_tolower(k[9]) << 8) + ((uint32_t)dns_tolower(k[10]) << 16) + ((uint32_t)dns_tolower(k[11]) << 24));
28,252,223✔
134
    burtlemix(a, b, c);
28,252,223✔
135
    k += 12;
28,252,223✔
136
    len -= 12;
28,252,223✔
137
  }
28,252,223✔
138

139
  /*------------------------------------- handle the last 11 bytes */
140
  c += length;
35,957,767✔
141
  switch (len) { /* all the case statements fall through */
35,957,767✔
142
  case 11:
6,651,580✔
143
    c += ((uint32_t)dns_tolower(k[10]) << 24);
6,651,580✔
144
    /* fall-through */
145
  case 10:
8,244,733✔
146
    c += ((uint32_t)dns_tolower(k[9]) << 16);
8,244,733✔
147
    /* fall-through */
148
  case 9:
9,009,131✔
149
    c += ((uint32_t)dns_tolower(k[8]) << 8);
9,009,131✔
150
    /* the first byte of c is reserved for the length */
151
    /* fall-through */
152
  case 8:
10,448,985✔
153
    b += ((uint32_t)dns_tolower(k[7]) << 24);
10,448,985✔
154
    /* fall-through */
155
  case 7:
10,829,445✔
156
    b += ((uint32_t)dns_tolower(k[6]) << 16);
10,829,445✔
157
    /* fall-through */
158
  case 6:
11,147,479✔
159
    b += ((uint32_t)dns_tolower(k[5]) << 8);
11,147,479✔
160
    /* fall-through */
161
  case 5:
11,603,300✔
162
    b += dns_tolower(k[4]);
11,603,300✔
163
    /* fall-through */
164
  case 4:
15,783,809✔
165
    a += ((uint32_t)dns_tolower(k[3]) << 24);
15,783,809✔
166
    /* fall-through */
167
  case 3:
18,111,672✔
168
    a += ((uint32_t)dns_tolower(k[2]) << 16);
18,111,672✔
169
    /* fall-through */
170
  case 2:
25,371,406✔
171
    a += ((uint32_t)dns_tolower(k[1]) << 8);
25,371,406✔
172
    /* fall-through */
173
  case 1:
31,076,852✔
174
    a += dns_tolower(k[0]);
31,076,852✔
175
    /* case 0: nothing left to add */
176
  }
35,957,767✔
177
  burtlemix(a, b, c);
36,012,678✔
178
  /*-------------------------------------------- report the result */
179
  return c;
36,003,850✔
180
}
35,957,767✔
181

182
template <typename T>
183
inline uint32_t burtleCI(const T& k, uint32_t initval)
184
{
32,061,258✔
185
  return burtleCI(reinterpret_cast<const unsigned char*>(k.data()), k.length(), initval); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): can't static_cast because of sign difference
32,061,258✔
186
}
32,061,258✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc