diff --git a/src/Soil-Core/SoilBTreeIterator.class.st b/src/Soil-Core/SoilBTreeIterator.class.st index 935a2264..9cb678a0 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,8 @@ 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 [ - currentKey := key. - currentPage := index rootPage find: key with: index. - ^ currentPage valueAt: currentKey ifAbsent: aBlock +SoilBTreeIterator >> findPageFor: key [ + ^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..5b63af29 100644 --- a/src/Soil-Core/SoilIndexIterator.class.st +++ b/src/Soil-Core/SoilIndexIterator.class.st @@ -28,8 +28,9 @@ SoilIndexIterator >> at: aKeyObject [ ] { #category : #accessing } -SoilIndexIterator >> at: aKeyObject ifAbsent: aBlock [ - ^ self subclassResponsibility +SoilIndexIterator >> at: aKeyObject ifAbsent: aBlock [ + currentKey := (aKeyObject asSkipListKeyOfSize: index keySize) asInteger. + ^self find: currentKey ifAbsent: aBlock ] { #category : #accessing } @@ -41,6 +42,11 @@ SoilIndexIterator >> at: aKeyObject put: anObject [ put: anObject ] +{ #category : #accessing } +SoilIndexIterator >> basicAt: key put: anObject [ + self subclassResponsibility +] + { #category : #accessing } SoilIndexIterator >> currentPage [ @@ -61,7 +67,19 @@ SoilIndexIterator >> do: aBlock [ ] { #category : #private } -SoilIndexIterator >> find: key [ +SoilIndexIterator >> find: key [ + ^ self find: key ifAbsent: [ ] +] + +{ #category : #private } +SoilIndexIterator >> find: key ifAbsent: aBlock [ + currentKey := key. + self findPageFor: key. + ^ currentPage valueAt: key ifAbsent: aBlock +] + +{ #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..33854973 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,18 +33,9 @@ SoilSkipListIterator >> basicAt: key put: anObject [ ] { #category : #private } -SoilSkipListIterator >> find: key [ - currentKey := key. - self - findPageFor: key - startingAt: index headerPage. - ^ currentPage valueAt: currentKey -] - -{ #category : #private } -SoilSkipListIterator >> findPageFor: key startingAt: page [ +SoilSkipListIterator >> findPageFor: key [ | pageIndex candidatePage | - currentPage := page. + currentPage := index headerPage. levels size to: 1 by: -1 do: [ :level | [ pageIndex := currentPage rightAt: level. @@ -105,7 +85,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"