From 7b839d28d3a0dab0d0de7b13cdfed67f8754473f Mon Sep 17 00:00:00 2001 From: Marcus Denker Date: Wed, 6 Dec 2023 13:36:24 +0100 Subject: [PATCH 1/3] unify the API of the IndexIterator, allows to push up some methods --- src/Soil-Core/SoilBTreeIterator.class.st | 18 ++-------------- src/Soil-Core/SoilIndexIterator.class.st | 19 +++++++++++++---- src/Soil-Core/SoilSkipListIterator.class.st | 23 ++++----------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/Soil-Core/SoilBTreeIterator.class.st b/src/Soil-Core/SoilBTreeIterator.class.st index 935a2264..d11812fc 100644 --- a/src/Soil-Core/SoilBTreeIterator.class.st +++ b/src/Soil-Core/SoilBTreeIterator.class.st @@ -4,12 +4,6 @@ Class { #category : #'Soil-Core-Index-BTree' } -{ #category : #accessing } -SoilBTreeIterator >> at: aKeyObject ifAbsent: aBlock [ - currentKey := (aKeyObject asSkipListKeyOfSize: index keySize) asInteger. - ^ self find: currentKey ifAbsent: aBlock -] - { #category : #accessing } SoilBTreeIterator >> basicAt: key put: anObject [ | posiblePrioValue | @@ -19,17 +13,9 @@ SoilBTreeIterator >> basicAt: key put: anObject [ ] { #category : #private } -SoilBTreeIterator >> find: key [ - currentKey := key. - currentPage := index rootPage find: key with: index. - ^ currentPage valueAt: currentKey -] - -{ #category : #private } -SoilBTreeIterator >> find: key ifAbsent: aBlock [ +SoilBTreeIterator >> findPageFor: key [ currentKey := key. - currentPage := index rootPage find: key with: index. - ^ currentPage valueAt: currentKey ifAbsent: aBlock + ^currentPage := index rootPage find: key with: index ] { #category : #accessing } diff --git a/src/Soil-Core/SoilIndexIterator.class.st b/src/Soil-Core/SoilIndexIterator.class.st index ad35d5a1..309816f3 100644 --- a/src/Soil-Core/SoilIndexIterator.class.st +++ b/src/Soil-Core/SoilIndexIterator.class.st @@ -27,9 +27,13 @@ SoilIndexIterator >> at: aKeyObject [ ^ self at: aKeyObject ifAbsent: [ KeyNotFound signalFor: aKeyObject in: self ] ] -{ #category : #accessing } -SoilIndexIterator >> at: aKeyObject ifAbsent: aBlock [ - ^ self subclassResponsibility +{ #category : #private } +SoilIndexIterator >> at: aKeyObject ifAbsent: aBlock [ + currentKey := (aKeyObject asSkipListKeyOfSize: index keySize) asInteger. + self findPageFor: currentKey. + ^ currentPage + valueAt: currentKey + ifAbsent: aBlock ] { #category : #accessing } @@ -61,7 +65,14 @@ SoilIndexIterator >> do: aBlock [ ] { #category : #private } -SoilIndexIterator >> find: key [ +SoilIndexIterator >> find: key [ + currentKey := key. + self findPageFor: key. + ^ currentPage valueAt: currentKey +] + +{ #category : #private } +SoilIndexIterator >> findPageFor: key [ ^ self subclassResponsibility ] diff --git a/src/Soil-Core/SoilSkipListIterator.class.st b/src/Soil-Core/SoilSkipListIterator.class.st index 9d277728..7de1e2bc 100644 --- a/src/Soil-Core/SoilSkipListIterator.class.st +++ b/src/Soil-Core/SoilSkipListIterator.class.st @@ -7,17 +7,6 @@ Class { #category : #'Soil-Core-Index-SkipList' } -{ #category : #private } -SoilSkipListIterator >> at: aKeyObject ifAbsent: aBlock [ - currentKey := (aKeyObject asSkipListKeyOfSize: index keySize) asInteger. - self - findPageFor: currentKey - startingAt: index headerPage. - ^ currentPage - valueAt: currentKey - ifAbsent: aBlock -] - { #category : #accessing } SoilSkipListIterator >> atLevel: key put: anObject [ levels at: key put: anObject @@ -27,7 +16,7 @@ SoilSkipListIterator >> atLevel: key put: anObject [ SoilSkipListIterator >> basicAt: key put: anObject [ |itemIndex | - self findPageFor: key startingAt: index headerPage. + self findPageFor: key. itemIndex := currentPage indexOfKey: key. "as an optimization we return the prior value stored in the list. If there was none we return nil" @@ -44,12 +33,8 @@ SoilSkipListIterator >> basicAt: key put: anObject [ ] { #category : #private } -SoilSkipListIterator >> find: key [ - currentKey := key. - self - findPageFor: key - startingAt: index headerPage. - ^ currentPage valueAt: currentKey +SoilSkipListIterator >> findPageFor: key [ + ^ self findPageFor: key startingAt: index headerPage ] { #category : #private } @@ -105,7 +90,7 @@ SoilSkipListIterator >> nextKeyCloseTo: key [ | binKey | binKey := (key asSkipListKeyOfSize: index keySize) asInteger. - self findPageFor: binKey startingAt: index headerPage. + self findPageFor: binKey. nextKey := currentPage keyOrClosestAfter: binKey. nextKey ifNil: [ "if there is no close key found, we position the cursor at the end, so that asking for the next association will return nil" From a72bbe12a1a65b4c12f6bf7fcd48c0651524a6c1 Mon Sep 17 00:00:00 2001 From: Marcus Denker Date: Wed, 6 Dec 2023 14:53:35 +0100 Subject: [PATCH 2/3] remove #findPageFor:startingAt: (not needed for SkipList, not possible fior BTree) --- src/Soil-Core/SoilSkipListIterator.class.st | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Soil-Core/SoilSkipListIterator.class.st b/src/Soil-Core/SoilSkipListIterator.class.st index 7de1e2bc..33854973 100644 --- a/src/Soil-Core/SoilSkipListIterator.class.st +++ b/src/Soil-Core/SoilSkipListIterator.class.st @@ -34,13 +34,8 @@ SoilSkipListIterator >> basicAt: key put: anObject [ { #category : #private } SoilSkipListIterator >> findPageFor: key [ - ^ self findPageFor: key startingAt: index headerPage -] - -{ #category : #private } -SoilSkipListIterator >> findPageFor: key startingAt: page [ | pageIndex candidatePage | - currentPage := page. + currentPage := index headerPage. levels size to: 1 by: -1 do: [ :level | [ pageIndex := currentPage rightAt: level. From 85cba795e0068800a051a389a15ff9505f60df61 Mon Sep 17 00:00:00 2001 From: Marcus Denker Date: Wed, 6 Dec 2023 17:47:19 +0100 Subject: [PATCH 3/3] unify at:ifAbsent: and find: --- src/Soil-Core/SoilBTreeIterator.class.st | 1 - src/Soil-Core/SoilIndexIterator.class.st | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Soil-Core/SoilBTreeIterator.class.st b/src/Soil-Core/SoilBTreeIterator.class.st index d11812fc..9cb678a0 100644 --- a/src/Soil-Core/SoilBTreeIterator.class.st +++ b/src/Soil-Core/SoilBTreeIterator.class.st @@ -14,7 +14,6 @@ SoilBTreeIterator >> basicAt: key put: anObject [ { #category : #private } SoilBTreeIterator >> findPageFor: key [ - currentKey := key. ^currentPage := index rootPage find: key with: index ] diff --git a/src/Soil-Core/SoilIndexIterator.class.st b/src/Soil-Core/SoilIndexIterator.class.st index 309816f3..5b63af29 100644 --- a/src/Soil-Core/SoilIndexIterator.class.st +++ b/src/Soil-Core/SoilIndexIterator.class.st @@ -27,13 +27,10 @@ SoilIndexIterator >> at: aKeyObject [ ^ self at: aKeyObject ifAbsent: [ KeyNotFound signalFor: aKeyObject in: self ] ] -{ #category : #private } +{ #category : #accessing } SoilIndexIterator >> at: aKeyObject ifAbsent: aBlock [ currentKey := (aKeyObject asSkipListKeyOfSize: index keySize) asInteger. - self findPageFor: currentKey. - ^ currentPage - valueAt: currentKey - ifAbsent: aBlock + ^self find: currentKey ifAbsent: aBlock ] { #category : #accessing } @@ -45,6 +42,11 @@ SoilIndexIterator >> at: aKeyObject put: anObject [ put: anObject ] +{ #category : #accessing } +SoilIndexIterator >> basicAt: key put: anObject [ + self subclassResponsibility +] + { #category : #accessing } SoilIndexIterator >> currentPage [ @@ -66,9 +68,14 @@ SoilIndexIterator >> do: aBlock [ { #category : #private } SoilIndexIterator >> find: key [ + ^ self find: key ifAbsent: [ ] +] + +{ #category : #private } +SoilIndexIterator >> find: key ifAbsent: aBlock [ currentKey := key. self findPageFor: key. - ^ currentPage valueAt: currentKey + ^ currentPage valueAt: key ifAbsent: aBlock ] { #category : #private }