Skip to content

Commit

Permalink
Merge pull request #623 from ApptiveGrid/add-pointer-for-last-free-page
Browse files Browse the repository at this point in the history
added pointer for last free page index
  • Loading branch information
noha authored Feb 16, 2024
2 parents 623f4fe + 37d88e1 commit bc9a348
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/Soil-Core/SoilBasicBTree.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ SoilBasicBTree >> flush [
self store flush
]

{ #category : #testing }
SoilBasicBTree >> hasHeaderPage [
^ store hasHeaderPage
]

{ #category : #initialization }
SoilBasicBTree >> initializeFilesystem [
self store initializeFilesystem
Expand Down
5 changes: 5 additions & 0 deletions src/Soil-Core/SoilBasicSkipList.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ SoilBasicSkipList class >> isAbstract [
^ self == SoilBasicSkipList
]

{ #category : #testing }
SoilBasicSkipList >> hasHeaderPage [
^ store hasHeaderPage
]

{ #category : #accessing }
SoilBasicSkipList >> maxLevel [

Expand Down
5 changes: 5 additions & 0 deletions src/Soil-Core/SoilPagedIndexStore.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ SoilPagedIndexStore >> flushCachedPages [
pages removeAll
]

{ #category : #testing }
SoilPagedIndexStore >> hasHeaderPage [
^ pages includesKey: 1
]

{ #category : #accessing }
SoilPagedIndexStore >> headerPage [
^ self pageAt: 1
Expand Down
14 changes: 8 additions & 6 deletions src/Soil-Core/SoilReindexer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ SoilReindexer >> prepareNewIndex [
| indexCopy |
indexCopy := index class new
path: reIndexPath;
initializeFilesystem;
initializeHeaderPage;
maxLevel: index maxLevel;
keySize: index keySize;
valueSize: index valueSize.
newIndex := indexBlock value: indexCopy
initializeFilesystem.
newIndex := indexBlock value: indexCopy.
newIndex hasHeaderPage ifFalse: [
newIndex
initializeHeaderPage;
maxLevel: index maxLevel;
keySize: index keySize;
valueSize: index valueSize ]
]

{ #category : #running }
Expand Down
1 change: 1 addition & 0 deletions src/Soil-Core/SoilSkipList.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ SoilSkipList >> newHeaderPage [
^ SoilSkipListHeaderPage new
index: 1;
lastPageIndex: 1;
lastFreePageIndex: 0;
pageSize: self pageSize
]

Expand Down
30 changes: 26 additions & 4 deletions src/Soil-Core/SoilSkipListHeaderPage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Class {
#superclass : #SoilSkipListPage,
#instVars : [
'maxLevel',
'lastPageIndex'
'lastPageIndex',
'lastFreePageIndex'
],
#category : #'Soil-Core-Index-SkipList'
}
Expand All @@ -29,12 +30,19 @@ SoilSkipListHeaderPage class >> pageCode [
{ #category : #utilities }
SoilSkipListHeaderPage >> headerSize [
^ super headerSize
+ 10 "keySize, valueSize, maxLevel, lastPageIndex"
+ 14 "keySize(2), valueSize(2), maxLevel(2), lastPageIndex(4), lastFreePageIndex(4)"
+ 1 "level"
+ (self level * self rightSize)
+ 2 "items size"
]

{ #category : #initialization }
SoilSkipListHeaderPage >> initialize [
super initialize.
lastPageIndex := 1.
lastFreePageIndex := 0
]

{ #category : #accessing }
SoilSkipListHeaderPage >> keySize: anInteger [
"as long as no items have been added the key size can be changed"
Expand All @@ -46,6 +54,18 @@ SoilSkipListHeaderPage >> keySize: anInteger [

]

{ #category : #accessing }
SoilSkipListHeaderPage >> lastFreePageIndex [

^ lastFreePageIndex
]

{ #category : #accessing }
SoilSkipListHeaderPage >> lastFreePageIndex: anObject [

lastFreePageIndex := anObject
]

{ #category : #accessing }
SoilSkipListHeaderPage >> lastPageIndex [

Expand Down Expand Up @@ -93,7 +113,8 @@ SoilSkipListHeaderPage >> readHeaderFrom: aStream [
keySize := (aStream next: 2) asInteger.
valueSize := (aStream next: 2) asInteger.
maxLevel := (aStream next: 2) asInteger.
lastPageIndex :=(aStream next: 4) asInteger
lastPageIndex :=(aStream next: 4) asInteger.
lastFreePageIndex :=(aStream next: 4) asInteger
]

{ #category : #accessing }
Expand All @@ -108,7 +129,8 @@ SoilSkipListHeaderPage >> writeHeaderOn: aStream [
nextPutAll: (keySize asByteArrayOfSize: 2);
nextPutAll: (valueSize asByteArrayOfSize: 2);
nextPutAll: (maxLevel asByteArrayOfSize: 2);
nextPutAll: (lastPageIndex asByteArrayOfSize: 4).
nextPutAll: (lastPageIndex asByteArrayOfSize: 4);
nextPutAll: (lastFreePageIndex asByteArrayOfSize: 4).
self
writeLevelsOn: aStream.
aStream nextPutAll: (items size asByteArrayOfSize: self itemsSizeSize).
Expand Down

0 comments on commit bc9a348

Please sign in to comment.