Skip to content

Commit

Permalink
Make diff internals private
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Jul 4, 2023
1 parent 50310cd commit 3bae4d9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tools/rsync/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (self *list) pop_front() *Operation {
return nil
}

type Diff struct {
type diff struct {
buffer []byte
// A single β hash may correlate with many unique hashes.
hash_lookup map[uint32][]BlockHash
Expand All @@ -348,7 +348,7 @@ type Diff struct {
ready_ops list
}

func (self *Diff) Next() (op *Operation, err error) {
func (self *diff) Next() (op *Operation, err error) {
if self.ready_ops.is_empty() {
if err = self.pump_till_op_available(); err != nil {
return
Expand All @@ -357,15 +357,15 @@ func (self *Diff) Next() (op *Operation, err error) {
return self.ready_ops.pop_front(), nil
}

func (self *Diff) hash(b []byte) []byte {
func (self *diff) hash(b []byte) []byte {
self.hasher.Reset()
self.hasher.Write(b)
return self.hasher.Sum(self.hash_buf[:0])
}

// Combine OpBlock into OpBlockRange. To do this store the previous
// non-data operation and determine if it can be extended.
func (self *Diff) enqueue(op Operation) {
func (self *diff) enqueue(op Operation) {
switch op.Type {
case OpBlock:
if self.pending_op != nil {
Expand Down Expand Up @@ -401,7 +401,7 @@ func (self *Diff) enqueue(op Operation) {

}

func (self *Diff) send_data() {
func (self *diff) send_data() {
data := self.buffer[self.data.tail:self.data.head]
srepr := make([]byte, len(data)+5)
copy(srepr[5:], data)
Expand All @@ -412,7 +412,7 @@ func (self *Diff) send_data() {
self.data.tail = self.data.head
}

func (self *Diff) pump_till_op_available() error {
func (self *diff) pump_till_op_available() error {
for self.ready_ops.is_empty() && !self.finished {
if err := self.read_at_least_one_operation(); err != nil {
return err
Expand All @@ -426,7 +426,7 @@ func (self *Diff) pump_till_op_available() error {
}

// See https://rsync.samba.org/tech_report/node4.html for the design of this algorithm
func (self *Diff) read_at_least_one_operation() error {
func (self *diff) read_at_least_one_operation() error {
last_run := false
required_pos_for_sum := self.sum.tail + self.block_size
if required_pos_for_sum > self.valid_to { // need more data in buffer
Expand Down Expand Up @@ -518,8 +518,8 @@ func (self *Diff) read_at_least_one_operation() error {
return nil
}

func (r *RSync) CreateDiff(source io.Reader, signature []BlockHash) (ans *Diff) {
ans = &Diff{
func (r *RSync) CreateDiff(source io.Reader, signature []BlockHash) func() (*Operation, error) {
ans := &diff{
block_size: r.BlockSize, buffer: make([]byte, (r.BlockSize*2)+(r.MaxDataOp)),
hash_lookup: make(map[uint32][]BlockHash, len(signature)),
source: source, max_data_op: r.MaxDataOp, hasher: r.UniqueHasher,
Expand All @@ -530,14 +530,14 @@ func (r *RSync) CreateDiff(source io.Reader, signature []BlockHash) (ans *Diff)
ans.hash_lookup[key] = append(ans.hash_lookup[key], h)
}

return
return ans.Next
}

func (r *RSync) CreateDelta(source io.Reader, signature []BlockHash, ops OperationWriter) (err error) {
diff := r.CreateDiff(source, signature)
var op *Operation
for {
op, err = diff.Next()
op, err = diff()
if op == nil {
return
}
Expand Down

0 comments on commit 3bae4d9

Please sign in to comment.