diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-08-31 16:28:07 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-08-31 16:38:34 +0200 |
commit | 504fe3db47c058807b656a8e63bb27c12420f268 (patch) | |
tree | 5fec35a147b3234633d237601cc49627fbedf331 /repo.go | |
parent | c481eb2b44adf50b62de3b9e3355f64973967d52 (diff) | |
download | dna-backup-504fe3db47c058807b656a8e63bb27c12420f268.tar.gz dna-backup-504fe3db47c058807b656a8e63bb27c12420f268.zip |
join too small temp chunks with previous one if possible
Diffstat (limited to 'repo.go')
-rw-r--r-- | repo.go | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -71,7 +71,7 @@ func (r *Repo) Commit(source string) { go concatFiles(files, writer) fingerprints, _ := hashChunks(oldChunks) chunks := r.matchStream(reader, fingerprints) - extractNewChunks(chunks) + extractTempChunks(chunks) // storeChunks(newChunkPath, newChunks) // storeFiles(newFilesPath, files) fmt.Println(files) @@ -327,24 +327,32 @@ func (r *Repo) matchStream(stream io.Reader, fingerprints FingerprintMap) []Chun return chunks } -// extractNewChunks extracts new chunks from an array of chunks and -// returns them in an array of consecutive new chunk's array -func extractNewChunks(chunks []Chunk) (ret [][]Chunk) { - var i int - ret = append(ret, nil) +// extractTempChunks extracts temporary chunks from an array of chunks. +// If a chunk is smaller than the size required to calculate a super-feature, +// it is then appended to the previous consecutive temporary chunk if it exists. +func extractTempChunks(chunks []Chunk) (ret []Chunk) { + var prev *TempChunk + var curr *TempChunk for _, c := range chunks { - _, isTmp := c.(*TempChunk) + tmp, isTmp := c.(*TempChunk) if !isTmp { - if len(ret[i]) != 0 { - i++ - ret = append(ret, nil) + if prev != nil && curr.Len() <= SuperFeatureSize(chunkSize, sketchSfCount, sketchFCount) { + prev.AppendFrom(curr.Reader()) + } else if curr != nil { + ret = append(ret, curr) } + curr = nil + prev = nil } else { - ret[i] = append(ret[i], c) + prev = curr + curr = tmp + if prev != nil { + ret = append(ret, prev) + } } } - if len(ret[i]) == 0 { - ret = ret[:i] + if curr != nil { + ret = append(ret, curr) } return } |