Skip to content

Commit

Permalink
Add GitDeltaCreator, GitDeltaIndex and helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusDoe committed Oct 11, 2024
1 parent f03a11b commit 919021e
Show file tree
Hide file tree
Showing 101 changed files with 713 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
instance creation
createFor: aCollection basedOn: aDeltaIndex
^ (self
withDeltaIndex: aDeltaIndex
target: aCollection)
create
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
instance creation
createFor: aCollection basedOn: aDeltaIndex maxSize: aNumber
^ (self
withDeltaIndex: aDeltaIndex
target: aCollection
maxSize: aNumber)
create
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
constants
maxOperationSize
^ GitDeltaRabinHasher window + 18
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
instance creation
withDeltaIndex: aDeltaIndex target: aCollection
^ self new
deltaIndex: aDeltaIndex;
target: aCollection;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
instance creation
withDeltaIndex: aDeltaIndex target: aCollection maxSize: aNumber
^ (self withDeltaIndex: aDeltaIndex target: aCollection)
maxSize: aNumber;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
checkMaxSize
(self hasMaxSize and: [self output size >= self maxSize])
ifTrue: [self output: nil].
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
as yet unclassified
create
self
initializeHasher;
createOutput;
writeSourceSize;
writeTargetSize;
writeInsertionsWhileInitializingHashValue;
mainLoop;
ensureInsertionCountIsWritten;
checkMaxSize.
^ self output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
as yet unclassified
createOutput
| initialSize |
initialSize := 8192.
(self hasMaxSize and: [initialSize >= self maxSize])
ifTrue: [initialSize := self maxSize + self class maxOperationSize + 1].
self output: (OrderedCollection new: initialSize).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
deltaIndex: anObject
deltaIndex := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
deltaIndex
^ deltaIndex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
ensureInsertionCountIsWritten
self hasInsertion ifTrue: [self writeInsertionCount].
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
erase
self output removeLast.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
eraseSlotForInsertionCount
self erase.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
as yet unclassified
expandMatchBackwards
self hasInsertion ifFalse: [^ self].
[self matchIndex > 1 and: [(self source at: self matchIndex - 1) = (self target at: self targetIndex - 1)]]
whileTrue: [
self matchSize: self matchSize + 1.
self matchIndex: self matchIndex - 1.
self targetIndex: self targetIndex - 1.
self erase.
self insertionCount: self insertionCount - 1.
self hasInsertion ifFalse: [
self eraseSlotForInsertionCount.
^ self]].
self writeInsertionCount.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
as yet unclassified
findMatch
self matchSize < 4096 ifFalse: [^ self].
self hasher addRollingValueAt: self targetIndex.
self deltaIndex entriesWithHashValue: self hasher hashValue do: [:entry |
| currentSource sourceRestSize currentTarget newMatchSize |
currentSource := entry index.
currentTarget := self targetIndex.
sourceRestSize := self source size + 1 - currentSource
clampHigh: self target size + 1 - currentTarget.
sourceRestSize < self matchSize ifTrue: [^ self].
[sourceRestSize > 0 and: [(self source at: currentSource) = (self target at: currentTarget)]] whileTrue: [
sourceRestSize := sourceRestSize - 1.
currentSource := currentSource + 1.
currentTarget := currentTarget + 1].
newMatchSize := currentSource - entry index.
self matchSize < newMatchSize ifTrue: [
self
matchSize: newMatchSize;
matchIndex: entry index.
self matchSize >= 4096 ifTrue: [^ self]]].
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
as yet unclassified
handleMatch
self matchSize < 4
ifTrue: [self insertOne]
ifFalse: [self
expandMatchBackwards;
writeCopy;
reinitializeHashValue].
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
hasInsertion
^ self insertionCount > 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
hasMaxSize
^ self maxSize isZero not
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
hasher: anObject
hasher := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
hasher
^ hasher
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
as yet unclassified
initialize
super initialize.
self
maxSize: 0;
targetIndex: 1;
insertionCount: 0;
matchIndex: 1;
matchSize: 0.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
initializeHasher
self hasher: (GitDeltaRabinHasher on: self target).
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing
insertOne
self hasInsertion ifFalse: [self skipSlotForInsertionCount].
self writeInsertion.
self targetIndex: self targetIndex + 1.
self insertionCount = 16r7f ifTrue: [self writeInsertionCount].
self matchSize: 0.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
insertionCount: anObject
insertionCount := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
insertionCount
^ insertionCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
isAborted
^ self output isNil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
isAtEnd
^ self targetIndex > self target size
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
as yet unclassified
mainLoop
[self isAtEnd] whileFalse: [
self
findMatch;
handleMatch;
checkMaxSize.
self isAborted ifTrue: [^ self]].
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
matchIndex: anObject
matchIndex := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
matchIndex
^ matchIndex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
matchSize: anObject
matchSize := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
matchSize
^ matchSize
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
maxSize: anObject
maxSize := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
maxSize
^ maxSize
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
output: anObject
output := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
output
^ output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
read
^ self target at: self targetIndex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
reinitializeHashValue
self matchSize < 4096 ifFalse: [^ self].
self hasher hashFirstWindowAt: self targetIndex - self hasher class window.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
skipSlotForInsertionCount
"placeholder that will be overwritten or easy to find during debugging"
self write: -1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
skipSlotForOperation
"placeholder that will be overwritten or easy to find during debugging"
self write: -1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
source
^ self deltaIndex source
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
target: anObject
target := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
target
^ target
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
targetIndex: anObject
targetIndex := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
targetIndex
^ targetIndex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
write: anInteger
self output addLast: anInteger.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
as yet unclassified
writeCopy
| left operationIndex operation offset |
left := self matchSize - 16r10000 clampLow: 0.
self matchSize: self matchSize - left.
self skipSlotForOperation.
operationIndex := self output size.
operation := 16r80.
offset := self matchIndex - 1.
(offset bitAnd: 16r000000ff) > 0 ifTrue: [operation := operation bitOr: 16r01. self write: (offset"bitShift: 0")].
(offset bitAnd: 16r0000ff00) > 0 ifTrue: [operation := operation bitOr: 16r02. self write: (offset bitShift: -8)].
(offset bitAnd: 16r00ff0000) > 0 ifTrue: [operation := operation bitOr: 16r04. self write: (offset bitShift: -16)].
(offset bitAnd: 16rff000000) > 0 ifTrue: [operation := operation bitOr: 16r08. self write: (offset bitShift: -24)].
(self matchSize bitAnd: 16r00ff) > 0 ifTrue: [operation := operation bitOr: 16r10. self write: (self matchSize"bitShift: 0")].
(self matchSize bitAnd: 16rff00) > 0 ifTrue: [operation := operation bitOr: 16r20. self write: (self matchSize bitShift: -8)].
self output at: operationIndex put: operation.

self targetIndex: self targetIndex + self matchSize.
self matchIndex: self matchIndex + self matchSize.
self matchSize: left.
self matchIndex - 1 > 16rffffffff ifTrue: [self matchSize: 0].
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
writeInsertion
self write: self read.
self insertionCount: self insertionCount + 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
writeInsertionCount
self output at: self output size - self insertionCount put: self insertionCount.
self insertionCount: 0.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
as yet unclassified
writeInsertionsWhileInitializingHashValue
self skipSlotForInsertionCount.
self hasher class window timesRepeat: [
self isAtEnd ifTrue: [^ self].
self writeInsertion.
self hasher addFirstWindowValueAt: self targetIndex.
self targetIndex: self targetIndex + 1].
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
writeSourceSize
self writeVariableSizeInteger: self source size.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
writeTargetSize
self writeVariableSizeInteger: self target size.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
as yet unclassified
writeVariableSizeInteger: anInteger
| left |
left := anInteger.
[left >= 16r80] whileTrue: [
self write: (left bitOr: 16r80).
left := left bitShift: -7].
self write: left.
Loading

0 comments on commit 919021e

Please sign in to comment.