michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2003-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: uarrsort.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2003aug04 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * Internal function for sorting arrays. michael@0: */ michael@0: michael@0: #ifndef __UARRSORT_H__ michael@0: #define __UARRSORT_H__ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: U_CDECL_BEGIN michael@0: /** michael@0: * Function type for comparing two items as part of sorting an array or similar. michael@0: * Callback function for uprv_sortArray(). michael@0: * michael@0: * @param context Application-specific pointer, passed through by uprv_sortArray(). michael@0: * @param left Pointer to the "left" item. michael@0: * @param right Pointer to the "right" item. michael@0: * @return 32-bit signed integer comparison result: michael@0: * <0 if left0 if left>right michael@0: * michael@0: * @internal michael@0: */ michael@0: typedef int32_t U_CALLCONV michael@0: UComparator(const void *context, const void *left, const void *right); michael@0: U_CDECL_END michael@0: michael@0: /** michael@0: * Array sorting function. michael@0: * Uses a UComparator for comparing array items to each other, and simple michael@0: * memory copying to move items. michael@0: * michael@0: * @param array The array to be sorted. michael@0: * @param length The number of items in the array. michael@0: * @param itemSize The size in bytes of each array item. michael@0: * @param cmp UComparator function used to compare two items each. michael@0: * @param context Application-specific pointer, passed through to the UComparator. michael@0: * @param sortStable If true, a stable sorting algorithm must be used. michael@0: * @param pErrorCode ICU in/out UErrorCode parameter. michael@0: * michael@0: * @internal michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: uprv_sortArray(void *array, int32_t length, int32_t itemSize, michael@0: UComparator *cmp, const void *context, michael@0: UBool sortStable, UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Convenience UComparator implementation for uint16_t arrays. michael@0: * @internal michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uprv_uint16Comparator(const void *context, const void *left, const void *right); michael@0: michael@0: /** michael@0: * Convenience UComparator implementation for int32_t arrays. michael@0: * @internal michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uprv_int32Comparator(const void *context, const void *left, const void *right); michael@0: michael@0: /** michael@0: * Convenience UComparator implementation for uint32_t arrays. michael@0: * @internal michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uprv_uint32Comparator(const void *context, const void *left, const void *right); michael@0: michael@0: /** michael@0: * Much like Java Collections.binarySearch(list, key, comparator). michael@0: * michael@0: * Except: Java documents "If the list contains multiple elements equal to michael@0: * the specified object, there is no guarantee which one will be found." michael@0: * michael@0: * This version here will return the largest index of any equal item, michael@0: * for use in stable sorting. michael@0: * michael@0: * @return the index>=0 where the item was found: michael@0: * the largest such index, if multiple, for stable sorting; michael@0: * or the index<0 for inserting the item at ~index in sorted order michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uprv_stableBinarySearch(char *array, int32_t length, void *item, int32_t itemSize, michael@0: UComparator *cmp, const void *context); michael@0: michael@0: #endif