File: genck.cn

package info (click to toggle)
xdelta 0.14-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 684 kB
  • ctags: 682
  • sloc: ansic: 5,668; sh: 1,740; makefile: 62
file content (84 lines) | stat: -rw-r--r-- 2,232 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* -*-Mode: C;-*-
 * XDELTA - RCS replacement and delta generator
 * Copyright (C) 1997  Josh MacDonald
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: genck.cn 1.4 Sun, 12 Oct 1997 20:29:34 -0700 jmacd $
 */

ChecksumArray*
NAME (const TYPE  *segment,
      gint         segment_len,
      gint         cksum_width,
      FromSegment *from)
{
  gint buffer_index     = cksum_width;
  gint buffer_index_old = 0;
  gint total_checksums  = segment_len / cksum_width;
  gint checksum_index   = 0;
  gint i;
  Checksum cksum;
  Checksum *result;
  ChecksumArray *array;

#ifdef DEBUG_XD
  g_print ("Total base checksums: %d\n", total_checksums);
#endif

  assert (total_checksums > 0);

  array = g_new (ChecksumArray, 1);
  result = g_new (Checksum, total_checksums);

  array->ck_count = total_checksums;
  array->ck_width = cksum_width;
  array->cksums = result;
  array->from = from;

  GCKSUM (segment, cksum_width, &cksum);

  for (;;)
    {
#ifdef DEBUG_CKSUM
      g_print ("New cksum %04x %04x indices %d-%d\n",
	       cksum.low, cksum.high,
	       buffer_index_old, buffer_index - 1);
#endif

      result[checksum_index++] = cksum;

      if (buffer_index + cksum_width > segment_len)
	break;

      for (i=0; i < cksum_width; i += 1, buffer_index += 1, buffer_index_old += 1)
	{
	  guint16 old_c = CHEW(segment[buffer_index_old]);
	  guint16 new_c = CHEW(segment[buffer_index]);

	  cksum.low  -= old_c;
	  cksum.low  += new_c;

	  cksum.high -= cksum_width * old_c;
	  cksum.high += cksum.low;
	}
    }

  return array;
}

#undef X
#undef NAME
#undef GCKSUM