Skip to content

Commit 7f9896e

Browse files
committed
-
1 parent 349917d commit 7f9896e

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

source_py3/python_toolbox/binary_search/binary_search_profile.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ def __init__(self, sequence, value, function=misc_tools.identity_function,
3232
'''
3333
Construct a `BinarySearchProfile`.
3434
35-
`sequence` is the sequence through which the search is made. `function`
36-
is a strictly monotonic rising function on the sequence. `value` is the
37-
wanted value.
35+
`sequence` is the sequence through which the search is made. `value` is
36+
the wanted value.
37+
38+
You may optionally pass a key function as `function`, so instead of the
39+
objects in `sequence` being compared, their outputs from `function`
40+
will be compared. If you do pass in a function, it's assumed that it's
41+
strictly rising.
42+
3843
3944
In the `both` argument you may put binary search results (with the BOTH
4045
rounding option.) This will prevent the constructor from performing the

source_py3/python_toolbox/binary_search/functions.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ def binary_search_by_index(sequence, value,
2727
'''
2828
Do a binary search, returning answer as index number.
2929
30-
Similiar to binary_search (refer to its documentation for more info). The
30+
For all rounding options, a return value of None is returned if no matching
31+
item is found. (In the case of `rounding=BOTH`, either of the items in the
32+
tuple may be `None`)
33+
34+
You may optionally pass a key function as `function`, so instead of the
35+
objects in `sequence` being compared, their outputs from `function` will be
36+
compared. If you do pass in a function, it's assumed that it's strictly
37+
rising.
38+
39+
Note: This function uses `None` to express its inability to find any
40+
matches; therefore, you better not use it on sequences in which None is a
41+
possible item.
42+
43+
Similiar to `binary_search` (refer to its documentation for more info). The
3144
difference is that instead of returning a result in terms of sequence
3245
items, it returns the indexes of these items in the sequence.
3346
@@ -45,8 +58,10 @@ def _binary_search_both(sequence, value,
4558
'''
4659
Do a binary search through a sequence with the `BOTH` rounding.
4760
48-
It is assumed that `function` is a strictly monotonic rising function on
49-
`sequence`.
61+
You may optionally pass a key function as `function`, so instead of the
62+
objects in `sequence` being compared, their outputs from `function` will be
63+
compared. If you do pass in a function, it's assumed that it's strictly
64+
rising.
5065
5166
Note: This function uses `None` to express its inability to find any
5267
matches; therefore, you better not use it on sequences in which `None` is a
@@ -106,13 +121,15 @@ def binary_search(sequence, value, function=misc_tools.identity_function,
106121
'''
107122
Do a binary search through a sequence.
108123
109-
It is assumed that `function` is a strictly monotonic rising function on
110-
`sequence`.
111-
112124
For all rounding options, a return value of None is returned if no matching
113125
item is found. (In the case of `rounding=BOTH`, either of the items in the
114126
tuple may be `None`)
115127
128+
You may optionally pass a key function as `function`, so instead of the
129+
objects in `sequence` being compared, their outputs from `function` will be
130+
compared. If you do pass in a function, it's assumed that it's strictly
131+
rising.
132+
116133
Note: This function uses `None` to express its inability to find any
117134
matches; therefore, you better not use it on sequences in which None is a
118135
possible item.

0 commit comments

Comments
 (0)