2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 19:38:57 +00:00

chunker: unexport WindowSize and AverageBits

This commit is contained in:
Alexander Neumann 2015-05-02 16:19:16 +02:00
parent 1f94ac724f
commit cf62eb3e15

View File

@ -12,16 +12,16 @@ const (
MiB = 1024 * KiB MiB = 1024 * KiB
// WindowSize is the size of the sliding window. // WindowSize is the size of the sliding window.
WindowSize = 64 windowSize = 64
// aim to create chunks of 20 bits or about 1MiB on average. // aim to create chunks of 20 bits or about 1MiB on average.
AverageBits = 20 averageBits = 20
// Chunks should be in the range of 512KiB to 8MiB. // Chunks should be in the range of 512KiB to 8MiB.
MinSize = 512 * KiB MinSize = 512 * KiB
MaxSize = 8 * MiB MaxSize = 8 * MiB
splitmask = (1 << AverageBits) - 1 splitmask = (1 << averageBits) - 1
) )
type tables struct { type tables struct {
@ -61,7 +61,7 @@ type Chunker struct {
rd io.Reader rd io.Reader
closed bool closed bool
window [WindowSize]byte window [windowSize]byte
wpos int wpos int
buf []byte buf []byte
@ -97,7 +97,7 @@ func (c *Chunker) Reset(rd io.Reader, p Pol) {
c.fillTables() c.fillTables()
c.rd = rd c.rd = rd
for i := 0; i < WindowSize; i++ { for i := 0; i < windowSize; i++ {
c.window[i] = 0 c.window[i] = 0
} }
c.closed = false c.closed = false
@ -116,7 +116,7 @@ func (c *Chunker) Reset(rd io.Reader, p Pol) {
} }
// do not start a new chunk unless at least MinSize bytes have been read // do not start a new chunk unless at least MinSize bytes have been read
c.pre = MinSize - WindowSize c.pre = MinSize - windowSize
} }
// Calculate out_table and mod_table for optimization. Must be called only // Calculate out_table and mod_table for optimization. Must be called only
@ -154,7 +154,7 @@ func (c *Chunker) fillTables() {
var h Pol var h Pol
h = appendByte(h, byte(b), c.pol) h = appendByte(h, byte(b), c.pol)
for i := 0; i < WindowSize-1; i++ { for i := 0; i < windowSize-1; i++ {
h = appendByte(h, 0, c.pol) h = appendByte(h, 0, c.pol)
} }
c.tables.out[b] = h c.tables.out[b] = h
@ -246,7 +246,7 @@ func (c *Chunker) Next() (*Chunk, error) {
out := c.window[c.wpos] out := c.window[c.wpos]
c.window[c.wpos] = b c.window[c.wpos] = b
c.digest ^= uint64(c.tables.out[out]) c.digest ^= uint64(c.tables.out[out])
c.wpos = (c.wpos + 1) % WindowSize c.wpos = (c.wpos + 1) % windowSize
// c.append(b) // c.append(b)
index := c.digest >> c.polShift index := c.digest >> c.polShift
@ -284,7 +284,7 @@ func (c *Chunker) Next() (*Chunk, error) {
c.Reset(c.rd, c.pol) c.Reset(c.rd, c.pol)
c.pos = pos c.pos = pos
c.start = pos c.start = pos
c.pre = MinSize - WindowSize c.pre = MinSize - windowSize
return chunk, nil return chunk, nil
} }
@ -330,7 +330,7 @@ func (c *Chunker) slide(b byte) {
out := c.window[c.wpos] out := c.window[c.wpos]
c.window[c.wpos] = b c.window[c.wpos] = b
c.digest ^= uint64(c.tables.out[out]) c.digest ^= uint64(c.tables.out[out])
c.wpos = (c.wpos + 1) % WindowSize c.wpos = (c.wpos + 1) % windowSize
c.append(b) c.append(b)
} }