func (e *snappyGen) encodeL3(dst *tokens, src []byte) {
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.prev = nil
		e.cur += len(src)
		return
	}
	if e.cur > 1<<30 {
		e.cur = 0
	}
	var (
		s   int  
		lit int  
	)
	for s+3 < len(src) {
		h := uint32(src[s]) | uint32(src[s+1])<<8 | uint32(src[s+2])<<16 | uint32(src[s+3])<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		tmp := *p
		p1 := int(tmp & 0xffffffff)  
		p2 := int(tmp >> 32)         
		t1 := p1 - 1 - e.cur
		var l2 int
		var t2 int
		l1 := e.matchlen(s, t1, src)
		if l1 < 16 {
			t2 = p2 - 1 - e.cur
			l2 = e.matchlen(s, t2, src)
			if l1 < 4 && l2 < 4 {
				*p = int64(s+1+e.cur) | (int64(p1) << 32)
				s += 1 + ((s - lit) >> 5)
				continue
			}
		}
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}
		*p = int64(s+1+e.cur) | (int64(p1) << 32)
		if l1 >= l2 {
			dst.tokens[dst.n] = matchToken(uint32(l1-3), uint32(s-t1-minOffsetSize))
			s += l1
		} else {
			dst.tokens[dst.n] = matchToken(uint32(l2-3), uint32(s-t2-minOffsetSize))
			s += l2
		}
		dst.n++
		lit = s
	}
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
	if len(src) == maxStoreBlockSize {
		copy(e.block[:], src)
		e.prev = e.block[:len(src)]
	} else {
		e.prev = nil
	}
}
EncodeL3 uses a similar algorithm to level 2, but is capable
will keep two matches per hash.
Both hashes are checked if the first isn't ok, and the longest is selected.
package flate
const maxOffset = 1 << 15
func emitLiteral(dst *tokens, lit []byte) {
	ol := dst.n
	for i, v := range lit {
		dst.tokens[i+ol] = token(v)
	}
	dst.n += len(lit)
}
func emitCopy(dst *tokens, offset, length int) {
	dst.tokens[dst.n] = matchToken(uint32(length-3), uint32(offset-minOffsetSize))
	dst.n++
}
type snappyEnc interface {
	Encode(dst *tokens, src []byte)
	Reset()
}
func newSnappy(level int) snappyEnc {
	if useSSE42 {
		e := &snappySSE4{}
		switch level {
		case 3:
			e.enc = e.encodeL3
			return e
		}
	}
	e := &snappyGen{}
	switch level {
	case 1:
		e.enc = e.encodeL1
	case 2:
		e.enc = e.encodeL2
	case 3:
		e.enc = e.encodeL3
	default:
		panic("invalid level specified")
	}
	return e
}
const tableBits = 14              
const tableSize = 1 << tableBits  
type snappyGen struct {
	table [tableSize]int64
	block [maxStoreBlockSize]byte
	prev  []byte
	cur   int
	enc   func(dst *tokens, src []byte)
}
func (e *snappyGen) Encode(dst *tokens, src []byte) {
	e.enc(dst, src)
}
func (e *snappyGen) encodeL1(dst *tokens, src []byte) {
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.cur += 4
		return
	}
	if e.cur > 1<<30 {
		e.cur = 0
	}
	var (
		s   int  
		t   int  
		lit int  
	)
	for s+3 < len(src) {
		b0, b1, b2, b3 := src[s], src[s+1], src[s+2], src[s+3]
		h := uint32(b0) | uint32(b1)<<8 | uint32(b2)<<16 | uint32(b3)<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		t, *p = int(*p)-1-e.cur, int64(s+1+e.cur)
		offset := uint(s - t - 1)
		if t < 0 || offset >= (maxOffset-1) || b0 != src[t] || b1 != src[t+1] || b2 != src[t+2] || b3 != src[t+3] {
			s += 1 + ((s - lit) >> 4)
			continue
		}
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}
		s0 := s
		s1 := s + maxMatchLength
		if s1 > len(src) {
			s1 = len(src)
		}
		s, t = s+4, t+4
		for s < s1 && src[s] == src[t] {
			s++
			t++
		}
		dst.tokens[dst.n] = matchToken(uint32(s-s0-3), uint32(s-t-minOffsetSize))
		dst.n++
		lit = s
	}
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
}
func (e *snappyGen) encodeL2(dst *tokens, src []byte) {
	if len(src) <= 4 {
		if len(src) != 0 {
			emitLiteral(dst, src)
		}
		e.prev = nil
		e.cur += len(src)
		return
	}
	if e.cur > 1<<30 {
		e.cur = 0
	}
	var (
		s   int  
		t   int  
		lit int  
	)
	for s+3 < len(src) {
		b0, b1, b2, b3 := src[s], src[s+1], src[s+2], src[s+3]
		h := uint32(b0) | uint32(b1)<<8 | uint32(b2)<<16 | uint32(b3)<<24
		p := &e.table[(h*0x1e35a7bd)>>(32-tableBits)]
		t, *p = int(*p)-1-e.cur, int64(s+1+e.cur)
		if t >= 0 {
			offset := uint(s - t - 1)
			if offset >= (maxOffset-1) || b0 != src[t] || b1 != src[t+1] || b2 != src[t+2] || b3 != src[t+3] {
				s += 1 + ((s - lit) >> 5)
				continue
			}
			if lit != s {
				emitLiteral(dst, src[lit:s])
			}
			s0 := s
			s1 := s + maxMatchLength
			if s1 > len(src) {
				s1 = len(src)
			}
			s, t = s+4, t+4
			for s < s1 && src[s] == src[t] {
				s++
				t++
			}
			dst.tokens[dst.n] = matchToken(uint32(s-s0-3), uint32(s-t-minOffsetSize))
			dst.n++
			lit = s
			continue
		}
		tp := len(e.prev) + t
		if tp < 0 || t > -5 || s-t >= maxOffset || b0 != e.prev[tp] || b1 != e.prev[tp+1] || b2 != e.prev[tp+2] || b3 != e.prev[tp+3] {
			s += 1 + ((s - lit) >> 5)
			continue
		}
		if lit != s {
			emitLiteral(dst, src[lit:s])
		}
		s0 := s
		s1 := s + maxMatchLength
		if s1 > len(src) {
			s1 = len(src)
		}
		s, tp = s+4, tp+4
		for s < s1 && src[s] == e.prev[tp] {
			s++
			tp++
			if tp == len(e.prev) {
				t = 0
				for s < s1 && src[s] == src[t] {
					s++
					t++
				}
				goto l
			}
		}
	l:
		if t < 0 {
			t = tp - len(e.prev)
		}
		dst.tokens[dst.n] = matchToken(uint32(s-s0-3), uint32(s-t-minOffsetSize))
		dst.n++
		lit = s
	}
	if lit != len(src) {
		emitLiteral(dst, src[lit:])
	}
	e.cur += len(src)
	if len(src) == maxStoreBlockSize {
		copy(e.block[:], src)
		e.prev = e.block[:len(src)]
	} else {
		e.prev = nil
	}
}