# NAG CL Interfacem01esc (reorder_​vector)

Settings help

CL Name Style:

## 1Purpose

m01esc rearranges a vector of arbitrary type data objects into the order specified by a vector of indices.

## 2Specification

 #include
 void m01esc (Pointer vec, size_t n, size_t size, ptrdiff_t stride, size_t indices[], NagError *fail)
The function may be called by the names: m01esc, nag_sort_reorder_vector or nag_reorder_vector.

## 3Description

m01esc uses a variant of list merging as described by Knuth (1973). The function rearranges a set of $n$ data objects of arbitrary type, which are stored in an array at intervals of length stride, into the order specified by an array of indices.

## 4References

Knuth D E (1973) The Art of Computer Programming (Volume 3) (2nd Edition) Addison–Wesley

## 5Arguments

1: $\mathbf{vec}\left[{\mathbf{n}}\right]$Pointer  Input/Output
On entry: the array of objects to be rearranged.
On exit: the objects rearranged according to array indices.
2: $\mathbf{n}$size_t Input
On entry: the number, $n$, of objects to be rearranged.
Constraint: $0\le {\mathbf{n}}\le \mathrm{MAX_LENGTH}$, where $\mathrm{MAX_LENGTH}$ is an implementation-dependent value for the maximum size of an array.
3: $\mathbf{size}$size_t Input
On entry: the size of each object to be rearranged.
Constraint: $1\le {\mathbf{size}}\le p$, where $p$ is an implementation-dependent value for the maximum size_t size on the system, divided by n if n is positive.
4: $\mathbf{stride}$ptrdiff_t Input
On entry: the increment between data items in vec to be rearranged.
Note: if stride is positive, vec should point at the first data object; otherwise vec should point at the last data object.
Constraint: ${\mathbf{size}}\le |{\mathbf{stride}}|\le p$, where $p$ is an implementation-dependent value for the maximum size_t size on the system, divided by n if n is positive.
5: $\mathbf{indices}\left[{\mathbf{n}}\right]$size_t Input
On entry: the indices specifying the order in which the elements of vector are to be rearranged.
6: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, $|{\mathbf{stride}}|=⟨\mathit{\text{value}}⟩$ while ${\mathbf{size}}=⟨\mathit{\text{value}}⟩$. These arguments must satisfy $|{\mathbf{stride}}|\ge {\mathbf{size}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
Invalid indices vector.
NE_INT_ARG_GT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\le ⟨\mathit{\text{value}}⟩$, an implementation-dependent size that is printed in the error message.
On entry, ${\mathbf{size}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{size}}\le ⟨\mathit{\text{value}}⟩$, an implementation-dependent size that is printed in the error message.
On entry, ${\mathbf{stride}}=⟨\mathit{\text{value}}⟩$.
Constraint: $|{\mathbf{stride}}|\le ⟨\mathit{\text{value}}⟩$, an implementation-dependent size that is printed in the error message.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{size}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{size}}\ge 1$.

Not applicable.

## 8Parallelism and Performance

m01esc is not threaded in any implementation.

The average time taken by the function is approximately proportional to n.

## 10Example

The example program.

### 10.1Program Text

Program Text (m01esce.c)

### 10.2Program Data

Program Data (m01esce.d)

### 10.3Program Results

Program Results (m01esce.r)