summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorpkoppstein <pkoppstein@gmail.com>2014-10-07 09:43:11 -0400
committerNicolas Williams <nico@cryptonector.com>2014-12-27 18:44:20 -0600
commit00f018a054aa6411431d9e62549f4db7d9aaa235 (patch)
tree5c4f84a3a230bc99429f4ee605cb551cc663b204 /docs
parent56344670f4aea8bedb5bbbab55c28918fa9224a8 (diff)
bsearch(x) (binary search): builtin.c (tested), with documentation and test case. Always yields an integer (even if input is unsorted); returns (-1 - ix) if x is not in input array.
Diffstat (limited to 'docs')
-rw-r--r--docs/content/3.manual/manual.yml23
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml
index cfd87c24..76231b8d 100644
--- a/docs/content/3.manual/manual.yml
+++ b/docs/content/3.manual/manual.yml
@@ -1461,6 +1461,29 @@ sections:
output: ['[1,2],[null,3]']
+ - title: "`bsearch(x)`"
+ body: |
+
+ bsearch(x) conducts a binary search for x in the input
+ array. If the input is sorted and contains x, then
+ bsearch(x) will return its index in the array; otherwise, if
+ the array is sorted, it will return (-1 - ix) where ix is an
+ insertion point such that the array would still be sorted
+ after the insertion of x at ix. If the array is not sorted,
+ bsearch(x) will return an integer that is probably of no
+ interest.
+
+ examples:
+ - program: 'bsearch(0)'
+ input: '[0,1]'
+ output: ['0']
+ - program: 'bsearch(0)'
+ input: '[1,2,3]'
+ output: ['-1']
+ - program: 'bsearch(4) as $ix | if $ix < 0 then .[-(1+$ix)] = 4 else . end'
+ input: '[1,2,3]'
+ output: ['[1,2,3,4]']
+
- title: "String interpolation - `\\(foo)`"
body: |