Skip to content

Commit

Permalink
use atIndex: and first: of the iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusDenker committed Dec 15, 2023
1 parent f9df3ca commit 6f60648
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
18 changes: 3 additions & 15 deletions src/Soil-Core/SoilBasicBTree.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ SoilBasicBTree >> at: aKeyObject put: anObject [

{ #category : #accessing }
SoilBasicBTree >> atIndex: anInteger [
| current iterator |
iterator := self newIterator.
current := iterator first.
2 to: anInteger do: [ :idx |
current := iterator next ].
^ current value
^ self newIterator atIndex: anInteger
]

{ #category : #'open/close' }
Expand All @@ -70,15 +65,8 @@ SoilBasicBTree >> first [
]

{ #category : #accessing }
SoilBasicBTree >> first: anInteger [
| iterator col |
iterator := self newIterator.
col := OrderedCollection new: anInteger.
anInteger timesRepeat: [
(iterator nextPresent)
ifNotNil: [ :value | col add: value ]
ifNil: [ ^ col ]].
^ col
SoilBasicBTree >> first: anInteger [
^ self newIterator first: anInteger
]

{ #category : #accessing }
Expand Down
20 changes: 4 additions & 16 deletions src/Soil-Core/SoilBasicSkipList.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ SoilBasicSkipList >> at: aKeyObject put: anObject [
]

{ #category : #accessing }
SoilBasicSkipList >> atIndex: anInteger [
| current iterator |
iterator := self newIterator.
current := iterator first.
2 to: anInteger do: [ :idx |
current := iterator next ].
^ current value
SoilBasicSkipList >> atIndex: anInteger [
^ self newIterator atIndex: anInteger
]

{ #category : #accessing }
Expand All @@ -69,15 +64,8 @@ SoilBasicSkipList >> first [
]

{ #category : #accessing }
SoilBasicSkipList >> first: anInteger [
| iterator col |
iterator := self newIterator.
col := OrderedCollection new: anInteger.
anInteger timesRepeat: [
(iterator nextPresent)
ifNotNil: [ :value | col add: value ]
ifNil: [ ^ col ]].
^ col
SoilBasicSkipList >> first: anInteger [
^ self newIterator first: anInteger
]

{ #category : #accessing }
Expand Down

0 comments on commit 6f60648

Please sign in to comment.