File: rolling_hash.cc

package info (click to toggle)
zbackup 1.5-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 868 kB
  • sloc: cpp: 6,957; ansic: 468; python: 207; makefile: 10
file content (29 lines) | stat: -rw-r--r-- 649 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE

#include "rolling_hash.hh"

RollingHash::RollingHash()
{
  reset();
}

void RollingHash::reset()
{
  count = 0;
  factor = 0;
  nextFactor = 1;
  value = 0;
}

RollingHash::Digest RollingHash::digest( void const * buf, unsigned size )
{
  // TODO: this can be optimized, as in this case there's no need to calculate
  // factor values.
  RollingHash hash;

  for ( char const * p = ( char const * )buf; size--; )
    hash.rollIn( *p++ );

  return hash.digest();
}