1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
// Copyright (c) 2018 10X Genomics, Inc. All rights reserved.

// This file contains miscellaneous vector utilities.

use superslice::Ext;

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// DISTANCE BETWEEN TWO VECTORS
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// Return the number of positions at which two vectors of equal length differ.

pub fn distance<T: Eq>(x1: &[T], x2: &[T]) -> usize {
    assert_eq!(x1.len(), x2.len());
    let mut dist = 0;
    for i in 0..x1.len() {
        if x1[i] != x2[i] {
            dist += 1;
        }
    }
    dist
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// SORT A VECTOR
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// Reverse sort a vector.

pub fn reverse_sort<T: Ord>(x: &mut Vec<T>) {
    x.sort_by(|a, b| b.cmp(a));
}

// Unique sort a vector.

pub fn unique_sort<T: Ord>(x: &mut Vec<T>) {
    x.sort();
    x.dedup();
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// DOES VECTOR CONTAIN ANOTHER VECTOR
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// Test to see if a vector contains another vector at a given position.

pub fn contains_at<T: Eq>(s: &[T], t: &[T], p: usize) -> bool {
    if p + t.len() > s.len() {
        return false;
    }
    for i in 0..t.len() {
        if s[p + i] != t[i] {
            return false;
        }
    }
    true
}

// Determine if vector x contains vector y.

pub fn contains<T: Eq>(x: &[T], y: &[T]) -> bool {
    if y.len() > x.len() {
        return false;
    }
    for i in 0..=x.len() - y.len() {
        let mut matches = true;
        for j in 0..y.len() {
            if x[i + j] != y[j] {
                matches = false;
                break;
            }
        }
        if matches {
            return true;
        }
    }
    false
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// UNSIGNED VECTOR SIZE AND SOME SPECIAL SIZES
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

pub trait VecUtils<'a> {
    fn ilen(&self) -> isize;

    fn solo(&self) -> bool;

    fn duo(&self) -> bool;
}

impl<'a, T> VecUtils<'a> for [T] {
    fn ilen(&self) -> isize {
        self.len() as isize
    }

    fn solo(&self) -> bool {
        self.len() == 1
    }

    fn duo(&self) -> bool {
        self.len() == 2
    }
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// ERASE GIVEN ELEMENTS OF A VECTOR
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// Erase elements in a vector that are flagged by another vector.  Both vectors
// must have the same length.

pub fn erase_if<T>(x: &mut Vec<T>, to_delete: &[bool]) {
    let mut count = 0;
    for (j, &delete) in to_delete.iter().take(x.len()).enumerate() {
        if !delete {
            if j != count {
                x.swap(j, count);
            }
            count += 1;
        }
    }
    x.truncate(count);
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// INTERSECTION FUNCTIONS
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// Determine if two sorted vectors have an element in common.

pub fn meet<T: Ord>(x: &[T], y: &[T]) -> bool {
    let mut i = 0;
    let mut j = 0;
    while i < x.len() && j < y.len() {
        if x[i] < y[j] {
            i += 1;
        } else if y[j] < x[i] {
            j += 1;
        } else {
            return true;
        }
    }
    false
}

// Find the intersection size of two sorted vectors.  If an element occurs
// repeatedly, say n1 times in one vector and n2 times in the other vector, then
// that contributes min(n1,n2) to the total.

pub fn meet_size<T: Ord>(x: &[T], y: &[T]) -> usize {
    let mut i = 0;
    let mut j = 0;
    let mut count = 0;
    while i < x.len() && j < y.len() {
        if x[i] < y[j] {
            i += 1;
        } else if y[j] < x[i] {
            j += 1;
        } else {
            count += 1;
            i += 1;
            j += 1;
        }
    }
    count
}

// Compute the intersection of two sorted vectors.

pub fn intersection<T: Ord + Clone>(x: &[T], y: &[T], z: &mut Vec<T>) {
    z.clear();
    let (mut ix, mut iy) = (0, 0);
    while ix < x.len() && iy < y.len() {
        if x[ix] < y[iy] {
            ix += 1;
        } else if y[iy] < x[ix] {
            iy += 1;
        } else {
            z.push(x[ix].clone());
            ix += 1;
            iy += 1;
        }
    }
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// FREQUENCY FUNCTIONS
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// Count elements in a sorted vector by type.  The output consists of a reverse
// sorted vector of pairs (m,v) where m is the multiplicity of an element v.

pub fn make_freq<T: Ord + Clone>(x: &[T], freq: &mut Vec<(u32, T)>) {
    freq.clear();
    let mut j = 0;
    loop {
        if j == x.len() {
            break;
        }
        let mut k = j + 1;
        loop {
            if k == x.len() || x[k] != x[j] {
                break;
            }
            k += 1;
        }
        let t = x[j].clone();
        freq.push(((k - j) as u32, t));
        j = k;
    }
    freq.sort_by(|a, b| b.cmp(a)); // freq.reverse_sort();
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// MEMBERSHIP
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// Test to see if a sorted vector contains a given element.

pub fn bin_member<T: Ord>(x: &[T], d: &T) -> bool {
    x.binary_search(d).is_ok()
}

// Return the position of an element in an unsorted vector.
// Returns -1 if not present.

pub fn position<T: Ord>(x: &[T], d: &T) -> i32 {
    for (i, y) in x.iter().enumerate() {
        if y == d {
            return i as i32;
        }
    }
    -1_i32
}

// Return the position of an element in a sorted vector, or using just the first
// position.  Returns -1 if not present.

pub fn bin_position<T: Ord>(x: &[T], d: &T) -> i32 {
    match x.binary_search(d) {
        Ok(p) => p as i32,
        Err(_e) => -1,
    }
}

pub fn bin_position1_2<S: Ord, T: Ord>(x: &[(S, T)], d: &S) -> i32 {
    match x.binary_search_by_key(&d, |&(ref a, ref _b)| a) {
        Ok(p) => p as i32,
        Err(_e) => -1,
    }
}

pub fn bin_position1_3<S: Ord, T: Ord, U: Ord>(x: &[(S, T, U)], d: &S) -> i32 {
    match x.binary_search_by_key(&d, |&(ref a, ref _b, ref _c)| a) {
        Ok(p) => p as i32,
        Err(_e) => -1,
    }
}

pub fn bin_position1_4<S: Ord, T: Ord, U: Ord, V: Ord>(x: &[(S, T, U, V)], d: &S) -> i32 {
    match x.binary_search_by_key(&d, |&(ref a, ref _b, ref _c, ref _d)| a) {
        Ok(p) => p as i32,
        Err(_e) => -1,
    }
}

pub fn bin_position1_5<S: Ord, T: Ord, U: Ord, V: Ord, W: Ord>(
    x: &[(S, T, U, V, W)],
    d: &S,
) -> i32 {
    match x.binary_search_by_key(&d, |&(ref a, ref _b, ref _c, ref _d, ref _e)| a) {
        Ok(p) => p as i32,
        Err(_e) => -1,
    }
}

// Find lower/upper bounds.

pub fn lower_bound<T: Ord>(x: &[T], d: &T) -> i64 {
    x.lower_bound(d) as i64
}

pub fn upper_bound<T: Ord>(x: &[T], d: &T) -> i64 {
    x.upper_bound(d) as i64
}

pub fn lower_bound1_2<S: Ord, T: Ord>(x: &[(S, T)], d: &S) -> i64 {
    x.lower_bound_by_key(&d, |(a, _b)| a) as i64
}

pub fn upper_bound1_2<S: Ord, T: Ord>(x: &[(S, T)], d: &S) -> i64 {
    x.upper_bound_by_key(&d, |(a, _b)| a) as i64
}

pub fn lower_bound1_3<S: Ord, T: Ord, U: Ord>(x: &[(S, T, U)], d: &S) -> i64 {
    x.lower_bound_by_key(&d, |(a, _b, _c)| a) as i64
}

pub fn upper_bound1_3<S: Ord, T: Ord, U: Ord>(x: &[(S, T, U)], d: &S) -> i64 {
    x.upper_bound_by_key(&d, |(a, _b, _c)| a) as i64
}

// Compute the number of instances of a given element in a sorted vector.

pub fn count_instances<T: Ord>(x: &[T], d: &T) -> i32 {
    (x.upper_bound(d) - x.lower_bound(d)) as i32
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// NEXT DIFFERENCE
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// Find first element that's different in a sorted vector, or different in
// first position.

pub fn next_diff<T: Eq>(x: &[T], i: usize) -> usize {
    let mut j = i + 1;
    loop {
        if j == x.len() || x[j] != x[i] {
            return j;
        }
        j += 1;
    }
}

pub fn next_diff1_2<T: Eq, U: Eq>(x: &[(T, U)], i: i32) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32 || x[j as usize].0 != x[i as usize].0 {
            return j;
        }
        j += 1;
    }
}

pub fn next_diff1_3<T: Eq, U: Eq, V: Eq>(x: &[(T, U, V)], i: i32) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32 || x[j as usize].0 != x[i as usize].0 {
            return j;
        }
        j += 1;
    }
}

pub fn next_diff1_4<T: Eq, U: Eq, V: Eq, W: Eq>(x: &[(T, U, V, W)], i: i32) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32 || x[j as usize].0 != x[i as usize].0 {
            return j;
        }
        j += 1;
    }
}

pub fn next_diff12_3<T: Eq, U: Eq, V: Eq>(x: &[(T, U, V)], i: i32) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32
            || x[j as usize].0 != x[i as usize].0
            || x[j as usize].1 != x[i as usize].1
        {
            return j;
        }
        j += 1;
    }
}

pub fn next_diff12_4<T: Eq, U: Eq, V: Eq, W: Eq>(x: &[(T, U, V, W)], i: i32) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32
            || x[j as usize].0 != x[i as usize].0
            || x[j as usize].1 != x[i as usize].1
        {
            return j;
        }
        j += 1;
    }
}

#[allow(clippy::type_complexity)]
pub fn next_diff12_8<S: Eq, T: Eq, U: Eq, V: Eq, W: Eq, X: Eq, Y: Eq, Z: Eq>(
    x: &[(S, T, U, V, W, X, Y, Z)],
    i: i32,
) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32
            || x[j as usize].0 != x[i as usize].0
            || x[j as usize].1 != x[i as usize].1
        {
            return j;
        }
        j += 1;
    }
}

pub fn next_diff1_5<T: Eq, U: Eq, V: Eq, W: Eq, X: Eq>(x: &[(T, U, V, W, X)], i: i32) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32 || x[j as usize].0 != x[i as usize].0 {
            return j;
        }
        j += 1;
    }
}

pub fn next_diff1_6<T: Eq, U: Eq, V: Eq, W: Eq, X: Eq, Y: Eq>(
    x: &[(T, U, V, W, X, Y)],
    i: i32,
) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32 || x[j as usize].0 != x[i as usize].0 {
            return j;
        }
        j += 1;
    }
}

pub fn next_diff1_7<T: Eq, U: Eq, V: Eq, W: Eq, X: Eq, Y: Eq, Z: Eq>(
    x: &[(T, U, V, W, X, Y, Z)],
    i: i32,
) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32 || x[j as usize].0 != x[i as usize].0 {
            return j;
        }
        j += 1;
    }
}

#[allow(clippy::type_complexity)]
pub fn next_diff1_8<S: Eq, T: Eq, U: Eq, V: Eq, W: Eq, X: Eq, Y: Eq, Z: Eq>(
    x: &[(S, T, U, V, W, X, Y, Z)],
    i: i32,
) -> i32 {
    let mut j: i32 = i + 1;
    loop {
        if j == x.len() as i32 || x[j as usize].0 != x[i as usize].0 {
            return j;
        }
        j += 1;
    }
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// RESIZE WITHOUT SETTING
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

// resize_without_setting: Resize a vector to the given size without initializing
// the entries.  Capacity is not reduced if it exceeds the given size.  This
// function is only 'safe' (meaning actually safe) if followed by code that sets all
// all the entries.  And this should only be used when the type is 'fixed width',
// e.g. not on Strings or Vecs.
//
// Panics if allocation fails.

pub unsafe fn resize_without_setting<T>(x: &mut Vec<T>, n: usize) {
    x.clear();
    x.reserve(n);
    x.set_len(n); /* unsafe */
}

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
// SORT SYNC VECTORS
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

pub fn sort_sync2<T: Ord + Clone, S1: Ord + Clone>(t: &mut Vec<T>, s1: &mut Vec<S1>) {
    let permutation = permutation::sort(&t[..]);
    *t = permutation.apply_slice(&t[..]);
    *s1 = permutation.apply_slice(&s1[..]);
}

pub fn sort_sync3<T: Ord + Clone, S1: Ord + Clone, S2: Ord + Clone>(
    t: &mut Vec<T>,
    s1: &mut Vec<S1>,
    s2: &mut Vec<S2>,
) {
    let permutation = permutation::sort(&t[..]);
    *t = permutation.apply_slice(&t[..]);
    *s1 = permutation.apply_slice(&s1[..]);
    *s2 = permutation.apply_slice(&s2[..]);
}

pub fn sort_sync4<T: Ord + Clone, S1: Ord + Clone, S2: Ord + Clone, S3: Ord + Clone>(
    t: &mut Vec<T>,
    s1: &mut Vec<S1>,
    s2: &mut Vec<S2>,
    s3: &mut Vec<S3>,
) {
    let permutation = permutation::sort(&t[..]);
    *t = permutation.apply_slice(&t[..]);
    *s1 = permutation.apply_slice(&s1[..]);
    *s2 = permutation.apply_slice(&s2[..]);
    *s3 = permutation.apply_slice(&s3[..]);
}

pub fn sort_sync5<
    T: Ord + Clone,
    S1: Ord + Clone,
    S2: Ord + Clone,
    S3: Ord + Clone,
    S4: Ord + Clone,
>(
    t: &mut Vec<T>,
    s1: &mut Vec<S1>,
    s2: &mut Vec<S2>,
    s3: &mut Vec<S3>,
    s4: &mut Vec<S4>,
) {
    let permutation = permutation::sort(&t[..]);
    *t = permutation.apply_slice(&t[..]);
    *s1 = permutation.apply_slice(&s1[..]);
    *s2 = permutation.apply_slice(&s2[..]);
    *s3 = permutation.apply_slice(&s3[..]);
    *s4 = permutation.apply_slice(&s4[..]);
}

pub fn sort_sync6<
    T: Ord + Clone,
    S1: Ord + Clone,
    S2: Ord + Clone,
    S3: Ord + Clone,
    S4: Ord + Clone,
    S5: Ord + Clone,
>(
    t: &mut Vec<T>,
    s1: &mut Vec<S1>,
    s2: &mut Vec<S2>,
    s3: &mut Vec<S3>,
    s4: &mut Vec<S4>,
    s5: &mut Vec<S5>,
) {
    let permutation = permutation::sort(&t[..]);
    *t = permutation.apply_slice(&t[..]);
    *s1 = permutation.apply_slice(&s1[..]);
    *s2 = permutation.apply_slice(&s2[..]);
    *s3 = permutation.apply_slice(&s3[..]);
    *s4 = permutation.apply_slice(&s4[..]);
    *s5 = permutation.apply_slice(&s5[..]);
}

pub fn sort_sync7<
    T: Ord + Clone,
    S1: Ord + Clone,
    S2: Ord + Clone,
    S3: Ord + Clone,
    S4: Ord + Clone,
    S5: Ord + Clone,
    S6: Ord + Clone,
>(
    t: &mut Vec<T>,
    s1: &mut Vec<S1>,
    s2: &mut Vec<S2>,
    s3: &mut Vec<S3>,
    s4: &mut Vec<S4>,
    s5: &mut Vec<S5>,
    s6: &mut Vec<S6>,
) {
    let permutation = permutation::sort(&t[..]);
    *t = permutation.apply_slice(&t[..]);
    *s1 = permutation.apply_slice(&s1[..]);
    *s2 = permutation.apply_slice(&s2[..]);
    *s3 = permutation.apply_slice(&s3[..]);
    *s4 = permutation.apply_slice(&s4[..]);
    *s5 = permutation.apply_slice(&s5[..]);
    *s6 = permutation.apply_slice(&s6[..]);
}