proxygen
folly::Fingerprint< BITS > Class Template Reference

#include <Fingerprint.h>

Public Member Functions

 Fingerprint ()
 
Fingerprintupdate8 (uint8_t v)
 
Fingerprintupdate32 (uint32_t v)
 
Fingerprintupdate64 (uint64_t v)
 
Fingerprintupdate (StringPiece str)
 
void write (uint64_t *out) const
 

Static Public Member Functions

static constexpr int size ()
 

Private Member Functions

void xortab (std::array< uint64_t, detail::poly_size(BITS)> const &tab)
 
uint8_t shlor8 (uint8_t v)
 
uint32_t shlor32 (uint32_t v)
 
uint64_t shlor64 (uint64_t v)
 
template<>
uint8_t shlor8 (uint8_t v)
 
template<>
uint32_t shlor32 (uint32_t v)
 
template<>
uint64_t shlor64 (uint64_t v)
 
template<>
uint8_t shlor8 (uint8_t v)
 
template<>
uint32_t shlor32 (uint32_t v)
 
template<>
uint64_t shlor64 (uint64_t v)
 
template<>
uint8_t shlor8 (uint8_t v)
 
template<>
uint32_t shlor32 (uint32_t v)
 
template<>
uint64_t shlor64 (uint64_t v)
 

Private Attributes

uint64_t fp_ [detail::poly_size(BITS)]
 

Detailed Description

template<int BITS>
class folly::Fingerprint< BITS >

Compute the Rabin fingerprint.

TODO(tudorb): Extend this to allow removing values from the computed fingerprint (so we can fingerprint a sliding window, as in the Rabin-Karp string matching algorithm)

update* methods return *this, so you can chain them together: Fingerprint<96>().update8(x).update(str).update64(val).write(output);

Definition at line 105 of file Fingerprint.h.

Constructor & Destructor Documentation

template<int BITS>
folly::Fingerprint< BITS >::Fingerprint ( )
inline

Definition at line 107 of file Fingerprint.h.

References i, and folly::size().

107  {
108  // Use a non-zero starting value. We'll use (1 << (BITS-1))
109  fp_[0] = 1ULL << 63;
110  for (int i = 1; i < size(); i++) {
111  fp_[i] = 0;
112  }
113  }
static constexpr int size()
Definition: Fingerprint.h:153
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186

Member Function Documentation

template<int BITS>
uint32_t folly::Fingerprint< BITS >::shlor32 ( uint32_t  v)
private
template<>
uint32_t folly::Fingerprint< 64 >::shlor32 ( uint32_t  v)
inlineprivate

Definition at line 232 of file Fingerprint.h.

References uint32_t, uint64_t, and v.

232  {
233  uint32_t out = (uint32_t)(fp_[0] >> 32);
234  fp_[0] = (fp_[0] << 32) | ((uint64_t)v);
235  return out;
236 }
auto v
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<>
uint32_t folly::Fingerprint< 96 >::shlor32 ( uint32_t  v)
inlineprivate

Definition at line 254 of file Fingerprint.h.

References uint32_t, and uint64_t.

254  {
255  uint32_t out = (uint32_t)(fp_[0] >> 32);
256  fp_[0] = (fp_[0] << 32) | (fp_[1] >> 32);
257  fp_[1] = ((uint64_t)v << 32);
258  return out;
259 }
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<>
uint32_t folly::Fingerprint< 128 >::shlor32 ( uint32_t  v)
inlineprivate

Definition at line 278 of file Fingerprint.h.

References uint32_t, uint64_t, and v.

278  {
279  uint32_t out = (uint32_t)(fp_[0] >> 32);
280  fp_[0] = (fp_[0] << 32) | (fp_[1] >> 32);
281  fp_[1] = (fp_[1] << 32) | ((uint64_t)v);
282  return out;
283 }
auto v
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<int BITS>
uint64_t folly::Fingerprint< BITS >::shlor64 ( uint64_t  v)
private
template<>
uint64_t folly::Fingerprint< 64 >::shlor64 ( uint64_t  v)
inlineprivate

Definition at line 239 of file Fingerprint.h.

References uint64_t, and v.

239  {
240  uint64_t out = fp_[0];
241  fp_[0] = v;
242  return out;
243 }
auto v
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<>
uint64_t folly::Fingerprint< 96 >::shlor64 ( uint64_t  v)
inlineprivate

Definition at line 262 of file Fingerprint.h.

References uint64_t.

262  {
263  uint64_t out = fp_[0];
264  fp_[0] = fp_[1] | (v >> 32);
265  fp_[1] = v << 32;
266  return out;
267 }
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<>
uint64_t folly::Fingerprint< 128 >::shlor64 ( uint64_t  v)
inlineprivate

Definition at line 286 of file Fingerprint.h.

References uint64_t, and v.

286  {
287  uint64_t out = fp_[0];
288  fp_[0] = fp_[1];
289  fp_[1] = v;
290  return out;
291 }
auto v
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<int BITS>
uint8_t folly::Fingerprint< BITS >::shlor8 ( uint8_t  v)
private
template<>
uint8_t folly::Fingerprint< 64 >::shlor8 ( uint8_t  v)
inlineprivate

Definition at line 225 of file Fingerprint.h.

References uint64_t, uint8_t, and v.

225  {
226  uint8_t out = (uint8_t)(fp_[0] >> 56);
227  fp_[0] = (fp_[0] << 8) | ((uint64_t)v);
228  return out;
229 }
auto v
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<>
uint8_t folly::Fingerprint< 96 >::shlor8 ( uint8_t  v)
inlineprivate

Definition at line 246 of file Fingerprint.h.

References uint64_t, and uint8_t.

246  {
247  uint8_t out = (uint8_t)(fp_[0] >> 56);
248  fp_[0] = (fp_[0] << 8) | (fp_[1] >> 56);
249  fp_[1] = (fp_[1] << 8) | ((uint64_t)v << 32);
250  return out;
251 }
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<>
uint8_t folly::Fingerprint< 128 >::shlor8 ( uint8_t  v)
inlineprivate

Definition at line 270 of file Fingerprint.h.

References uint64_t, uint8_t, and v.

270  {
271  uint8_t out = (uint8_t)(fp_[0] >> 56);
272  fp_[0] = (fp_[0] << 8) | (fp_[1] >> 56);
273  fp_[1] = (fp_[1] << 8) | ((uint64_t)v);
274  return out;
275 }
auto v
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<int BITS>
static constexpr int folly::Fingerprint< BITS >::size ( )
inlinestatic

Return the number of uint64s needed to hold the fingerprint value.

Definition at line 153 of file Fingerprint.h.

References folly::detail::poly_size().

153  {
154  return detail::poly_size(BITS);
155  }
constexpr size_t poly_size(size_t bits)
Definition: Fingerprint.h:55
template<int BITS>
Fingerprint& folly::Fingerprint< BITS >::update ( StringPiece  str)
inline

Definition at line 142 of file Fingerprint.h.

References c, and uint8_t.

142  {
143  // TODO(tudorb): We could be smart and do update64 or update32 if aligned
144  for (auto c : str) {
145  update8(uint8_t(c));
146  }
147  return *this;
148  }
Fingerprint & update8(uint8_t v)
Definition: Fingerprint.h:115
char c
template<int BITS>
Fingerprint& folly::Fingerprint< BITS >::update32 ( uint32_t  v)
inline

Definition at line 124 of file Fingerprint.h.

References i, and uint32_t.

Referenced by TEST().

124  {
125  uint32_t out = shlor32(v);
126  for (int i = 0; i < 4; i++) {
128  out >>= 8;
129  }
130  return *this;
131  }
const poly_table< 64 > table
void xortab(std::array< uint64_t, detail::poly_size(BITS)> const &tab)
Definition: Fingerprint.h:173
uint32_t shlor32(uint32_t v)
template<int BITS>
Fingerprint& folly::Fingerprint< BITS >::update64 ( uint64_t  v)
inline

Definition at line 133 of file Fingerprint.h.

References i, and uint64_t.

Referenced by TEST().

133  {
134  uint64_t out = shlor64(v);
135  for (int i = 0; i < 8; i++) {
137  out >>= 8;
138  }
139  return *this;
140  }
uint64_t shlor64(uint64_t v)
const poly_table< 64 > table
void xortab(std::array< uint64_t, detail::poly_size(BITS)> const &tab)
Definition: Fingerprint.h:173
template<int BITS>
Fingerprint& folly::Fingerprint< BITS >::update8 ( uint8_t  v)
inline

Definition at line 115 of file Fingerprint.h.

References uint8_t.

Referenced by TEST().

115  {
116  uint8_t out = shlor8(v);
118  return *this;
119  }
uint8_t shlor8(uint8_t v)
const poly_table< 64 > table
void xortab(std::array< uint64_t, detail::poly_size(BITS)> const &tab)
Definition: Fingerprint.h:173
template<int BITS>
void folly::Fingerprint< BITS >::write ( uint64_t out) const
inline

Write the computed fingeprint to an array of size() uint64_t's. For Fingerprint<64>, size()==1; we write 64 bits in out[0] For Fingerprint<96>, size()==2; we write 64 bits in out[0] and the most significant 32 bits of out[1] For Fingerprint<128>, size()==2; we write 64 bits in out[0] and 64 bits in out[1].

Definition at line 165 of file Fingerprint.h.

References i, and folly::size().

Referenced by folly::fingerprint128(), folly::fingerprint64(), folly::fingerprint96(), and TEST().

165  {
166  for (int i = 0; i < size(); i++) {
167  out[i] = fp_[i];
168  }
169  }
static constexpr int size()
Definition: Fingerprint.h:153
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186
template<int BITS>
void folly::Fingerprint< BITS >::xortab ( std::array< uint64_t, detail::poly_size(BITS)> const &  tab)
inlineprivate

Definition at line 173 of file Fingerprint.h.

References i, folly::size(), uint32_t, uint64_t, and uint8_t.

173  {
174  for (int i = 0; i < size(); i++) {
175  fp_[i] ^= tab[i];
176  }
177  }
static constexpr int size()
Definition: Fingerprint.h:153
uint64_t fp_[detail::poly_size(BITS)]
Definition: Fingerprint.h:186

Member Data Documentation

template<int BITS>
uint64_t folly::Fingerprint< BITS >::fp_[detail::poly_size(BITS)]
private

Definition at line 186 of file Fingerprint.h.


The documentation for this class was generated from the following file: