From 1351d8330fed4d9f0f29f32741a5e3ce73e7b595 Mon Sep 17 00:00:00 2001 From: Marcus Denker Date: Thu, 8 Feb 2024 16:38:26 +0100 Subject: [PATCH] This PR finishes the hierarchy merge. -> move up ivars 'keySize lastTransaction' -> this allows us to share more code fixes #274 --- src/Soil-Core/SoilBTreeDataPage.class.st | 2 +- src/Soil-Core/SoilBTreeIndexPage.class.st | 2 +- src/Soil-Core/SoilBTreePage.class.st | 40 ++------------- src/Soil-Core/SoilIndexItemsPage.class.st | 59 ++++++++++++++++++++++- src/Soil-Core/SoilSkipListPage.class.st | 54 +-------------------- 5 files changed, 65 insertions(+), 92 deletions(-) diff --git a/src/Soil-Core/SoilBTreeDataPage.class.st b/src/Soil-Core/SoilBTreeDataPage.class.st index 21555ed6..38d8004d 100644 --- a/src/Soil-Core/SoilBTreeDataPage.class.st +++ b/src/Soil-Core/SoilBTreeDataPage.class.st @@ -33,7 +33,7 @@ SoilBTreeDataPage >> initialize [ next := 0 ] -{ #category : #accessing } +{ #category : #adding } SoilBTreeDataPage >> insertItem: anItem for: iterator [ | newPage pageWithItem return | diff --git a/src/Soil-Core/SoilBTreeIndexPage.class.st b/src/Soil-Core/SoilBTreeIndexPage.class.st index 8d5af8a0..4dd7ea02 100644 --- a/src/Soil-Core/SoilBTreeIndexPage.class.st +++ b/src/Soil-Core/SoilBTreeIndexPage.class.st @@ -32,7 +32,7 @@ SoilBTreeIndexPage >> headerSize [ + 2 "items size" ] -{ #category : #searching } +{ #category : #adding } SoilBTreeIndexPage >> insertItem: item for: iterator [ | foundItem return newPage | diff --git a/src/Soil-Core/SoilBTreePage.class.st b/src/Soil-Core/SoilBTreePage.class.st index 769b2bd1..e74734f6 100644 --- a/src/Soil-Core/SoilBTreePage.class.st +++ b/src/Soil-Core/SoilBTreePage.class.st @@ -1,10 +1,6 @@ Class { #name : #SoilBTreePage, #superclass : #SoilIndexItemsPage, - #instVars : [ - 'keySize', - 'lastTransaction' - ], #category : #'Soil-Core-Index-BTree' } @@ -40,29 +36,9 @@ SoilBTreePage >> initialize [ dirty := true ] -{ #category : #testing } -SoilBTreePage >> isOlderThan: aVersionNumber [ - ^ lastTransaction <= aVersionNumber -] - -{ #category : #accessing } -SoilBTreePage >> keySize [ - ^ keySize -] - -{ #category : #accessing } -SoilBTreePage >> keySize: anInteger [ - keySize := anInteger -] - -{ #category : #accessing } -SoilBTreePage >> lastTransaction [ - ^ lastTransaction -] - -{ #category : #accessing } -SoilBTreePage >> lastTransaction: anInteger [ - lastTransaction := anInteger +{ #category : #adding } +SoilBTreePage >> insertItem: anItem for: iterator [ + ^ self subclassResponsibility ] { #category : #accessing } @@ -86,11 +62,6 @@ SoilBTreePage >> readItemsFrom: aStream [ items add: (aStream next: self keySize) asInteger -> (aStream next: self valueSize) ] ] -{ #category : #writing } -SoilBTreePage >> readLastTransactionFrom: aStream [ - lastTransaction := (aStream next: 8) asInteger. -] - { #category : #private } SoilBTreePage >> split: newPage [ | middle | @@ -113,10 +84,7 @@ SoilBTreePage >> writeHeaderOn: aStream [ SoilBTreePage >> writeItemsOn: aStream [ aStream nextPutAll: (items size asByteArrayOfSize: self itemsSizeSize). - items do: [ :assoc | - aStream - nextPutAll: (assoc key asByteArrayOfSize: self keySize); - nextPutAll: (assoc value asByteArrayOfSize: self valueSize)] + super writeItemsOn: aStream ] { #category : #writing } diff --git a/src/Soil-Core/SoilIndexItemsPage.class.st b/src/Soil-Core/SoilIndexItemsPage.class.st index 727f22c1..b21b0ab1 100644 --- a/src/Soil-Core/SoilIndexItemsPage.class.st +++ b/src/Soil-Core/SoilIndexItemsPage.class.st @@ -2,7 +2,9 @@ Class { #name : #SoilIndexItemsPage, #superclass : #SoilIndexPage, #instVars : [ - 'items' + 'items', + 'lastTransaction', + 'keySize' ], #category : #'Soil-Core-Index-Common' } @@ -68,6 +70,11 @@ SoilIndexItemsPage >> isEmpty [ ^ items isEmpty ] +{ #category : #testing } +SoilIndexItemsPage >> isOlderThan: aVersionNumber [ + ^ lastTransaction <= aVersionNumber +] + { #category : #accessing } SoilIndexItemsPage >> itemAfter: key [ | i item | @@ -153,6 +160,17 @@ SoilIndexItemsPage >> keyOrClosestAfter: key [ (items at: (b min: items size)) key ] ] +{ #category : #accessing } +SoilIndexItemsPage >> keySize [ + ^ keySize +] + +{ #category : #accessing } +SoilIndexItemsPage >> keySize: anInteger [ + (anInteger = 0) ifTrue: [ Error signal: 'cannot use key size 0' ]. + keySize := anInteger +] + { #category : #accessing } SoilIndexItemsPage >> lastItem [ @@ -165,6 +183,16 @@ SoilIndexItemsPage >> lastKey [ ^ items isNotEmpty ifTrue: [ items last key ] ] +{ #category : #accessing } +SoilIndexItemsPage >> lastTransaction [ + ^ lastTransaction +] + +{ #category : #accessing } +SoilIndexItemsPage >> lastTransaction: anInteger [ + lastTransaction := anInteger +] + { #category : #accessing } SoilIndexItemsPage >> numberOfItems [ ^ items size @@ -176,6 +204,21 @@ SoilIndexItemsPage >> postCopy [ items := items copy. ] +{ #category : #reading } +SoilIndexItemsPage >> readItemsFrom: aStream [ + | numberOfItems | + numberOfItems := (aStream next: self itemsSizeSize) asInteger. + items := SortedCollection new: numberOfItems. + numberOfItems timesRepeat: [ + items add: ((aStream next: self keySize) asInteger -> (aStream next: self valueSize) asSoilObjectId) ] +] + +{ #category : #writing } +SoilIndexItemsPage >> readLastTransactionFrom: aStream [ + lastTransaction := (aStream next: 8) asInteger. + +] + { #category : #accessing } SoilIndexItemsPage >> setItems: aCollection [ items := aCollection @@ -204,3 +247,17 @@ SoilIndexItemsPage >> valueAt: anInteger ifAbsent: aBlock [ SoilIndexItemsPage >> valueSize [ ^ self subclassResponsibility ] + +{ #category : #accessing } +SoilIndexItemsPage >> valueSize: anInteger [ + ^ self subclassResponsibility +] + +{ #category : #writing } +SoilIndexItemsPage >> writeItemsOn: aStream [ + items do: [ :assoc | + aStream + nextPutAll: (assoc key asByteArrayOfSize: self keySize); + nextPutAll: (assoc value asByteArrayOfSize: self valueSize)]. + +] diff --git a/src/Soil-Core/SoilSkipListPage.class.st b/src/Soil-Core/SoilSkipListPage.class.st index 38d85bfc..ed589575 100644 --- a/src/Soil-Core/SoilSkipListPage.class.st +++ b/src/Soil-Core/SoilSkipListPage.class.st @@ -3,9 +3,7 @@ Class { #superclass : #SoilIndexItemsPage, #instVars : [ 'right', - 'keySize', - 'valueSize', - 'lastTransaction' + 'valueSize' ], #category : #'Soil-Core-Index-SkipList' } @@ -59,32 +57,6 @@ SoilSkipListPage >> isLastPage [ ^ (right at: 1) = 0 ] -{ #category : #testing } -SoilSkipListPage >> isOlderThan: aVersionNumber [ - ^ lastTransaction <= aVersionNumber -] - -{ #category : #accessing } -SoilSkipListPage >> keySize [ - ^ keySize -] - -{ #category : #accessing } -SoilSkipListPage >> keySize: anInteger [ - (anInteger = 0) ifTrue: [ Error signal: 'cannot use key size 0' ]. - keySize := anInteger. -] - -{ #category : #accessing } -SoilSkipListPage >> lastTransaction [ - ^ lastTransaction -] - -{ #category : #accessing } -SoilSkipListPage >> lastTransaction: anInteger [ - lastTransaction := anInteger -] - { #category : #accessing } SoilSkipListPage >> level [ ^ right size @@ -107,21 +79,6 @@ SoilSkipListPage >> readFrom: aStream [ self readLastTransactionFrom: aStream ] -{ #category : #writing } -SoilSkipListPage >> readItemsFrom: aStream [ - | numberOfItems | - numberOfItems := (aStream next: self itemsSizeSize) asInteger. - items := SortedCollection new: numberOfItems. - numberOfItems timesRepeat: [ - items add: ((aStream next: self keySize) asInteger -> (aStream next: self valueSize) asSoilObjectId) ] -] - -{ #category : #writing } -SoilSkipListPage >> readLastTransactionFrom: aStream [ - lastTransaction := (aStream next: 8) asInteger. - -] - { #category : #writing } SoilSkipListPage >> readLevelsFrom: aStream [ | level | @@ -188,15 +145,6 @@ SoilSkipListPage >> writeHeaderOn: aStream [ ] -{ #category : #writing } -SoilSkipListPage >> writeItemsOn: aStream [ - items do: [ :assoc | - aStream - nextPutAll: (assoc key asByteArrayOfSize: self keySize); - nextPutAll: (assoc value asByteArrayOfSize: self valueSize)]. - -] - { #category : #writing } SoilSkipListPage >> writeLevelsOn: aStream [ aStream