Skip to content

Commit

Permalink
Merge pull request #594 from ApptiveGrid/cleanup-firstAssociation-las…
Browse files Browse the repository at this point in the history
…tAssociation
  • Loading branch information
noha authored Feb 8, 2024
2 parents 1273556 + e6a9e97 commit 4a3b2b6
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 35 deletions.
84 changes: 66 additions & 18 deletions src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,13 @@ SoilIndexedDictionaryTest >> testFirstAssociationWithTransaction [
| tx tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: 1 put: #one.
dict at: 2 put: #two.
"self assert: dict last equals: #two."
dict at: #one put: #onevalue.
dict at: #two put: #twovalue.
tx commit.
"open a second transaction ..."
tx2 := soil newTransaction.
"and test last"
self assert: tx2 root firstAssociation equals: 1->#one.
self assert: tx2 root firstAssociation value equals: #onevalue.

]

Expand All @@ -286,18 +285,17 @@ SoilIndexedDictionaryTest >> testFirstAssociationWithTransactionRemoved [
| tx tx1 tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: 1 put: #one.
dict at: 2 put: #two.
"self assert: dict last equals: #two."
dict at: #one put: #onevalue.
dict at: #two put: #twovalue.
tx commit.

"open a two transactions ..."
tx1 := soil newTransaction.
tx2 := soil newTransaction.
tx2 root removeKey: 1.
tx2 root removeKey: #one.
tx2 commit.
"in tx1 the removed one is not removed"
self assert: tx1 root firstAssociation equals: 1->#one.
self assert: tx1 root firstAssociation value equals: #onevalue.

]

Expand All @@ -318,6 +316,25 @@ SoilIndexedDictionaryTest >> testFirstWithTransaction [

]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFirstWithTransactionRemoved [
| tx tx1 tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: #one put: #onevalue.
dict at: #two put: #twovalue.
tx commit.

"open a two transactions ..."
tx1 := soil newTransaction.
tx2 := soil newTransaction.
tx2 root removeKey: #one.
tx2 commit.
"in tx1 the removed one is not removed"
self assert: tx1 root first equals: #onevalue.

]

{ #category : #tests }
SoilIndexedDictionaryTest >> testFlushIndexPages [
| tx capacity txn2 txn1 root1 root2 |
Expand Down Expand Up @@ -407,34 +424,32 @@ SoilIndexedDictionaryTest >> testLastAssociationWithTransaction [
| tx tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: 2 put: #two.
dict at: 1 put: #one.
dict at: #two put: #twovalue.
dict at: #one put: #onevalue.

"self assert: dict last equals: #two."
tx commit.
"open a second transaction ..."
tx2 := soil newTransaction.
"and test last, not: key order"
self assert: tx2 root lastAssociation equals: 2->#two
self assert: tx2 root lastAssociation value equals: #twovalue
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testLastAssociationWithTransactionRemoved [
| tx tx1 tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: 1 put: #one.
dict at: 2 put: #two.
"self assert: dict last equals: #two."
dict at: #one put: #onevalue.
dict at: #two put: #twovalue.
tx commit.

"open a two transactions ..."
tx1 := soil newTransaction.
tx2 := soil newTransaction.
tx2 root removeKey: 2.
tx2 root removeKey: #two.
tx2 commit.
"in tx1 the removed one is not removed"
self assert: tx1 root lastAssociation equals: 2->#two.
self assert: tx1 root lastAssociation value equals: #twovalue.

]

Expand Down Expand Up @@ -470,6 +485,39 @@ SoilIndexedDictionaryTest >> testLastWithTransactionRemoveLast [
self assert: tx2 root last equals: #onevalue
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testLastWithTransactionRemoved [
| tx tx1 tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: #one put: #onevalue.
dict at: #two put: #twovalue.
tx commit.

"open a two transactions ..."
tx1 := soil newTransaction.
tx2 := soil newTransaction.
tx2 root removeKey: #two.
tx2 commit.
"in tx1 the removed one is not removed"
self assert: tx1 root last equals: #twovalue.

]

{ #category : #tests }
SoilIndexedDictionaryTest >> testNextAfterWithTransaction [
| tx tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: #one put: #onevalue.
dict at: #two put: #twovalue.
tx commit.
"open a second transaction ..."
tx2 := soil newTransaction.
"and test last"
self assert: (tx2 root nextAfter: #one) value equals: #twovalue
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testNextAssociationAfterWithTransaction [
| tx tx2 |
Expand Down
4 changes: 2 additions & 2 deletions src/Soil-Core/SoilBTreeIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Class {
}

{ #category : #accessing }
SoilBTreeIterator >> basicAt: key put: anObject [
SoilBTreeIterator >> basicAt: binKey put: anObject [
| posiblePrioValue |
posiblePrioValue := index rootPage insertItem: (key -> anObject) for: self.
posiblePrioValue := index rootPage insertItem: (binKey -> anObject) for: self.
"as an optimization we return the prior value stored in the list. If there was none we return nil"
^ posiblePrioValue returnValue
]
Expand Down
10 changes: 6 additions & 4 deletions src/Soil-Core/SoilIndexIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SoilIndexIterator >> basicAssociationsDo: aBlock [
]

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

Expand Down Expand Up @@ -164,6 +164,7 @@ SoilIndexIterator >> first: anInteger [

{ #category : #accessing }
SoilIndexIterator >> firstAssociation [
"Note: key will be binary key"
| item |
currentPage := index store headerPage.
item := self nextAssociation.
Expand Down Expand Up @@ -235,6 +236,7 @@ SoilIndexIterator >> last [

{ #category : #accessing }
SoilIndexIterator >> lastAssociation [
"Note: key will be binary key"
| lastAssociation lastValue key |
lastAssociation := self priorAssociation ifNil: [ ^nil ].
lastValue := (self
Expand Down Expand Up @@ -266,7 +268,7 @@ SoilIndexIterator >> next: anInteger [

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

"Note: key will be binary key"
| nextAssociation nextValue key |
nextAssociation := self basicNextAssociation ifNil: [ ^nil ].
nextValue := (self
Expand All @@ -277,14 +279,14 @@ SoilIndexIterator >> nextAssociation [

{ #category : #accessing }
SoilIndexIterator >> nextAssociationAfter: key [

"Note: key will be binary key"
self find: key.
^ self nextAssociation
]

{ #category : #private }
SoilIndexIterator >> nextKeyCloseTo: key [

"Note: returnrd key will be binary key"
| binKey |
binKey := (key asIndexKeyOfSize: index keySize) asInteger.
self findPageFor: binKey.
Expand Down
9 changes: 5 additions & 4 deletions src/Soil-Core/SoilIndexedDictionary.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ SoilIndexedDictionary >> first: anInteger [

{ #category : #accessing }
SoilIndexedDictionary >> firstAssociation [

"Note: key will be binary key"
^ self newIterator firstAssociation ifNotNil: [ :assoc |
assoc key -> (transaction objectWithId: assoc value asSoilObjectId) ]
]
Expand Down Expand Up @@ -148,7 +148,7 @@ SoilIndexedDictionary >> last [

{ #category : #accessing }
SoilIndexedDictionary >> lastAssociation [

"Note: key will be binary key"
^ self newIterator lastAssociation ifNotNil: [ :assoc |
assoc key -> (transaction objectWithId: assoc value asSoilObjectId) ]

Expand Down Expand Up @@ -183,14 +183,15 @@ SoilIndexedDictionary >> nextAfter: key [

{ #category : #accessing }
SoilIndexedDictionary >> nextAssociationAfter: key [

"Note: key will be binary key"
^ (self newIterator nextAssociationAfter: key)
ifNotNil: [ :assoc |
assoc key -> (transaction objectWithId: assoc value asSoilObjectId) ]
]

{ #category : #private }
SoilIndexedDictionary >> nextKeyCloseTo: aKey [
SoilIndexedDictionary >> nextKeyCloseTo: aKey [
"Note: key will be binary key"
^ self newIterator nextKeyCloseTo: aKey
]

Expand Down
14 changes: 7 additions & 7 deletions src/Soil-Core/SoilSkipListIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ SoilSkipListIterator >> atLevel: key put: anObject [
]

{ #category : #accessing }
SoilSkipListIterator >> basicAt: key put: anObject [
SoilSkipListIterator >> basicAt: binKey put: anObject [

|itemIndex |
self findPageFor: key.
itemIndex := currentPage indexOfKey: key.
self findPageFor: binKey.
itemIndex := currentPage indexOfKey: binKey.
"as an optimization we return the prior value stored in the list. If
there was none we return nil"
^ itemIndex > 0
ifTrue: [ currentPage itemAt: key put: anObject ]
ifTrue: [ currentPage itemAt: binKey put: anObject ]
ifFalse: [
currentPage hasRoom ifFalse: [ | newPage |
newPage := index splitPage: self forKey: key.
currentPage := currentPage biggestKey < key
newPage := index splitPage: self forKey: binKey.
currentPage := currentPage biggestKey < binKey
ifTrue: [ newPage ]
ifFalse: [ currentPage ] ].
currentPage addItem: key -> anObject.
currentPage addItem: binKey -> anObject.
nil ]
]

Expand Down

0 comments on commit 4a3b2b6

Please sign in to comment.