m01 Chapter Contents
m01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_reorder_vector (m01esc)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_reorder_vector (Pointer vec, size_t n, size_t size, ptrdiff_t stride, size_t indices[], NagError *fail)

## 3  Description

nag_reorder_vector (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.

## 4  References

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

## 5  Arguments

1:     vec[${\mathbf{n}}$]Pointer Input/Output
On entry: the array of objects to be rearranged.
On exit: the objects rearranged according to array indices.
2:     nsize_tInput
On entry: the number, $n$, of objects to be rearranged.
Constraint: ${\mathbf{n}}\ge 0$.
3:     sizesize_tInput
On entry: the size of each object to be rearranged.
Constraint: ${\mathbf{size}}\ge 1$.
4:     strideptrdiff_tInput
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: $\left|{\mathbf{stride}}\right|\ge {\mathbf{size}}$.
5:     indices[n]size_tInput
On entry: the indices specifying the order in which the elements of vector are to be rearranged.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, $\left|{\mathbf{stride}}\right|=〈\mathit{\text{value}}〉$ while ${\mathbf{size}}=〈\mathit{\text{value}}〉$. These arguments must satisfy $\left|{\mathbf{stride}}\right|\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}}〉$.
On entry, ${\mathbf{size}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{size}}\le 〈\mathit{\text{value}}〉$.
These arguments are limited to an implementation-dependent size which is printed in the error message.
On entry, $\left|{\mathbf{stride}}\right|$ must not be greater than $〈\mathit{\text{value}}〉$: $\left|{\mathbf{stride}}\right|=〈\mathit{\text{value}}〉$.
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.

## 8  Further Comments

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

## 9  Example

The example program.

### 9.1  Program Text

Program Text (m01esce.c)

### 9.2  Program Data

Program Data (m01esce.d)

### 9.3  Program Results

Program Results (m01esce.r)