~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to doc/stdlib/sort.rst

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-02-06 17:54:29 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130206175429-13br5kqpkfjqdmre
Tags: 0.0.0+20130206.git32ff5759-1
* New upstream snapshot.
* debian/copyright: reflect upstream changes
* debian/rules: update get-orig-source to reflect upstream changes
   + Don't ship nginx
   + Adapt for new configure-random target in deps/Makefile
* Enable build of Tk wrapper.
   + debian/control: add build dependency on tk-dev
   + debian/rules: add tk rule to build-arch
* debian/julia.install: install VERSION and COMMIT files
* no-webrepl.patch: new patch
* Refresh other patches
* Add source override for config.status file under deps/random/

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
The `Sort` module contains algorithms and other functions related to
8
8
sorting.  Default sort functions and standard versions of the various
9
9
sort algorithm are available by default. 
10
 
Specific versions of unexported routines can be used by importing
 
10
Specific sort algorithms can be used by importing
11
11
`Sort`, or for finer grain control, importing the fully qualified
12
 
function name, e.g.,::
 
12
algorithm name, e.g.,::
13
13
 
14
14
  # Julia code
15
 
  import Sort.timsort_perm!
 
15
  import Sort.TimSort
16
16
 
17
 
will allow use of the in-place version of timsort which provides a
18
 
permutation, which is not exported by default.  All of the sorting
19
 
routines can be made available directly with::
 
17
will allow use of timsort with the various sort functions.  All of the
 
18
sorting algorithms can be made available directly with::
20
19
 
21
20
  # Julia code
22
21
  using Sort
56
55
 
57
56
  julia> canonicalize(s) = filter(c -> ('A'<=c<='Z' || 'a'<=c<='z'), s) | uppercase
58
57
 
59
 
  julia> sort_by(canonicalize, ["New York", "New Jersey", "Nevada", "Nebraska", "Newark"])
 
58
  julia> sortby(canonicalize, ["New York", "New Jersey", "Nevada", "Nebraska", "Newark"])
60
59
  5-element ASCIIString Array:
61
60
   "Nebraska"  
62
61
   "Nevada"    
64
63
   "New Jersey"
65
64
   "New York"  
66
65
 
67
 
Note that none of the variants above modify the original arrays.  To sort in-place (which is often more efficient), each sort function has a mutating version which ends with an exclamation point (``sort!``, ``sortr!``, and ``sort_by!``).
 
66
Note that none of the variants above modify the original arrays.  To sort in-place (which is often more efficient), each sort function has a mutating version which ends with an exclamation point (``sort!``, ``sortr!``, and ``sortby!``).
68
67
 
69
 
There are also versions of these functions which, in addition to returning a sorted array, will return the permutation of original indices which create the sorted array.  These are ``sortperm``, ``sortperm_r``, and ``sortperm_by``, along with mutating versions ``sortperm!``, ``sortperm_r!``, and ``sortperm_by!``.
 
68
There are also versions of these functions which, in addition to returning a sorted array, will return the permutation of original indices which create the sorted array.  These are ``sortperm``, ``sortpermr``, and ``sortpermby``, along with mutating versions ``sortperm!``, ``sortpermr!``, and ``sortpermby!``.
70
69
 
71
70
These sort functions use reasonable default algorithms, but if you
72
71
want more control or want to see if a different sort algorithm will
78
77
 
79
78
There are currently four main sorting algorithms available in Julia::
80
79
 
81
 
  insertionsort
82
 
  quicksort
83
 
  mergesort
84
 
  timsort
 
80
  InsertionSort
 
81
  QuickSort
 
82
  MergeSort
 
83
  TimSort
85
84
 
86
85
Insertion sort is an O(n^2) stable sorting algorithm.  It is
87
86
efficient for very small ``n``, and is used internally by
88
 
``quicksort!`` and ``timsort!``. 
 
87
``QuickSort`` and ``TimSort``. 
89
88
 
90
89
Quicksort is an O(n log n) sorting algorithm.  For efficiency, it
91
90
is not stable.  It is among the fastest sorting algorithms.
96
95
takes advantage of sorted runs which exist in many real world
97
96
datasets.  
98
97
 
99
 
The ``sort``, ``sortr``, ``sort_by``, and ``sortperm`` functions select a reasonable
100
 
default algorithm, depending on the type of the target array.
 
98
The sort functions select a reasonable default algorithm, depending on
 
99
the type of the target array.
101
100
 
102
 
Mutating and non-mutating versions of the sort functions and of each
103
 
of the algorithm functions are exported and available for use by
 
101
Mutating and non-mutating versions of the sort functions using each
 
102
of the algorithms above are exported and available for use by
104
103
default.
105
104
 
106
 
+-------------------+--------------------+---------+-------------------+
107
 
| Non-mutating      | Mutating           | Stable  |  Time Complexity  |
108
 
+===================+====================+=========+===================+
109
 
| ``sort``          | ``sort!``          |  (\*)   |    O(n log n)     |
110
 
+-------------------+--------------------+---------+-------------------+
111
 
| ``sortr``         | ``sortr!``         |  (\*)   |    O(n log n)     |
112
 
+-------------------+--------------------+---------+-------------------+
113
 
| ``sort_by``       | ``sort_by!``       |  (\*)   |    O(n log n)     |
114
 
+-------------------+--------------------+---------+-------------------+
115
 
| ``sortperm``      | ``sortperm!``      |  (\*)   |    O(n log n)     |
116
 
+-------------------+--------------------+---------+-------------------+
117
 
| ``insertionsort`` | ``insertionsort!`` |  yes    |      O(n^2)       |
118
 
+-------------------+--------------------+---------+-------------------+
119
 
| ``quicksort``     | ``quicksort!``     |   no    |    O(n log n)     |
120
 
+-------------------+--------------------+---------+-------------------+
121
 
| ``mergesort``     | ``mergesort!``     |  yes    |    O(n log n)     |
122
 
+-------------------+--------------------+---------+-------------------+
123
 
| ``timsort``       | ``timsort!``       |  yes    |   <= O(n log n)   |
124
 
+-------------------+--------------------+---------+-------------------+
125
 
 
126
 
(\*) Stability depends on the algorithm for the target array data type.
127
 
 
128
 
In addition to the exported functions shown in the table, each of the
129
 
algorithms also has an additional set of unexported functions for
130
 
reverse sorting, sorting by a function of the data, and for the stable
131
 
sorts, function varieties which return a permutation in addition to
132
 
the sorted array.  These are shown in the table below.
133
 
 
134
 
+----------------------+---------------------------+----------------------------+--------------------------+
135
 
| Sort                 |  Non-mutating Variation   | Mutating Variation         | Function                 |
136
 
+======================+===========================+============================+==========================+
137
 
| ``insertionsort``    | ``insertionsort_r``       | ``insertionsort_r!``       | Reverse sort             |
138
 
+----------------------+---------------------------+----------------------------+--------------------------+
139
 
|                      | ``insertionsort_by``      | ``insertionsort_by!``      | Sort by function         |
140
 
+----------------------+---------------------------+----------------------------+--------------------------+
141
 
|                      | ``insertionsort_perm``    | ``insertionsort_perm!``    | Permutation sort         |
142
 
+----------------------+---------------------------+----------------------------+--------------------------+
143
 
|                      | ``insertionsort_perm_r``  | ``insertionsort_perm_r!``  | Reverse permutation sort |
144
 
+----------------------+---------------------------+----------------------------+--------------------------+
145
 
|                      | ``insertionsort_perm_by`` | ``insertionsort_perm_by!`` | Permutation sort by func |
146
 
+----------------------+---------------------------+----------------------------+--------------------------+
147
 
| ``mergesort``        | ``mergesort_r``           | ``mergesort_r!``           | Reverse sort             |
148
 
+----------------------+---------------------------+----------------------------+--------------------------+
149
 
|                      | ``mergesort_by``          | ``mergesort_by!``          | Sort by function         |
150
 
+----------------------+---------------------------+----------------------------+--------------------------+
151
 
|                      | ``mergesort_perm``        | ``mergesort_perm!``        | Permutation sort         |
152
 
+----------------------+---------------------------+----------------------------+--------------------------+
153
 
|                      | ``mergesort_perm_r``      | ``mergesort_perm_r!``      | Reverse permutation sort |
154
 
+----------------------+---------------------------+----------------------------+--------------------------+
155
 
|                      | ``mergesort_perm_by``     | ``mergesort_perm_by!``     | Permutation sort by func |
156
 
+----------------------+---------------------------+----------------------------+--------------------------+
157
 
| ``timsort``          | ``timsort_r``             | ``timsort_r!``             | Reverse sort             |
158
 
+----------------------+---------------------------+----------------------------+--------------------------+
159
 
|                      | ``timsort_by``            | ``timsort_by!``            | Sort by function         |
160
 
+----------------------+---------------------------+----------------------------+--------------------------+
161
 
|                      | ``timsort_perm``          | ``timsort_perm!``          | Permutation sort         |
162
 
+----------------------+---------------------------+----------------------------+--------------------------+
163
 
|                      | ``timsort_perm_r``        | ``timsort_perm_r!``        | Reverse permutation sort |
164
 
+----------------------+---------------------------+----------------------------+--------------------------+
165
 
|                      | ``timsort_perm_by``       | ``timsort_perm_by!``       | Permutation sort by func |
166
 
+----------------------+---------------------------+----------------------------+--------------------------+
167
 
| ``quicksort``        | ``quicksort_r``           | ``quicksort_r!``           | Reverse sort             |
168
 
+----------------------+---------------------------+----------------------------+--------------------------+
169
 
|                      | ``quicksort_by``          | ``quicksort_by!``          | Sort by function         |
170
 
+----------------------+---------------------------+----------------------------+--------------------------+
171
105
 
172
106
Functions
173
107
---------
175
109
----------------------
176
110
General Sort Functions
177
111
----------------------
178
 
.. function:: sort(v)
179
 
 
180
 
   Sort a vector in ascending order, according to ``isless``.
181
 
 
182
 
.. function:: sort!(v)
 
112
.. function:: sort(v[, dim])
 
113
 
 
114
   Sort a vector in ascending order.  If ``dim`` is provided, sort
 
115
   along the given dimension. 
 
116
 
 
117
.. function:: sort(lessthan, v[, dim])
 
118
 
 
119
   Sort with a custom comparison function.
 
120
 
 
121
.. function:: sort(alg, ...)
 
122
 
 
123
   Sort using a specific sorting algorithm (InsertionSort, QuickSort,
 
124
   MergeSort, or TimSort). 
 
125
 
 
126
.. function:: sort!(...)
183
127
 
184
128
   In-place sort.
185
129
 
186
 
.. function:: sortr(v)
187
 
 
188
 
   Sort a vector in descending order.
189
 
 
190
 
.. function:: sortr!(v)
191
 
 
192
 
   In-place sort in descending-order.
193
 
 
194
 
.. function:: sort_by(by, v)
195
 
 
196
 
   Sort a vector by the result of applying function ``by``
197
 
   to every element.
198
 
 
199
 
.. function:: sort_by!(by, v)
200
 
 
201
 
   Sort a vector in place by the result of applying function ``by``
202
 
   to every element.
203
 
 
204
 
.. function:: sort(a, dim)
205
 
 
206
 
   Sort an array along the given dimension.
207
 
 
208
 
.. function:: sort(lessthan, a, [dim])
209
 
 
210
 
   Sort with a custom comparison function.
 
130
.. function:: sortr(v[, dim])
 
131
 
 
132
   Sort a vector in descending order. If ``dim`` is provided, sort
 
133
   along the given dimension. 
 
134
 
 
135
.. function:: sortr(alg, ...)
 
136
 
 
137
   Sort in descending order with a specific sorting algorithm
 
138
   (InsertionSort, QuickSort, MergeSort, or TimSort).
 
139
 
 
140
.. function:: sortr!(...)
 
141
 
 
142
   In-place ``sortr``.
 
143
 
 
144
.. function:: sortby(by, v[, dim])
 
145
 
 
146
   Sort a vector according to ``by(v)``.   If ``dim`` is provided,
 
147
   sort along the given dimension. 
 
148
 
 
149
.. function:: sortby(alg, ...)
 
150
 
 
151
   ``sortby`` using a specific sorting algorithm (``InsertionSort``,
 
152
   ``QuickSort``, ``MergeSort``, or ``TimSort``). 
 
153
 
 
154
.. function:: sortby!(...)
 
155
 
 
156
   In-place ``sortby``.
211
157
 
212
158
.. function:: sortperm(v) -> s,p
213
159
 
214
 
   Sort a vector in ascending order, also constructing the permutation that sorts the vector
215
 
 
216
 
.. function:: sortperm!(v) -> s,p
217
 
 
218
 
   Sort a vector in ascending order in-place, also constructing the permutation that sorts the vector
219
 
 
220
 
.. function:: sortperm_r(v) -> s,p
221
 
 
222
 
   Sort a vector in descending order, also constructing the permutation that sorts the vector
223
 
 
224
 
.. function:: sortperm_r!(v) -> s,p
225
 
 
226
 
   Sort a vector in descending order in-place, also constructing the permutation that sorts the vector
227
 
 
228
 
.. function:: sortperm_by(by,v) -> s,p
 
160
   Sort a vector in ascending order, also constructing the permutation
 
161
   that sorts the vector.
 
162
 
 
163
.. function:: sortperm(lessthan, v) -> s,p
 
164
 
 
165
   Sort a vector with a custom comparison function, also constructing
 
166
   the permutation that sorts the vector.
 
167
 
 
168
.. function:: sortperm(alg, ...) -> s,p
 
169
 
 
170
   ``sortperm`` using a specific sorting algorithm (``InsertionSort``,
 
171
   ``QuickSort``, ``MergeSort``, or ``TimSort``).
 
172
 
 
173
.. function:: sortperm!(...) -> s,p
 
174
 
 
175
   In-place ``sortperm``.
 
176
 
 
177
.. function:: sortpermr(v) -> s,p
 
178
 
 
179
   Sort a vector in descending order, also constructing the
 
180
   permutation that sorts the vector!
 
181
 
 
182
.. function:: sortpermr(alg, ...) -> s,p
 
183
 
 
184
   ``sortpermr`` using a specific sorting algorithm
 
185
   (``InsertionSort``, ``QuickSort``, ``MergeSort``, or ``TimSort``).
 
186
 
 
187
.. function:: sortpermr!(v) -> s,p
 
188
 
 
189
   In-place ``sortpermr``.
 
190
 
 
191
.. function:: sortpermby(by,v) -> s,p
229
192
 
230
193
   Sort a vector according to the result of function ``by`` applied to
231
194
   all values, also constructing the permutation that sorts the vector.
232
195
 
233
 
.. function:: sortperm_by!(by,v) -> s,p
234
 
 
235
 
   Sort a vector in-place according to the result of function ``by``
236
 
   applied to all values of ``v``, also constructing the permutation
237
 
   that sorts the vector
238
 
 
239
 
 
240
 
---------------------------
241
 
Specific Sort Functions
242
 
---------------------------
243
 
 
244
 
.. function:: insertionsort(v[,dim])
245
 
 
246
 
   Sort a vector in ascending order with insertion sort, according to ``isless``.
247
 
 
248
 
.. function:: insertionsort(lessthan,v[,dim])
249
 
 
250
 
   Sort a vector in ascending order with insertion sort, using a
251
 
   custom comparison function.
252
 
 
253
 
.. function:: insertionsort!(v[,dim])
254
 
.. function:: insertionsort!(v[,lo,hi])
255
 
 
256
 
   In-place insertion sort, accoring to ``isless``.
257
 
 
258
 
.. function:: insertionsort!(lessthan,v[,dim])
259
 
.. function:: insertionsort!(lessthan,v[,lo,hi])
260
 
 
261
 
   In-place insertion sort with a custom comparison function.
262
 
 
263
 
.. function:: insertionsort_r(v[,dim])
264
 
.. function:: insertionsort_r(v[,lo,hi])
265
 
 
266
 
   Sort a vector in descending order using insertion sort.
267
 
 
268
 
.. function:: insertionsort_r!(v[,dim])
269
 
.. function:: insertionsort_r!(v[,lo,hi])
270
 
 
271
 
   In-place insertion sort in descending order.
272
 
 
273
 
.. function:: insertionsort_by(by,v[,dim])
274
 
.. function:: insertionsort_by(by,v[,lo,hi])
275
 
 
276
 
   Sort a vector with insertion sort according to the result of
277
 
   function ``by`` applied to all values.
278
 
 
279
 
.. function:: insertionsort_by!(by,v[,dim]) 
280
 
.. function:: insertionsort_by!(by,v[,lo,hi]) 
281
 
 
282
 
   Sort a vector with insertion sort in place according to the result
283
 
   of function ``by`` applied to all values.
284
 
 
285
 
.. function:: insertionsort_perm(v[,p[,lo,hi]]) -> s,p
286
 
 
287
 
   Sort a vector in ascending order, also constructing the
288
 
   permutation that sorts the vector 
289
 
 
290
 
   If provided, ``p`` is an initial permutation.
291
 
 
292
 
.. function:: insertionsort_perm(lessthan,v[,p[,lo,hi]]) -> s,p
293
 
 
294
 
   Sort a vector, using a custom comparison function, also
295
 
   constructing the permutation that sorts the vector .
296
 
 
297
 
   If provided, ``p`` is an initial permutation.
298
 
 
299
 
.. function:: insertionsort_perm!(v[,p[,lo,hi]])
300
 
 
301
 
   Sort a vector in ascending order in-place, also constructing the
302
 
   permutation that sorts the vector 
303
 
 
304
 
   If provided, ``p`` is an initial permutation.
305
 
 
306
 
.. function:: insertionsort_perm!(lessthan,v[,p[,lo,hi]])
307
 
 
308
 
   Sort a vector in place, using a custom comparison function, also 
309
 
   constructing the permutation that sorts the vector .
310
 
 
311
 
   If provided, ``p`` is an initial permutation.
312
 
 
313
 
.. function:: insertionsort_perm_r(v[,p,[,lo,hi]])
314
 
 
315
 
   Sort a vector in descending order, also constructing the
316
 
   permutation that sorts the vector 
317
 
 
318
 
   If provided, ``p`` is an initial permutation.
319
 
 
320
 
.. function:: insertionsort_perm_r!(v[,p,[,lo,hi]])
321
 
 
322
 
   Sort a vector in descending order in place, also constructing the
323
 
   permutation that sorts the vector 
324
 
 
325
 
   If provided, ``p`` is an initial permutation.
326
 
 
327
 
.. function:: insertionsort_perm_by(by,v[,p[,lo,hi]])
328
 
 
329
 
   Sort a vector with insertion sort according to the result
330
 
   of function ``by`` applied to all values.
331
 
 
332
 
   If provided, ``p`` is an initial permutation.
333
 
 
334
 
.. function:: insertionsort_perm_by!(by,v[,p[,lo,hi]])
335
 
 
336
 
   Sort a vector with insertion sort in place according to the result 
337
 
   of function ``by`` applied to all values.
338
 
 
339
 
   If provided, ``p`` is an initial permutation.
340
 
 
341
 
 
342
 
.. function:: mergesort(v[,dim])
343
 
 
344
 
   Sort a vector in ascending order with mergesort, according to ``isless``.
345
 
 
346
 
.. function:: mergesort(lessthan,v[,dim])
347
 
 
348
 
   Sort a vector in ascending order with mergesort, using a
349
 
   custom comparison function.
350
 
 
351
 
.. function:: mergesort!(v[,dim])
352
 
.. function:: mergesort!(v[,lo,hi])
353
 
 
354
 
   In-place mergesort, accoring to ``isless``.
355
 
 
356
 
.. function:: mergesort!(lessthan,v[,dim])
357
 
.. function:: mergesort!(lessthan,v[,lo,hi])
358
 
 
359
 
   In-place mergesort with a custom comparison function.
360
 
 
361
 
.. function:: mergesort_r(v[,dim])
362
 
.. function:: mergesort_r(v[,lo,hi])
363
 
 
364
 
   Sort a vector in descending order using mergesort.
365
 
 
366
 
.. function:: mergesort_r!(v[,dim])
367
 
.. function:: mergesort_r!(v[,lo,hi])
368
 
 
369
 
   In-place mergesort in descending order.
370
 
 
371
 
.. function:: mergesort_by(by,v[,dim])
372
 
.. function:: mergesort_by(by,v[,lo,hi])
373
 
 
374
 
   Sort a vector with mergesort according to the result of
375
 
   function ``by`` applied to all values.
376
 
 
377
 
.. function:: mergesort_by!(by,v[,dim])
378
 
.. function:: mergesort_by!(by,v[,lo,hi]) 
379
 
 
380
 
   Sort a vector with mergesort in place according to the result
381
 
   of function ``by`` applied to all values.
382
 
 
383
 
.. function:: mergesort_perm(v[,p[,lo,hi]]) -> s,p
384
 
 
385
 
   Sort a vector in ascending order, also constructing the
386
 
   permutation that sorts the vector 
387
 
 
388
 
   If provided, ``p`` is an initial permutation.
389
 
 
390
 
.. function:: mergesort_perm(lessthan,v[,p[,lo,hi]]) -> s,p
391
 
 
392
 
   Sort a vector, using a custom comparison function, also
393
 
   constructing the permutation that sorts the vector .
394
 
 
395
 
   If provided, ``p`` is an initial permutation.
396
 
 
397
 
.. function:: mergesort_perm!(v[,p[,lo,hi]])
398
 
 
399
 
   Sort a vector in ascending order in-place, also constructing the
400
 
   permutation that sorts the vector 
401
 
 
402
 
   If provided, ``p`` is an initial permutation.
403
 
 
404
 
.. function:: mergesort_perm!(lessthan,v[,p[,lo,hi]])
405
 
 
406
 
   Sort a vector in place, using a custom comparison function, also 
407
 
   constructing the permutation that sorts the vector .
408
 
 
409
 
   If provided, ``p`` is an initial permutation.
410
 
 
411
 
.. function:: mergesort_perm_r(v[,p,[,lo,hi]])
412
 
 
413
 
   Sort a vector in descending order, also constructing the
414
 
   permutation that sorts the vector 
415
 
 
416
 
   If provided, ``p`` is an initial permutation.
417
 
 
418
 
.. function:: mergesort_perm_r!(v[,p,[,lo,hi]])
419
 
 
420
 
   Sort a vector in descending order in place, also constructing the
421
 
   permutation that sorts the vector 
422
 
 
423
 
   If provided, ``p`` is an initial permutation.
424
 
 
425
 
.. function:: mergesort_perm_by(by,v[,p[,lo,hi]])
426
 
 
427
 
   Sort a vector with mergesort according to the result
428
 
   of function ``by`` applied to all values.
429
 
 
430
 
   If provided, ``p`` is an initial permutation.
431
 
 
432
 
.. function:: mergesort_perm_by!(by,v[,p[,lo,hi]])
433
 
 
434
 
   Sort a vector with mergesort in place according to the result 
435
 
   of function ``by`` applied to all values.
436
 
 
437
 
   If provided, ``p`` is an initial permutation.
438
 
 
439
 
 
440
 
.. function:: quicksort(v[,dim])
441
 
 
442
 
   Sort a vector in ascending order with quicksort, according to ``isless``.
443
 
 
444
 
.. function:: quicksort(lessthan,v[,dim])
445
 
 
446
 
   Sort a vector in ascending order with quicksort, using a
447
 
   custom comparison function.
448
 
 
449
 
.. function:: quicksort!(v[,dim])
450
 
.. function:: quicksort!(v[,lo,hi])
451
 
 
452
 
   In-place quicksort, accoring to ``isless``.
453
 
 
454
 
.. function:: quicksort!(lessthan,v[,dim])
455
 
.. function:: quicksort!(lessthan,v[,lo,hi])
456
 
 
457
 
   In-place quicksort with a custom comparison function.
458
 
 
459
 
.. function:: quicksort_r(v[,dim])
460
 
.. function:: quicksort_r(v[,lo,hi])
461
 
 
462
 
   Sort a vector in descending order using quicksort.
463
 
 
464
 
.. function:: quicksort_r!(v[,dim])
465
 
.. function:: quicksort_r!(v[,lo,hi])
466
 
 
467
 
   In-place quicksort in descending order.
468
 
 
469
 
.. function:: quicksort_by(by,v[,dim])
470
 
.. function:: quicksort_by(by,v[,lo,hi])
471
 
 
472
 
   Sort a vector with quicksort according to the result of
473
 
   function ``by`` applied to all values.
474
 
 
475
 
.. function:: quicksort_by!(by,v[,dim]) 
476
 
.. function:: quicksort_by!(by,v[,lo,hi]) 
477
 
 
478
 
   Sort a vector with quicksort in place according to the result
479
 
   of function ``by`` applied to all values.
 
196
.. function:: sortpermby(alg, ...) -> s,p
 
197
 
 
198
   ``sortpermby`` using a specific sorting algorithm
 
199
   (``InsertionSort``, ``QuickSort``, ``MergeSort``, or ``TimSort``).
 
200
 
 
201
.. function:: sortpermby!(...) -> s,p
 
202
 
 
203
   In-place ``sortpermby``.
480
204
 
481
205
-------------------------
482
206
Sorting-related Functions
486
210
 
487
211
   Test whether a vector is in ascending sorted order
488
212
 
489
 
.. function:: issorted_r(v)
 
213
.. function:: issortedr(v)
490
214
 
491
215
   Test whether a vector is in descending sorted order
492
216
 
493
 
.. function:: issorted_by(by,v)
494
 
 
495
 
   Test whether a vector is sorted by the result of function ``by``
496
 
   applied to all values of ``v``
497
 
 
498
 
.. function:: search_sorted(a, x[, lo, hi])
499
 
 
500
 
   For ``a`` sorted low to high, returns the index of the first value ``>=x``.
501
 
 
502
 
   ``lo`` and ``hi`` optionally limit the search range.
503
 
 
504
 
   Alias for ``search_sorted_first()``
505
 
 
506
 
.. function:: search_sorted(lt, a, x[, lo, hi])
507
 
 
508
 
   For ``a`` sorted using ordering function ``lt(x,y)``, returns the index of the first value equal to ``x`` or following ``x`` in the induced order
509
 
 
510
 
   ``lo`` and ``hi`` optionally limit the search range.
511
 
 
512
 
   Alias for ``search_sorted_first()``
513
 
 
514
 
.. function:: search_sorted_r(a, x[, lo, hi])
515
 
 
516
 
   For ``a`` sorted high to low, returns the index of the first value ``<=x``.
517
 
 
518
 
   ``lo`` and ``hi`` optionally limit the search range.
519
 
 
520
 
   Alias for ``search_sorted_first_r()``
521
 
 
522
 
.. function:: search_sorted_by(by, a, x[, lo, hi])
523
 
 
524
 
   For ``a`` sorted according to the natural order of ``by(x)`` for ``x`` in ``a``, returns the index of the first value equal to or following ``x`` in the induced order.
525
 
 
526
 
   ``lo`` and ``hi`` optionally limit the search range.
527
 
 
528
 
   Alias for ``search_sorted_first_by()``
529
 
 
530
 
.. function:: search_sorted_first(a, x[, lo, hi])
531
 
 
532
 
   For ``a`` sorted low to high, returns the index of the first occurance of ``x``, or if ``x`` is not in ``a``, the index of the first value following ``x`` in natural order.
533
 
 
534
 
   ``lo`` and ``hi`` optionally limit the search range.
535
 
 
536
 
.. function:: search_sorted_first(lt, a, x[, lo, hi])
537
 
 
538
 
   For ``a`` sorted using ordering function ``lt(x,y)``, returns the index of the first occurance of ``x``, or if ``x`` is not in ``a``, the index of the first value following ``x`` in the induced order.
539
 
 
540
 
   ``lo`` and ``hi`` optionally limit the search range.
541
 
 
542
 
   Alias for ``search_sorted_first()``
543
 
 
544
 
.. function:: search_sorted_first_r(a, x[, lo, hi])
545
 
 
546
 
   For ``a`` sorted high to low, returns the index of the first occurance of ``x``, or if ``x`` is not in ``a``, the index of the first value following ``x`` in reverse natural order.
547
 
 
548
 
   ``lo`` and ``hi`` optionally limit the search range.
549
 
 
550
 
.. function:: search_sorted_first_by(by, a, x[, lo, hi])
551
 
 
552
 
   For ``a`` sorted according to the natural order of ``by(x)`` for ``x`` in ``a``, returns the index of the first occurance of ``x``, or if ``x`` is not in ``a``, the index of the first value following ``x`` in the induced order.
553
 
 
554
 
   ``lo`` and ``hi`` optionally limit the search range.
555
 
 
556
 
.. function:: search_sorted_last(a, x[, lo, hi])
557
 
 
558
 
   For ``a`` sorted low to high, returns the index of the last occurance of ``x``, or if ``x`` is not in ``a``, the index of the last value preceding ``x`` in natural order.
559
 
 
560
 
   ``lo`` and ``hi`` optionally limit the search range.
561
 
 
562
 
.. function:: search_sorted_last(lt, a, x[, lo, hi])
563
 
 
564
 
   For ``a`` sorted using ordering function ``lt(x,y)``, returns the index of the last occurance of``x``, or if ``x`` is not in ``a``, the index of the last value preceding ``x`` in the induced order.
565
 
 
566
 
   ``lo`` and ``hi`` optionally limit the search range.
567
 
 
568
 
   Alias for ``search_sorted_last()``
569
 
 
570
 
.. function:: search_sorted_last_r(a, x[, lo, hi])
571
 
 
572
 
   For ``a`` sorted high to low, returns the index of the last occurance of ``x``, or if ``x`` is not in ``a``, the index of the last value preceding ``x`` in reverse natural order.
573
 
 
574
 
   ``lo`` and ``hi`` optionally limit the search range.
575
 
 
576
 
.. function:: search_sorted_last_by(by, a, x[, lo, hi])
577
 
 
578
 
   For ``a`` sorted according to the natural order of ``by(x)`` for ``x`` in ``a``, returns the index of the last occurance of ``x``, or if ``x`` is not in ``a``, the index of the last value preceding ``x`` in the induced order.
 
217
.. function:: issortedby(by,v)
 
218
 
 
219
   Test whether a vector is sorted according to ``by(v)``.
 
220
 
 
221
.. function:: searchsorted(a, x[, lo, hi])
 
222
 
 
223
   For ``a`` sorted low to high, returns the index of the first value ``>=x``.
 
224
 
 
225
   ``lo`` and ``hi`` optionally limit the search range.
 
226
 
 
227
   Alias for ``searchsortedfirst()``
 
228
 
 
229
.. function:: searchsorted(lt, a, x[, lo, hi])
 
230
 
 
231
   For ``a`` sorted using ``lt(x,y)``, returns the index of the first value ``>=x`` according to the induced order
 
232
 
 
233
   ``lo`` and ``hi`` optionally limit the search range.
 
234
 
 
235
   Alias for ``searchsortedfirst()``
 
236
 
 
237
.. function:: searchsortedr(a, x[, lo, hi])
 
238
 
 
239
   For ``a`` sorted high to low, returns the index of the first value ``<=x``.
 
240
 
 
241
   ``lo`` and ``hi`` optionally limit the search range.
 
242
 
 
243
   Alias for ``searchsortedfirstr()``
 
244
 
 
245
.. function:: searchsortedby(by, a, x[, lo, hi])
 
246
 
 
247
   For ``a`` sorted according to ``by(a)``, returns the index of the first value ``>=x`` according to the induced order.
 
248
 
 
249
   ``lo`` and ``hi`` optionally limit the search range.
 
250
 
 
251
   Alias for ``searchsortedfirstby()``
 
252
 
 
253
.. function:: searchsortedfirst(a, x[, lo, hi])
 
254
 
 
255
   For ``a`` sorted low to high, returns the index of the first value ``>=x``.
 
256
 
 
257
   ``lo`` and ``hi`` optionally limit the search range.
 
258
 
 
259
.. function:: searchsortedfirst(lt, a, x[, lo, hi])
 
260
 
 
261
   For ``a`` sorted using ordering function ``lt(x,y)``, returns the index of the first value ``>=x`` according to the induced order.
 
262
 
 
263
   ``lo`` and ``hi`` optionally limit the search range.
 
264
 
 
265
   Alias for ``searchsortedfirst()``
 
266
 
 
267
.. function:: searchsortedfirstr(a, x[, lo, hi])
 
268
 
 
269
   For ``a`` sorted high to low, returns the index of the first value ``<=x``.
 
270
 
 
271
   ``lo`` and ``hi`` optionally limit the search range.
 
272
 
 
273
.. function:: searchsortedfirstby(by, a, x[, lo, hi])
 
274
 
 
275
   For ``a`` sorted according to ``by(a)``, returns the index of the first value ``>=x`` according to the induced order.
 
276
 
 
277
   ``lo`` and ``hi`` optionally limit the search range.
 
278
 
 
279
.. function:: searchsortedlast(a, x[, lo, hi])
 
280
 
 
281
   For ``a`` sorted low to high, returns the index of the last value ``<=x``.
 
282
 
 
283
   ``lo`` and ``hi`` optionally limit the search range.
 
284
 
 
285
.. function:: searchsortedlast(lt, a, x[, lo, hi])
 
286
 
 
287
   For ``a`` sorted low to high, returns the index of the last value ``<=x`` according to the induced order.
 
288
 
 
289
   ``lo`` and ``hi`` optionally limit the search range.
 
290
 
 
291
   Alias for ``searchsortedlast()``
 
292
 
 
293
.. function:: searchsortedlastr(a, x[, lo, hi])
 
294
 
 
295
   For ``a`` sorted high to low, returns the index of the last value ``>=x``.
 
296
 
 
297
   ``lo`` and ``hi`` optionally limit the search range.
 
298
 
 
299
.. function:: searchsortedlastby(by, a, x[, lo, hi])
 
300
 
 
301
   For ``a`` sorted according to ``by(a)``, returns the index of the last value ``<=x`` according to the induced order.
579
302
 
580
303
   ``lo`` and ``hi`` optionally limit the search range.
581
304
 
595
318
 
596
319
   Version of ``select`` which permutes the input vector in place.
597
320
 
598
 
.. function:: select_r(v, k)
 
321
.. function:: selectr(v, k)
599
322
 
600
323
   Find the element in position ``k`` in the reverse sorted vector ``v``, without sorting.
601
324
 
602
 
.. function:: select_r!(v, k)
603
 
 
604
 
   Version of ``select_r`` which permutes the input vector in place.
605
 
 
606
 
.. function:: select_by(by, v, k)
607
 
 
608
 
   Find the element in position ``k`` in the vector ``v`` as if sorted by sort_by, without sorting.
609
 
 
610
 
.. function:: select_by!(by, v, k)
611
 
 
612
 
   Version of ``select_by`` which permutes the input vector in place.
 
325
.. function:: selectr!(v, k)
 
326
 
 
327
   Version of ``selectr`` which permutes the input vector in place.
 
328
 
 
329
.. function:: selectby(by, v, k)
 
330
 
 
331
   Find the element in position ``k`` in the vector ``v`` as if sorted by sortby, without sorting.
 
332
 
 
333
.. function:: selectby!(by, v, k)
 
334
 
 
335
   Version of ``selectby`` which permutes the input vector in place.
613
336