diff --git a/src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st b/src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st index 6b87d143..462aa254 100644 --- a/src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st +++ b/src/Soil-Core-Tests/SoilIndexedDictionaryTest.class.st @@ -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 [ diff --git a/src/Soil-Core/SoilIndexIterator.class.st b/src/Soil-Core/SoilIndexIterator.class.st index 74ec48b0..309b5796 100644 --- a/src/Soil-Core/SoilIndexIterator.class.st +++ b/src/Soil-Core/SoilIndexIterator.class.st @@ -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" diff --git a/src/Soil-Core/SoilIndexedDictionary.class.st b/src/Soil-Core/SoilIndexedDictionary.class.st index 6c1d1449..3b7ad609 100644 --- a/src/Soil-Core/SoilIndexedDictionary.class.st +++ b/src/Soil-Core/SoilIndexedDictionary.class.st @@ -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"