Skip to content

Commit

Permalink
refactor: remove utils for effective solution
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Apr 19, 2024
1 parent 822fb86 commit 01d7634
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 65 deletions.
3 changes: 2 additions & 1 deletion fileio/signature.go
Expand Up @@ -41,7 +41,8 @@ func ReadSignature(file string) ([]sync.Table, error) {
}

defer f.Close()
read := []sync.Table{}
var read []sync.Table

dataDecoder := gob.NewDecoder(f)
err = dataDecoder.Decode(&read)

Expand Down
25 changes: 9 additions & 16 deletions sync/sync.go
Expand Up @@ -10,7 +10,6 @@ import (
"io"

"github.com/geolffreym/rolling-sync/adler32"
"github.com/geolffreym/rolling-sync/utils"
)

const S = 16
Expand All @@ -20,11 +19,12 @@ type Indexes map[uint32]map[string]int

/*
Bytes store block differences
Missing = true && len(Lit) == 0 (block missing)
Missing = false && len(Lit) > 0 (block exist and some changes made to block)
Missing == false && Lit == nil (block intact just copy it)
Literal matches = any textual/literal value match found eg. "abcdef"
No literal matches = any match found by position range in block to copy eg. Block missing && Start > 0 && Offset > 0
Missing = true && len(Lit) == 0 (block missing)
Missing = false && len(Lit) > 0 (block exist and some changes made to block)
Missing == false && Lit == nil (block intact just copy it)
Literal matches = any textual/literal value match found eg. "abcdef"
No literal matches = any match found by position range in block to copy eg. Block missing && Start > 0 && Offset > 0
*/
type Bytes struct {
Offset int // End of diff position in block
Expand Down Expand Up @@ -200,22 +200,15 @@ func (s *Sync) Delta(sig []Table, reader *bufio.Reader) Delta {
delta.Add(index, newBlock) // Add new block to delta matches

// Clear garbage collectable
utils.Clear(&tmpLitMatches) // Clear tmp literal matches
utils.Clear(&weak) // Clear weak adler object
tmpLitMatches = tmpLitMatches[:0] // clear tmp literal matches
weak = adler32.New() // replace weak adler object
}

}

// Missing blocks?
// Finally check the blocks integrity
// Return cleaned/amplified copy for delta matches
delta = s.IntegrityCheck(sig, delta)

// Garbage collectable needed based on mem profiling analysis
utils.Clear(&weak)
utils.Clear(&tmpLitMatches)
return delta
return s.IntegrityCheck(sig, delta)

}

// TODO: add patch method
12 changes: 0 additions & 12 deletions utils/utils.go

This file was deleted.

36 changes: 0 additions & 36 deletions utils/utils_test.go

This file was deleted.

0 comments on commit 01d7634

Please sign in to comment.