diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-09 12:09:18 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-09 12:10:45 +0200 |
commit | 8a03c46bf24b5a1fa1d2080ac4f763532db01bbe (patch) | |
tree | 069554f3e1e3e235a22d13dbb4a4a555b2d6e0d6 /repo.go | |
parent | f061a7031181ef53d034c46b696156c143451cce (diff) | |
download | dna-backup-8a03c46bf24b5a1fa1d2080ac4f763532db01bbe.tar.gz dna-backup-8a03c46bf24b5a1fa1d2080ac4f763532db01bbe.zip |
export sketch in its own package
so that tests can be cached and to make sure it is independant of
the rest of the code
also move tests in testdata as this folder is ignored by go test by default
Diffstat (limited to 'repo.go')
-rw-r--r-- | repo.go | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -41,6 +41,7 @@ import ( "github.com/chmduquesne/rollinghash/rabinkarp64" "github.com/n-peugnet/dna-backup/cache" + "github.com/n-peugnet/dna-backup/sketch" ) type FingerprintMap map[uint64]*ChunkId @@ -167,7 +168,7 @@ func concatFiles(files []File, stream io.WriteCloser) { } func (r *Repo) chunkMinLen() int { - return SuperFeatureSize(r.chunkSize, r.sketchSfCount, r.sketchFCount) + return sketch.SuperFeatureSize(r.chunkSize, r.sketchSfCount, r.sketchFCount) } func (r *Repo) chunkStream(stream io.Reader, chunks chan<- []byte) { @@ -319,7 +320,7 @@ func (r *Repo) hashAndStoreChunk(chunk IdentifiedChunk, hasher hash.Hash64) { hasher.Reset() io.Copy(hasher, chunk.Reader()) fingerprint := hasher.Sum64() - sketch, _ := SketchChunk(chunk, r.pol, r.chunkSize, r.sketchWSize, r.sketchSfCount, r.sketchFCount) + sketch, _ := sketch.SketchChunk(chunk.Reader(), r.pol, r.chunkSize, r.sketchWSize, r.sketchSfCount, r.sketchFCount) r.storeChunkId(chunk.GetId(), fingerprint, sketch) } @@ -347,7 +348,7 @@ func (r *Repo) findSimilarChunk(chunk Chunk) (*ChunkId, bool) { var similarChunks = make(map[ChunkId]int) var max int var similarChunk *ChunkId - sketch, _ := SketchChunk(chunk, r.pol, r.chunkSize, r.sketchWSize, r.sketchSfCount, r.sketchFCount) + sketch, _ := sketch.SketchChunk(chunk.Reader(), r.pol, r.chunkSize, r.sketchWSize, r.sketchSfCount, r.sketchFCount) for _, s := range sketch { chunkIds, exists := r.sketches[s] if !exists { @@ -557,7 +558,7 @@ func (r *Repo) mergeTempChunks(chunks []Chunk) (ret []Chunk) { for _, c := range chunks { tmp, isTmp := c.(*TempChunk) if !isTmp { - if prev != nil && curr.Len() <= SuperFeatureSize(r.chunkSize, r.sketchSfCount, r.sketchFCount) { + if prev != nil && curr.Len() <= sketch.SuperFeatureSize(r.chunkSize, r.sketchSfCount, r.sketchFCount) { prev.AppendFrom(curr.Reader()) } else if curr != nil { ret = append(ret, curr) |