1
- as yet unclassified
1
+ searching
2
2
binarySearch: anElement
3
- < layer: #bpInstrumented >
4
3
< exampleNamed: ' basic' active: true self : ' BPSearchCollection newFrom: (1 to: 15)' with: ' 15' >
5
- < exampleNamed: ' not found' self : #numbersUpTo10 with: ' 20' >
6
- < exampleNamed: ' broken example' with: ' ' >
7
-
8
- | index low high flag |
9
- self bpBlock: 1 enteredAt: thisContext.
10
- low := 1 .
11
- high := self size.
12
- flag := Object new .
13
-
14
- self bpBlock: 1 leftWith: ([self bpBlock: 2 enteredAt: thisContext.
15
- self bpBlock: 2 leftWith: (high < low) at: thisContext] whileFalse: [
16
- self bpBlock: 3 enteredAt: thisContext.
17
- index := (self bpAssertAfter: [high + low // 2 ] that: [:result | result < 20 ] forAssertion: 7345425 given: ' BPSearchCollection>>#binarySearch:>>#' ' not found' ' ' inContext: thisContext).self bpBlock: 3 leftWith: ((anElement < (self at: (self bpTrace: [index] forProbe: 3156627 inContext: thisContext)))
18
- ifTrue: [ self bpBlock: 4 enteredAt: thisContext.
19
- self bpBlock: 4 leftWith: (high := index - 1 ) at: thisContext ]
4
+ < exampleNamed: ' not found' active: true self : #numbersUpTo10 with: ' 20' >
5
+ < exampleNamed: ' large example' active: true self : #numbersUpTo10000 with: ' 4532' >
6
+ | index low high |
7
+ low := 1 .
8
+ high := " <bpReplace for: 'BPSearchCollection>>#binarySearch:>>#''not found''' with: [20]>" self size" </bpReplace>" .
9
+
10
+ [high < low] whileFalseDo: " <bpSlider id: 5638804>" [
11
+ index := " <bpAssert id: 7345425 for: 'BPSearchCollection>>#binarySearch:>>#''large example''' that: [:result | result between: 4000 and: 5000]>" high + low // 2 " </bpAssert>" .
12
+ (anElement < (self at: " <bpProbe id: 3156627>" index" </bpProbe>" ))
13
+ ifTrue: [ high := index - 1 ]
20
14
ifFalse: [
21
- self bpBlock: 5 enteredAt: thisContext.
22
- self bpBlock: 5 leftWith: (anElement > (self at: index)
23
- ifTrue: [ self bpBlock: 6 enteredAt: thisContext.
24
- self bpBlock: 6 leftWith: ((self bpTraceAssignmentOf: [low := index + 1 ] before: {' low' . low} forProbe: 4824443 inContext: thisContext)) at: thisContext]
25
- ifFalse: [ self bpBlock: 7 enteredAt: thisContext.
26
- ^ self bpBlock: 7 leftWith: ((self bpTrace: [index] forProbe: 5475766 inContext: thisContext)) at: thisContext ]) at: thisContext]) at: thisContext]) at: thisContext.
15
+ anElement > (self at: index)
16
+ ifTrue: [ low := index + 1 ]
17
+ ifFalse: [ ^ index ]]]" </bpSlider>" .
0 commit comments