Home page.


This page contrasts the transpose_position and transpose_value functions. They swap two sets of elements within a permutation.

Function transpose_position is a wrapper for std::swap_ranges.

The examples rely on this definition:
    permu_arr_0<13> const q {4, 8, 6, 5, 12, 3, 7, 11, 1, 2, 10, 0, 9};
void transpose_position
(int const i, int const j, int const k = 1);
  • i is the first position of one swap region;
  • j is the first position of the other swap region;
  • k is how many elements are in each swap region.
The two regions may not overlap.
void transpose_value
(int const i, int const j, int const k = 1);
  • i is the lowest value of one swap range;
  • j is the lowest value of the other swap range;
  • k is how many elements are in each swap range.
The two ranges may not overlap.
Given these statements:
    permu_arr_0<13> p {q}; 
    p.transpose_position (7, 2, 3);
what happens is:
  • the elements at positions 7 and 2 are exchanged;
  • the elements at positions 8 and 3 are exchanged;
  • the elements at positions 9 and 4 are exchanged.

table 1 — zero-based transpose_position
position: 0123456789101112
original: 4865123711121009
(7, 2, 3): 4811123765121009

Given these statements:
    permu_arr_0<13> p {q}; 
    p.transpose_value (7, 2, 3);
what happens is:
  • elements 7 and 2 are exchanged;
  • elements 8 and 3 are exchanged;
  • elements 9 and 4 are exchanged.

table 2 — zero-based transpose_value
position: 0123456789101112
original: 4865123711121009
(7, 2, 3): 9365128211171004

equivalentequivalent
Given these statements:
    permu_arr_1<13> p {q}; 
    p.transpose_position (8, 3, 3);
the result is:
  • the elements at positions 8 and 3 are exchanged;
  • the elements at positions 9 and 4 are exchanged;
  • the elements at positions 10 and 5 are exchanged.

table 3 — one-based transpose_position
position: 12345678910111213
original: 59761348122311110
(8, 3, 3): 59122348761311110

Given these statements:
    permu_arr_1<13> p {q}; 
    p.transpose_value (8, 3, 3);
the result is:
  • elements 8 and 3 are exchanged;
  • elements 9 and 4 are exchanged;
  • elements 10 and 5 are exchanged.

table 4 — one-based transpose_value
position: 12345678910111213
original: 59761348122311110
(8, 3, 3): 10476139312281115

permu_vec_0 and permu_vec_1 work the same way.