diff --git a/src/Soil-Core/SoilBasicBTree.class.st b/src/Soil-Core/SoilBasicBTree.class.st index 08593d0f..337b3235 100644 --- a/src/Soil-Core/SoilBasicBTree.class.st +++ b/src/Soil-Core/SoilBasicBTree.class.st @@ -1,9 +1,6 @@ Class { #name : #SoilBasicBTree, - #superclass : #Object, - #instVars : [ - 'store' - ], + #superclass : #SoilIndex, #category : #'Soil-Core-Index-BTree' } @@ -20,55 +17,6 @@ SoilBasicBTree >> asCopyOnWrite [ yourself ] -{ #category : #accessing } -SoilBasicBTree >> at: key [ - ^ self - at: key - ifAbsent: [ KeyNotFound signalFor: key in: self ] -] - -{ #category : #accessing } -SoilBasicBTree >> at: anObject ifAbsent: aBlock [ - ^ (self find: anObject) - ifNotNil: [:node | node value ] - ifNil: [ aBlock value ] -] - -{ #category : #accessing } -SoilBasicBTree >> at: aKeyObject put: anObject [ - - self newIterator - at: aKeyObject - put: anObject. - -] - -{ #category : #accessing } -SoilBasicBTree >> atIndex: anInteger [ - ^ self newIterator atIndex: anInteger -] - -{ #category : #'open/close' } -SoilBasicBTree >> close [ - self store close -] - -{ #category : #private } -SoilBasicBTree >> find: aString [ - ^ self newIterator - find: (aString asSkipListKeyOfSize: self keySize) asInteger -] - -{ #category : #accessing } -SoilBasicBTree >> first [ - ^ self newIterator first -] - -{ #category : #accessing } -SoilBasicBTree >> first: anInteger [ - ^ self newIterator first: anInteger -] - { #category : #accessing } SoilBasicBTree >> firstPage [ ^ self headerPage @@ -79,16 +27,6 @@ SoilBasicBTree >> flush [ self store flush ] -{ #category : #accessing } -SoilBasicBTree >> flushCachedPages [ - store flushCachedPages -] - -{ #category : #accessing } -SoilBasicBTree >> headerPage [ - ^ self store headerPage -] - { #category : #initialization } SoilBasicBTree >> initializeFilesystem [ self store initializeFilesystem @@ -104,21 +42,6 @@ SoilBasicBTree >> initializeHeaderPage [ self store pageAt: rootIndexPage index put: rootIndexPage ] -{ #category : #testing } -SoilBasicBTree >> isEmpty [ - ^ self store headerPage isEmpty -] - -{ #category : #testing } -SoilBasicBTree >> isRegistered [ - ^ self subclassResponsibility -] - -{ #category : #accessing } -SoilBasicBTree >> keySize [ - ^ self headerPage keySize -] - { #category : #accessing } SoilBasicBTree >> keySize: anInteger [ self headerPage keySize: anInteger. @@ -126,16 +49,6 @@ SoilBasicBTree >> keySize: anInteger [ self rootPage keySize: anInteger ] -{ #category : #accessing } -SoilBasicBTree >> last [ - ^ self newIterator last -] - -{ #category : #accessing } -SoilBasicBTree >> lastPage [ - ^ self newIterator lastPage -] - { #category : #accessing } SoilBasicBTree >> maxLevel: anIntegeer [ "ignored, this allows to switch SkiList and BTree easily" @@ -202,21 +115,11 @@ SoilBasicBTree >> open [ self store open ] -{ #category : #accessing } -SoilBasicBTree >> pageAt: anInteger [ - ^ self store pageAt: anInteger -] - { #category : #initialization } SoilBasicBTree >> pageClass [ ^ SoilBTreeDataPage ] -{ #category : #accessing } -SoilBasicBTree >> pageSize [ - ^ 4 * 1024 -] - { #category : #accessing } SoilBasicBTree >> pages [ ^ self store pages @@ -227,13 +130,6 @@ SoilBasicBTree >> readPageFrom: aStream [ ^ SoilBTreePage readPageFrom: aStream keySize: self keySize valueSize: self valueSize ] -{ #category : #removing } -SoilBasicBTree >> removeKey: key [ - ^ self - removeKey: key - ifAbsent: [ KeyNotFound signalFor: key in: self ] -] - { #category : #removing } SoilBasicBTree >> removeKey: aString ifAbsent: aBlock [ | page index key | @@ -251,12 +147,6 @@ SoilBasicBTree >> rootPage [ ^ self store pageAt: 2 ] -{ #category : #accessing } -SoilBasicBTree >> size [ - "We iterate over all elements to get the size. Slow!" - ^ self newIterator size -] - { #category : #splitting } SoilBasicBTree >> splitIndexPage: page [ | newPage | @@ -276,33 +166,6 @@ SoilBasicBTree >> splitPage: page [ ^ newPage ] -{ #category : #accessing } -SoilBasicBTree >> store [ - ^ store ifNil: [ - store := self newFileStore ] -] - -{ #category : #accessing } -SoilBasicBTree >> store: anObject [ - anObject index: self. - store := anObject -] - -{ #category : #converting } -SoilBasicBTree >> thePersistentInstance [ - ^ self subclassResponsibility -] - -{ #category : #accessing } -SoilBasicBTree >> valueSize [ - ^ self headerPage valueSize -] - -{ #category : #accessing } -SoilBasicBTree >> valueSize: anInteger [ - self headerPage valueSize: anInteger -] - { #category : #writing } SoilBasicBTree >> writePages [ self store flushPages diff --git a/src/Soil-Core/SoilBasicSkipList.class.st b/src/Soil-Core/SoilBasicSkipList.class.st index 0961f192..64239e03 100644 --- a/src/Soil-Core/SoilBasicSkipList.class.st +++ b/src/Soil-Core/SoilBasicSkipList.class.st @@ -1,9 +1,6 @@ Class { #name : #SoilBasicSkipList, - #superclass : #Object, - #instVars : [ - 'store' - ], + #superclass : #SoilIndex, #category : #'Soil-Core-Index-SkipList' } @@ -13,107 +10,17 @@ SoilBasicSkipList class >> isAbstract [ ^ self == SoilBasicSkipList ] -{ #category : #private } -SoilBasicSkipList >> at: key [ - ^ self - at: key - ifAbsent: [ KeyNotFound signalFor: key in: self ] -] - -{ #category : #private } -SoilBasicSkipList >> at: anObject ifAbsent: aBlock [ - ^ (self find: anObject) - ifNotNil: [:node | node value ] - ifNil: [ aBlock value ] -] - -{ #category : #accessing } -SoilBasicSkipList >> at: aKeyObject put: anObject [ - self newIterator - at: aKeyObject - put: anObject. - -] - -{ #category : #accessing } -SoilBasicSkipList >> atIndex: anInteger [ - ^ self newIterator atIndex: anInteger -] - -{ #category : #accessing } -SoilBasicSkipList >> basicAt: key put: anObject [ - ^ self newIterator - basicAt: key - put: anObject -] - -{ #category : #enumerating } -SoilBasicSkipList >> do: aBlock [ - self newIterator do: aBlock -] - -{ #category : #private } -SoilBasicSkipList >> find: aString [ - ^ self newIterator - find: (aString asSkipListKeyOfSize: self keySize) asInteger -] - -{ #category : #accessing } -SoilBasicSkipList >> first [ - ^ self newIterator first -] - -{ #category : #accessing } -SoilBasicSkipList >> first: anInteger [ - ^ self newIterator first: anInteger -] - { #category : #accessing } SoilBasicSkipList >> firstPage [ ^ self store pageAt: 1 ] -{ #category : #accessing } -SoilBasicSkipList >> flushCachedPages [ - store flushCachedPages -] - -{ #category : #accessing } -SoilBasicSkipList >> headerPage [ - ^ self store headerPage -] - -{ #category : #testing } -SoilBasicSkipList >> isEmpty [ - ^ self store headerPage isEmpty -] - -{ #category : #testing } -SoilBasicSkipList >> isRegistered [ - ^ self subclassResponsibility -] - -{ #category : #accessing } -SoilBasicSkipList >> keySize [ - ^ self headerPage keySize -] - { #category : #accessing } SoilBasicSkipList >> keySize: anInteger [ anInteger isZero ifTrue: [ Error signal: 'keySize cannot be zero yet' ]. self headerPage keySize: anInteger ] -{ #category : #accessing } -SoilBasicSkipList >> last [ - ^ self newIterator last -] - -{ #category : #accessing } -SoilBasicSkipList >> lastPage [ - ^ self newIterator lastPage -] - { #category : #accessing } SoilBasicSkipList >> maxLevel [ @@ -126,38 +33,16 @@ SoilBasicSkipList >> maxLevel: anInteger [ self headerPage maxLevel: anInteger ] -{ #category : #'public/accessing' } +{ #category : #'instance creation' } SoilBasicSkipList >> newIterator [ ^ SoilSkipListIterator on: self ] -{ #category : #'instance creation' } -SoilBasicSkipList >> newPage [ - ^ self subclassResponsibility -] - -{ #category : #accessing } -SoilBasicSkipList >> pageAt: anInteger [ - ^ self store pageAt: anInteger -] - -{ #category : #accessing } -SoilBasicSkipList >> pageSize [ - ^ 4 * 1024 -] - { #category : #accessing } SoilBasicSkipList >> pages [ ^ self store pages ] -{ #category : #removing } -SoilBasicSkipList >> removeKey: key [ - ^ self - removeKey: key - ifAbsent: [ KeyNotFound signalFor: key in: self ] -] - { #category : #removing } SoilBasicSkipList >> removeKey: aString ifAbsent: aBlock [ | page index key | @@ -170,12 +55,6 @@ SoilBasicSkipList >> removeKey: aString ifAbsent: aBlock [ ifFalse: [ aBlock value ] ] -{ #category : #accessing } -SoilBasicSkipList >> size [ - "We iterate over all elements to get the size. Slow!" - ^ self newIterator size -] - { #category : #private } SoilBasicSkipList >> splitPage: aIterator forKey: aKey [ | newPage page | @@ -201,35 +80,6 @@ SoilBasicSkipList >> splitPage: aIterator forKey: aKey [ ^ newPage ] -{ #category : #accessing } -SoilBasicSkipList >> store [ - ^ store ifNil: [ - store := self newFileStore ] -] - -{ #category : #accessing } -SoilBasicSkipList >> store: anObject [ - anObject index: self. - store := anObject -] - -{ #category : #converting } -SoilBasicSkipList >> thePersistentInstance [ - ^ self subclassResponsibility -] - -{ #category : #accessing } -SoilBasicSkipList >> valueSize [ - "^ 8" - ^ self headerPage valueSize -] - -{ #category : #accessing } -SoilBasicSkipList >> valueSize: anInteger [ - "valueSize := anInteger" - self headerPage valueSize: anInteger -] - { #category : #enumerating } SoilBasicSkipList >> values [ | values | diff --git a/src/Soil-Core/SoilIndex.class.st b/src/Soil-Core/SoilIndex.class.st new file mode 100644 index 00000000..f203f6aa --- /dev/null +++ b/src/Soil-Core/SoilIndex.class.st @@ -0,0 +1,172 @@ +Class { + #name : #SoilIndex, + #superclass : #Object, + #instVars : [ + 'store' + ], + #category : #'Soil-Core-Index-Common' +} + +{ #category : #private } +SoilIndex >> at: key [ + ^ self + at: key + ifAbsent: [ KeyNotFound signalFor: key in: self ] +] + +{ #category : #accessing } +SoilIndex >> at: anObject ifAbsent: aBlock [ + ^ (self find: anObject) + ifNotNil: [:node | node value ] + ifNil: [ aBlock value ] +] + +{ #category : #accessing } +SoilIndex >> at: aKeyObject put: anObject [ + self newIterator + at: aKeyObject + put: anObject +] + +{ #category : #accessing } +SoilIndex >> atIndex: anInteger [ + ^ self newIterator atIndex: anInteger +] + +{ #category : #accessing } +SoilIndex >> basicAt: key put: anObject [ + ^ self newIterator + basicAt: key + put: anObject +] + +{ #category : #'open/close' } +SoilIndex >> close [ + self store close +] + +{ #category : #enumerating } +SoilIndex >> do: aBlock [ + self newIterator do: aBlock +] + +{ #category : #private } +SoilIndex >> find: aString [ + ^ self newIterator + find: (aString asSkipListKeyOfSize: self keySize) asInteger +] + +{ #category : #accessing } +SoilIndex >> first [ + ^ self newIterator first +] + +{ #category : #accessing } +SoilIndex >> first: anInteger [ + ^ self newIterator first: anInteger +] + +{ #category : #accessing } +SoilIndex >> flushCachedPages [ + store flushCachedPages +] + +{ #category : #accessing } +SoilIndex >> headerPage [ + ^ self store headerPage +] + +{ #category : #testing } +SoilIndex >> isEmpty [ + ^ self store headerPage isEmpty +] + +{ #category : #testing } +SoilIndex >> isRegistered [ + ^ self subclassResponsibility +] + +{ #category : #accessing } +SoilIndex >> keySize [ + ^ self headerPage keySize +] + +{ #category : #accessing } +SoilIndex >> last [ + ^ self newIterator last +] + +{ #category : #accessing } +SoilIndex >> lastPage [ + ^ self newIterator lastPage +] + +{ #category : #'instance creation' } +SoilIndex >> newFileStore [ + ^ self subclassResponsibility +] + +{ #category : #'instance creation' } +SoilIndex >> newIterator [ + ^ self subclassResponsibility +] + +{ #category : #'instance creation' } +SoilIndex >> newPage [ + ^ self subclassResponsibility +] + +{ #category : #accessing } +SoilIndex >> pageAt: anInteger [ + ^ self store pageAt: anInteger +] + +{ #category : #accessing } +SoilIndex >> pageSize [ + ^ 4 * 1024 +] + +{ #category : #removing } +SoilIndex >> removeKey: key [ + ^ self + removeKey: key + ifAbsent: [ KeyNotFound signalFor: key in: self ] +] + +{ #category : #'instance creation' } +SoilIndex >> removeKey: aString ifAbsent: aBlock [ + ^ self subclassResponsibility +] + +{ #category : #accessing } +SoilIndex >> size [ + "We iterate over all elements to get the size. Slow!" + ^ self newIterator size +] + +{ #category : #accessing } +SoilIndex >> store [ + ^ store ifNil: [ + store := self newFileStore ] +] + +{ #category : #accessing } +SoilIndex >> store: anObject [ + anObject index: self. + store := anObject +] + +{ #category : #converting } +SoilIndex >> thePersistentInstance [ + ^ self subclassResponsibility +] + +{ #category : #accessing } +SoilIndex >> valueSize [ + ^ self headerPage valueSize +] + +{ #category : #accessing } +SoilIndex >> valueSize: anInteger [ + self headerPage valueSize: anInteger +] diff --git a/src/Soil-Core/SoilSkipList.class.st b/src/Soil-Core/SoilSkipList.class.st index 2c2e996b..d6d0660b 100644 --- a/src/Soil-Core/SoilSkipList.class.st +++ b/src/Soil-Core/SoilSkipList.class.st @@ -21,17 +21,12 @@ SoilSkipList >> asCopyOnWrite [ yourself ] -{ #category : #'opening/closing' } -SoilSkipList >> close [ - self store close -] - { #category : #deleting } SoilSkipList >> destroy [ path ensureDelete ] -{ #category : #accessing } +{ #category : #deleting } SoilSkipList >> flush [ self store flush ] @@ -54,7 +49,7 @@ SoilSkipList >> initializeParametersFrom: aSoilSkipList [ valueSize: aSoilSkipList valueSize ] -{ #category : #private } +{ #category : #testing } SoilSkipList >> isPersistent [ ^ path notNil ] @@ -136,7 +131,6 @@ SoilSkipList >> thePersistentInstance [ { #category : #accessing } SoilSkipList >> valueSize [ - "^ 8" ^ valueSize ifNil: [ valueSize := super valueSize ] ]