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

Some more Btree cleanups #576

Merged
merged 1 commit into from
Jan 17, 2024
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
6 changes: 6 additions & 0 deletions src/Soil-Core/SoilBTree.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Class {
#category : #'Soil-Core-Index-BTree'
}

{ #category : #'open/close' }
SoilBTree >> close [
super close.
keySize := nil
]

{ #category : #deleting }
SoilBTree >> destroy [
path ensureDelete
Expand Down
8 changes: 0 additions & 8 deletions src/Soil-Core/SoilBTreeDataPage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ SoilBTreeDataPage >> isLastPage [
^ next == 0
]

{ #category : #accessing }
SoilBTreeDataPage >> itemBefore: key [

| item |
item := items at: key ifAbsent: [ ^ nil ].
^ items before: item ifAbsent: nil
]

{ #category : #accessing }
SoilBTreeDataPage >> next [
^next
Expand Down
5 changes: 0 additions & 5 deletions src/Soil-Core/SoilBTreeIndexPage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ SoilBTreeIndexPage >> findKey: aKey [
^nil
]

{ #category : #testing }
SoilBTreeIndexPage >> hasRoom [
^ self headerSize + ((items size + 1) * (self keySize + self pointerSize)) <= self pageSize
]

{ #category : #utilities }
SoilBTreeIndexPage >> headerSize [
^ super headerSize
Expand Down
12 changes: 7 additions & 5 deletions src/Soil-Core/SoilBTreePage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ SoilBTreePage class >> indexClass [
^ SoilBTree
]

{ #category : #testing }
SoilBTreePage class >> isAbstract [
<ignoreForCoverage>
^ self == SoilBTreePage
]

{ #category : #adding }
SoilBTreePage >> addItem: anAssociation [
"Updates entry if already there (different to SoilSkipListPage>>#addItem:)"
(items anySatisfy: [ :item | item key = anAssociation key ])
ifFalse: [ items add: anAssociation ]
ifTrue: [ self itemAt: anAssociation key put: anAssociation value ].
Expand All @@ -26,11 +33,6 @@ SoilBTreePage >> find: aKey with: aBTree [
^ self subclassResponsibility
]

{ #category : #testing }
SoilBTreePage >> hasRoom [
^ self headerSize + ((items size + 1) * (self keySize + self valueSize)) <= self pageSize
]

{ #category : #initialization }
SoilBTreePage >> initialize [
super initialize.
Expand Down
21 changes: 21 additions & 0 deletions src/Soil-Core/SoilIndexItemsPage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ SoilIndexItemsPage class >> isAbstract [
^ self == SoilIndexItemsPage
]

{ #category : #adding }
SoilIndexItemsPage >> addItem: anAssociation [
^ self subclassResponsibility
]

{ #category : #accessing }
SoilIndexItemsPage >> associationAt: anInteger [
^ self
Expand All @@ -33,6 +38,14 @@ SoilIndexItemsPage >> firstItem [
^ items isNotEmpty ifTrue: [ items first ]
]

{ #category : #testing }
SoilIndexItemsPage >> hasRoom [
| used itemSize |
itemSize := self keySize + self valueSize.
used := self headerSize + (items size * itemSize).
^ used <= (self pageSize - itemSize)
]

{ #category : #utilities }
SoilIndexItemsPage >> headerSize [
^ super headerSize + 8 "last transaction number"
Expand Down Expand Up @@ -81,6 +94,14 @@ SoilIndexItemsPage >> itemAt: key put: anObject [
^ removedItem
]

{ #category : #accessing }
SoilIndexItemsPage >> itemBefore: key [

| item |
item := items findBinary: [ :each | key - each key] do: [ :e | e ] ifNone: [ ^ nil ] .
^ items before: item ifAbsent: nil
]

{ #category : #accessing }
SoilIndexItemsPage >> itemCapacity [
^ ((self pageSize - self headerSize) / (self keySize + self valueSize)) floor
Expand Down
19 changes: 2 additions & 17 deletions src/Soil-Core/SoilSkipListPage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ SoilSkipListPage class >> isAbstract [
]

{ #category : #adding }
SoilSkipListPage >> addItem: anAssociation [
SoilSkipListPage >> addItem: anAssociation [
"Note: this can only be called for new items, client has to check first and update if an entry for the key is already there, different to SoilBTreePage>>#addItem:"
items add: anAssociation.
dirty := true
]
Expand All @@ -34,14 +35,6 @@ SoilSkipListPage >> biggestKey [
ifFalse: [ self lastKey ]
]

{ #category : #testing }
SoilSkipListPage >> hasRoom [
| used itemSize |
itemSize := keySize + valueSize.
used := self headerSize + (items size * itemSize).
^ used <= (self pageSize - itemSize)
]

{ #category : #initialization }
SoilSkipListPage >> initialize [
super initialize.
Expand Down Expand Up @@ -71,14 +64,6 @@ SoilSkipListPage >> isOlderThan: aVersionNumber [
^ lastTransaction <= aVersionNumber
]

{ #category : #accessing }
SoilSkipListPage >> itemBefore: key [

| item |
item := items findBinary: [ :each | key - each key] do: [ :e | e ] ifNone: [ ^ nil ] .
^ items before: item ifAbsent: nil
]

{ #category : #accessing }
SoilSkipListPage >> keyOrClosestAfter: key [
"find the closest key in this page. This returns the exact key if
Expand Down
Loading