Skip to content

Commit

Permalink
Merge pull request #597 from ApptiveGrid/nextCloseTo
Browse files Browse the repository at this point in the history
Add SoilIndexedDictionary>>#nextCloseTo:
  • Loading branch information
MarcusDenker authored Feb 9, 2024
2 parents 1711c2e + 676ee9d commit 32df755
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,26 @@ SoilIndexedDictionaryTest >> testNextKeyCloseToWithTransaction [
self assert: (tx2 root nextKeyCloseTo: 15) value equals: 20
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testNextcloseToWithTransaction [
| tx tx2 |
tx := soil newTransaction.
tx root: dict.
dict at: #'10' put: #one.
dict at: #'20' put: #two.
tx commit.
"open a second transaction ..."
tx2 := soil newTransaction.
"and test"
self assert: (tx2 root nextCloseTo: #'5') equals: #one.
self assert: (tx2 root nextCloseTo: #'10') equals: #one.
self assert: (tx2 root nextCloseTo: #'11') equals: #two.
self assert: (tx2 root nextCloseTo: #'15 ') equals: #two.
self assert: (tx2 root nextCloseTo: #'20') equals: #two.
"this is a bit odd, when looking with larger values we get the last one"
self assert: (tx2 root nextCloseTo: #'100') equals: #two
]

{ #category : #tests }
SoilIndexedDictionaryTest >> testRemoveKeyIfAbsentWithTransaction [

Expand Down
6 changes: 6 additions & 0 deletions src/Soil-Core/SoilIndexIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ SoilIndexIterator >> nextAssociationAfter: key [
^ self nextAssociation
]

{ #category : #private }
SoilIndexIterator >> nextCloseTo: key [
"return the next entry after key, even if key itself is not there"
^ self at: (self nextKeyCloseTo: key)
]

{ #category : #private }
SoilIndexIterator >> nextKeyCloseTo: key [
"Note: returnrd key will be binary key"
Expand Down
5 changes: 5 additions & 0 deletions src/Soil-Core/SoilIndexedDictionary.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ SoilIndexedDictionary >> nextAssociationAfter: key [
assoc key -> (transaction objectWithId: assoc value asSoilObjectId) ]
]

{ #category : #private }
SoilIndexedDictionary >> nextCloseTo: aKey [
^ transaction objectWithId: (self newIterator nextCloseTo: aKey)
]

{ #category : #private }
SoilIndexedDictionary >> nextKeyCloseTo: aKey [
"Note: key will be binary key"
Expand Down

0 comments on commit 32df755

Please sign in to comment.