SUMMARY:  INNER | FIELD | CONSTR | METHOD | FRIEND DETAIL:  FIELD | CONSTR | METHOD | FRIEND


Namespace Platform::Arrays

namespace Platform::Arrays

Provides operations for manipulating native C arrays (copying, searching, sorting etc).

Method Summarycollapse
template <typename Type>
Int
binarySearch(const Type* array, Int size, const Type& object)
          Searches an array for the specified element using the binary search algorithm which has worst case performance O(log n).
template <typename Type,
typename Comparator>
Int
binarySearch(const Type* array, Int size, const Type& object, Comparator compareFn)
          Searches an array for the specified element using the binary search algorithm which has worst case performance O(log n).
template <typename Type>
Void
copy(Type* destination, const Type* source, Int size)
          Copies elements from source array into destination array.
template <typename Type>
Void
copyBackward(Type* destination, const Type* source, Int size)
          Copies elements from source array into destination array in the reverse order.
template <typename Type>
Void
copyForward(Type* destination, const Type* source, Int size)
          Copies elements from source array into destination array.
Void fill(LatinChar* destination, LatinChar value, Int size)
          Fills the destination array with the specified value.
Void fill(Small* destination, Small value, Int size)
          Fills the destination array with the specified value.
template <typename Type>
Void
fill(Type* destination, const Type& value, Int size)
          Fills the destination array with the specified value.
Void fill(USmall* destination, USmall value, Int size)
          Fills the destination array with the specified value.
template <typename Type>
Int
findSubArray(const Type* source, Int sourceSize, const Type* target, Int targetSize, Int fromIndex)
          Finds the first occurance of the specified target array in the source array starting the search from the given offset.
template <typename Type,
typename EqualityTester>
Int
findSubArray(const Type* source, Int sourceSize, const Type* target, Int targetSize, Int fromIndex, EqualityTester equalFn)
          Finds the first occurance of the specified target array in the source array starting the search from the given offset using the specified equality tester function.
template <typename Type>
Int
indexOf(const Type* array, Int size, const Type& object, Int fromIndex)
          Finds the first occurance of the specified element in an array from the given offset.
template <typename Type,
typename EqualityTester>
Int
indexOf(const Type* array, Int size, const Type& object, Int fromIndex, EqualityTester equalFn)
          Finds the first occurance of the specified element in an array from the given offset using the specified equality tester function.
template <typename Type>
Bool
isSorted(const Type* array, Int size)
          Tests whether the elements in an array are ordered according to their natural ordering.
template <typename Type,
typename Comparator>
Bool
isSorted(const Type* array, Int size, Comparator compareFn)
          Tests whether the elements in an array are ordered according to their natural ordering using the specified comparator function.
template <typename Type>
Int
lastIndexOf(const Type* array, Int size, const Type& object, Int fromIndex)
          Finds the last occurance of the specified element in an array from the given offset.
template <typename Type,
typename EqualityTester>
Int
lastIndexOf(const Type* array, Int size, const Type& object, Int fromIndex, EqualityTester equalFn)
          Finds the last occurance of the specified element in an array from the given offset using the specified equality tester function.
template <typename Type>
Int
maxElement(const Type* array, Int size)
          Finds an element with the largest value in a given array.
template <typename Type,
typename Comparator>
Int
maxElement(const Type* array, Int size, Comparator compareFn)
          Finds an element with the largest value in a given array using the specified comparator function.
template <typename Type>
Int
minElement(const Type* array, Int size)
          Finds an element with the smallest value in a given array.
template <typename Type,
typename Comparator>
Int
minElement(const Type* array, Int size, Comparator compareFn)
          Finds an element with the smallest value in a given array using the specified comparator function.
template <typename Type>
Int
replace(Type* array, Int size, const Type& oldObject, const Type& newObject)
          Replaces every occurance of the element oldObject with newObject in a given array.
template <typename Type,
typename EqualityTester>
Int
replace(Type* array, Int size, const Type& oldObject, const Type& newObject, EqualityTester equalFn)
          Replaces every occurance of the element oldObject with newObject in a given array using the specified equality tester function.
template <typename Type>
Void
reverse(Type* array, Int size)
          Reverses the order of the elements in an array.
template <typename Type,
typename Exchanger>
Void
reverse(Type* array, Int size, Exchanger exchangeFn)
          Reverses the order of the elements in an array using the specified exchanger function.
template <typename Type>
Void
rotate(Type* array, Int size, Int distance)
          Rotates the elements in an array by distance amount left or right.
template <typename Type>
Void
shift(Type* array, Int size, Int distance)
          Shifts the elements in an array by distance amount left or right.
template <typename Type>
Void
sort(Type* array, Int size)
          Sorts the elements in an array according to their natural ordering.
template <typename Type,
typename Comparator>
Void
sort(Type* array, Int size, Comparator compareFn)
          Sorts the elements in an array according to their natural ordering using the specified comparator function.
template <typename Type,
typename Comparator,
typename Exchanger>
Void
sort(Type* array, Int size, Comparator compareFn, Exchanger exchangeFn)
          Sorts the elements in an array according to their natural ordering using the specified comparator and exchanger functions.
template <typename Type>
Void
swap(Type* arrayA, Type* arrayB, Int size)
          Swaps the contents of two arrays.
template <typename Type,
typename Exchanger>
Void
swap(Type* arrayA, Type* arrayB, Int size, Exchanger exchangeFn)
          Swaps the contents of two arrays using the specified exchange function.

 

Method Detail

binarySearch[inline]

template <typename Type>
Int binarySearch(const Type* array, Int size, const Type& object)

Searches an array for the specified element using the binary search algorithm which has worst case performance O(log n). The contents of the array must be ordered according to the natural ordering of its elements, otherwise the result of this method is undefined.

Parameters:
array - an array
size - the number of elements in the array
object - the element to look for
Returns:
the index (>= 0) of the element if found, otherwise (-(insertion point) - 1) which is the index where the element would be inserted
Preconditions:
the array must be sorted prior to using this method
See Also:
Array::sort, Array::isSorted, Lang::TypeActors::Comparator
http://en.wikipedia.org/wiki/Binary_search_algorithm

binarySearch[inline]

template <typename Type, typename Comparator>
Int binarySearch(const Type* array, Int size, const Type& object, Comparator compareFn)

Searches an array for the specified element using the binary search algorithm which has worst case performance O(log n). This method accepts a custom comparator function. The contents of the array must be ordered according to the natural ordering of its elements, otherwise the result of this method is undefined.

Parameters:
array - an array
size - the number of elements in the array
object - the element to look for
compareFn - comparator function
Returns:
the index (>= 0) of the element if found, otherwise (-(insertion point) - 1) which is the index where the element would be inserted
Preconditions:
the array must be sorted prior to using this method
See Also:
Array::sort, Array::isSorted, Lang::TypeActors::Comparator
http://en.wikipedia.org/wiki/Binary_search_algorithm

copy[inline]

template <typename Type>
Void copy(Type* destination, const Type* source, Int size)

Copies elements from source array into destination array. Source and destination arrays may overlap.

Parameters:
destination - the destination array
source - the source array
size - the number of elements to copy
See Also:
Mem::copy

copyBackward[inline]

template <typename Type>
Void copyBackward(Type* destination, const Type* source, Int size)

Copies elements from source array into destination array in the reverse order. Source and destination arrays may not overlap.

Parameters:
destination - the destination array
source - the source array
size - the number of elements to copy
See Also:
Mem::copyBackward

copyForward[inline]

template <typename Type>
Void copyForward(Type* destination, const Type* source, Int size)

Copies elements from source array into destination array. Source and destination arrays may not overlap.

Parameters:
destination - the destination array
source - the source array
size - the number of elements to copy
See Also:
Mem::copyForward

fill[nothrow, inline]

Void fill(LatinChar* destination, LatinChar value, Int size)

Fills the destination array with the specified value.

Parameters:
destination - an array
value - the value to fill with
size - the number of elements to fill
See Also:
Mem::fill

fill[nothrow, inline]

Void fill(Small* destination, Small value, Int size)

Fills the destination array with the specified value.

Parameters:
destination - an array
value - the value to fill with
size - the number of elements to fill
See Also:
Mem::fill

fill[inline]

template <typename Type>
Void fill(Type* destination, const Type& value, Int size)

Fills the destination array with the specified value.

Parameters:
destination - an array
value - the value to fill with
size - the number of elements to fill
See Also:
Mem::fill

fill[nothrow, inline]

Void fill(USmall* destination, USmall value, Int size)

Fills the destination array with the specified value.

Parameters:
destination - an array
value - the value to fill with
size - the number of elements to fill
See Also:
Mem::fill

findSubArray[inline]

template <typename Type>
Int findSubArray(const Type* source, Int sourceSize, const Type* target, Int targetSize, Int fromIndex)

Finds the first occurance of the specified target array in the source array starting the search from the given offset.

Parameters:
source - the source array
sourceSize - the number of elements in the source array
target - the array to find
targetSize - the number of elements in the target array
fromIndex - offset from the start of the array
Returns:
the index of the first occurance of target array in the source array or -1 if not found

findSubArray[inline]

template <typename Type, typename EqualityTester>
Int findSubArray(const Type* source, Int sourceSize, const Type* target, Int targetSize, Int fromIndex, EqualityTester equalFn)

Finds the first occurance of the specified target array in the source array starting the search from the given offset using the specified equality tester function.

Parameters:
source - the source array
sourceSize - the number of elements in the source array
target - the array to find
targetSize - the number of elements in the target array
fromIndex - offset from the start of the array
equalFn - equality tester function
Returns:
the index of the first occurance of target array in the source array or -1 if not found
See Also:
Lang::TypeActors::EqualityTester

indexOf[inline]

template <typename Type>
Int indexOf(const Type* array, Int size, const Type& object, Int fromIndex)

Finds the first occurance of the specified element in an array from the given offset.

Parameters:
array - an array
size - the number of elements in the array
object - the element to look for
fromIndex - offset from the start of the array
Returns:
the index of the first occurance of element object or -1 if not found

indexOf[inline]

template <typename Type, typename EqualityTester>
Int indexOf(const Type* array, Int size, const Type& object, Int fromIndex, EqualityTester equalFn)

Finds the first occurance of the specified element in an array from the given offset using the specified equality tester function.

Parameters:
array - an array
size - the number of elements in the array
object - the element to look for
fromIndex - offset from the start of the array
equalFn - equality tester function
Returns:
the index of the first occurance of element object or -1 if not found
See Also:
Lang::TypeActors::EqualityTester

isSorted[inline]

template <typename Type>
Bool isSorted(const Type* array, Int size)

Tests whether the elements in an array are ordered according to their natural ordering.

Parameters:
array - an array
size - the number of elements in the array
Returns:
True if the elements in an array are ordered according to their natural ordering, False otherwise
Preconditions:
the array must contain at least two elements
See Also:
Array::sort, Array::binarySearch, Lang::TypeActors::Comparator

isSorted[inline]

template <typename Type, typename Comparator>
Bool isSorted(const Type* array, Int size, Comparator compareFn)

Tests whether the elements in an array are ordered according to their natural ordering using the specified comparator function.

Parameters:
array - an array
size - the number of elements in the array
compareFn - comparator function
Returns:
True if the elements in an array are ordered according to their natural ordering, False otherwise
Preconditions:
the array must contain at least two elements
See Also:
Array::sort, Array::binarySearch, Lang::TypeActors::Comparator

lastIndexOf[inline]

template <typename Type>
Int lastIndexOf(const Type* array, Int size, const Type& object, Int fromIndex)

Finds the last occurance of the specified element in an array from the given offset.

Parameters:
array - an array
size - the number of elements in the array
object - the element to look for
fromIndex - offset from the end of the array
Returns:
the index of the last occurance of element object or -1 if not found

lastIndexOf[inline]

template <typename Type, typename EqualityTester>
Int lastIndexOf(const Type* array, Int size, const Type& object, Int fromIndex, EqualityTester equalFn)

Finds the last occurance of the specified element in an array from the given offset using the specified equality tester function.

Parameters:
array - an array
size - the number of elements in the array
object - the element to look for
fromIndex - offset from the end of the array
equalFn - equality tester function
Returns:
the index of the last occurance of element object or -1 if not found
See Also:
Lang::TypeActors::EqualityTester

maxElement[inline]

template <typename Type>
Int maxElement(const Type* array, Int size)

Finds an element with the largest value in a given array.

Parameters:
array - an array
size - the number of elements in the array
Returns:
the index of the element with the largest value
Preconditions:
the array must contain at least two elements

maxElement[inline]

template <typename Type, typename Comparator>
Int maxElement(const Type* array, Int size, Comparator compareFn)

Finds an element with the largest value in a given array using the specified comparator function.

Parameters:
array - an array
size - the number of elements in the array
compareFn - comparator function
Returns:
the index of the element with the largest value
Preconditions:
the array must contain at least two elements
See Also:
Lang::TypeActors::Comparator

minElement[inline]

template <typename Type>
Int minElement(const Type* array, Int size)

Finds an element with the smallest value in a given array.

Parameters:
array - an array
size - the number of elements in the array
Returns:
the index of the element with the smallest value
Preconditions:
the array must contain at least two elements

minElement[inline]

template <typename Type, typename Comparator>
Int minElement(const Type* array, Int size, Comparator compareFn)

Finds an element with the smallest value in a given array using the specified comparator function.

Parameters:
array - an array
size - the number of elements in the array
compareFn - comparator function
Returns:
the index of the element with the smallest value
Preconditions:
the array must contain at least two elements
See Also:
Lang::TypeActors::Comparator

replace[inline]

template <typename Type>
Int replace(Type* array, Int size, const Type& oldObject, const Type& newObject)

Replaces every occurance of the element oldObject with newObject in a given array.

Parameters:
array - an array
size - the number of elements in the array
oldObject - an element to replace
newObject - the replacement element
Returns:
the number of replaced elements

replace[inline]

template <typename Type, typename EqualityTester>
Int replace(Type* array, Int size, const Type& oldObject, const Type& newObject, EqualityTester equalFn)

Replaces every occurance of the element oldObject with newObject in a given array using the specified equality tester function.

Parameters:
array - an array
size - the number of elements in the array
oldObject - an element to replace
newObject - the replacement element
equalFn - equality tester function
Returns:
the number of replaced elements
See Also:
Lang::TypeActors::EqualityTester

reverse[inline]

template <typename Type>
Void reverse(Type* array, Int size)

Reverses the order of the elements in an array.

Parameters:
array - an array
size - the number of elements in the array

reverse[inline]

template <typename Type, typename Exchanger>
Void reverse(Type* array, Int size, Exchanger exchangeFn)

Reverses the order of the elements in an array using the specified exchanger function.

Parameters:
array - an array
size - the number of elements in the array
exchangeFn - exchanger function
See Also:
Lang::TypeActors::Exchanger

rotate[inline]

template <typename Type>
Void rotate(Type* array, Int size, Int distance)

Rotates the elements in an array by distance amount left or right.

Parameters:
array - an array
size - the number of elements in the array
distance - the distance by which to rotate the elements; positive value rotates right, negative left

shift[inline]

template <typename Type>
Void shift(Type* array, Int size, Int distance)

Shifts the elements in an array by distance amount left or right.

Parameters:
array - an array
size - the number of elements in the array
distance - the distance by which to shift the elements; positive value shifts right, negative left

sort[inline]

template <typename Type>
Void sort(Type* array, Int size)

Sorts the elements in an array according to their natural ordering. The sort algorithm is unstable.

Parameters:
array - an array
size - the number of elements in the array

sort[inline]

template <typename Type, typename Comparator>
Void sort(Type* array, Int size, Comparator compareFn)

Sorts the elements in an array according to their natural ordering using the specified comparator function. The sort algorithm is unstable.

Parameters:
array - an array
size - the number of elements in the array
compareFn - comparator function
See Also:
Lang::TypeActors::Comparator

sort[inline]

template <typename Type, typename Comparator, typename Exchanger>
Void sort(Type* array, Int size, Comparator compareFn, Exchanger exchangeFn)

Sorts the elements in an array according to their natural ordering using the specified comparator and exchanger functions. The sort algorithm is unstable.

Parameters:
array - an array
size - the number of elements in the array
compareFn - comparator function
exchangeFn - exchanger function
See Also:
Lang::TypeActors::Comparator, Lang::TypeActors::Exchanger

swap[inline]

template <typename Type>
Void swap(Type* arrayA, Type* arrayB, Int size)

Swaps the contents of two arrays.

Parameters:
arrayA - first array
arrayB - second array
size - the number of elements to swap
See Also:
Lang::TypeActors::Exchanger

swap[inline]

template <typename Type, typename Exchanger>
Void swap(Type* arrayA, Type* arrayB, Int size, Exchanger exchangeFn)

Swaps the contents of two arrays using the specified exchange function.

Parameters:
arrayA - first array
arrayB - second array
size - the number of elements to swap
exchangeFn - the exchange function
See Also:
Lang::TypeActors::Exchanger


SUMMARY:  INNER | FIELD | CONSTR | METHOD | FRIEND DETAIL:  FIELD | CONSTR | METHOD | FRIEND