File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from chapter14 .textbook14_3 import interval_search , overlap
1+ from chapter14 .textbook14_3 import overlap
22
33
4- def min_interval_search (T , i ):
5- x = interval_search (T , i )
6- if x is not T .nil :
7- y = x .left
8- while y is not T .nil :
9- if overlap (i , y .int ):
10- x = y
11- y = x .left
12- else :
13- if y .left is not T .nil and y .left .max >= i .low :
14- y = y .left
15- else :
16- y = y .right
17- return x
4+ def interval_search_lowest (T , i ):
5+ x = T .root
6+ y = T .nil
7+ while x is not T .nil :
8+ if overlap (i , x .int ) and (y is T .nil or x .int .low < y .int .low ):
9+ y = x
10+ if x .left is not T .nil and x .left .max >= i .low :
11+ x = x .left
12+ else :
13+ x = x .right
14+ return y
Original file line number Diff line number Diff line change 33
44from hamcrest import *
55
6- from chapter14 .exercise14_3_3 import min_interval_search
6+ from chapter14 .exercise14_3_3 import interval_search_lowest
77from chapter14 .textbook14_3 import overlap
88from datastructures .array import Array
99from datastructures .essential import Interval
1212
1313class TestExercise14_3_3 (TestCase ):
1414
15- def test_min_interval_search (self ):
15+ def test_interval_search_lowest (self ):
1616 tree = get_random_interval_tree ()
1717 inorder_nodes = get_binary_search_tree_inorder_nodes (tree )
1818 inorder_intervals = Array (node .int for node in inorder_nodes )
1919 low_endpoint = random .randint (0 , 949 )
2020 high_endpoint = low_endpoint + random .randint (0 , 50 )
2121 interval = Interval (low_endpoint , high_endpoint )
2222
23- actual_found = min_interval_search (tree , interval )
23+ actual_found = interval_search_lowest (tree , interval )
2424
2525 if actual_found is not tree .nil :
2626 assert_that (overlap (actual_found .int , interval ))
You can’t perform that action at this time.
0 commit comments