Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify the API of the IndexIterators #534

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/Soil-Core/SoilBTreeIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 }
Expand Down
24 changes: 21 additions & 3 deletions src/Soil-Core/SoilIndexIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -41,6 +42,11 @@ SoilIndexIterator >> at: aKeyObject put: anObject [
put: anObject
]

{ #category : #accessing }
SoilIndexIterator >> basicAt: key put: anObject [
self subclassResponsibility
]

{ #category : #accessing }
SoilIndexIterator >> currentPage [

Expand All @@ -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
]

Expand Down
28 changes: 4 additions & 24 deletions src/Soil-Core/SoilSkipListIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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"
Expand Down
Loading