diff --git a/chunker/chunker.go b/chunker/chunker.go index e9d583937..7d94ede0b 100644 --- a/chunker/chunker.go +++ b/chunker/chunker.go @@ -25,8 +25,8 @@ const ( ) type tables struct { - out [256]uint64 - mod [256]uint64 + out [256]Pol + mod [256]Pol } // cache precomputed tables, these are read-only anyway @@ -151,13 +151,13 @@ func (c *Chunker) fill_tables() { // // Afterwards a new byte can be shifted in. for b := 0; b < 256; b++ { - var hash uint64 + var h Pol - hash = append_byte(hash, byte(b), uint64(c.pol)) + h = append_byte(h, byte(b), c.pol) for i := 0; i < WindowSize-1; i++ { - hash = append_byte(hash, 0, uint64(c.pol)) + h = append_byte(h, 0, c.pol) } - c.tables.out[b] = hash + c.tables.out[b] = h } // calculate table for reduction mod Polynomial @@ -170,7 +170,7 @@ func (c *Chunker) fill_tables() { // two parts: Part A contains the result of the modulus operation, part // B is used to cancel out the 8 top bits so that one XOR operation is // enough to reduce modulo Polynomial - c.tables.mod[b] = mod(uint64(b)<= deg(p) { - shift := uint(deg(x) - deg(p)) - - x = x ^ (p << shift) - } - - return x -} - -// Deg returns the degree of the polynomial p, this is equivalent to the number -// of the highest bit set in p. -func deg(p uint64) int { - var mask uint64 = 0x8000000000000000 - - for i := 0; i < 64; i++ { - if mask&p > 0 { - return 63 - i - } - - mask >>= 1 - } - - return -1 + return hash.Mod(pol) } diff --git a/chunker/polynomials.go b/chunker/polynomials.go index 6a0caef86..355da1095 100644 --- a/chunker/polynomials.go +++ b/chunker/polynomials.go @@ -64,12 +64,14 @@ func (x Pol) Deg() int { return -1 } + var mask Pol = (1 << 63) for i := 63; i >= 0; i-- { // test if bit i is set - if x&(1< 0 { + if x&mask > 0 { // this is the degree of x return i } + mask >>= 1 } // fall-through, return -1