]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/uarrsort.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2003-2013, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: uarrsort.h
12 * tab size: 8 (not used)
15 * created on: 2003aug04
16 * created by: Markus W. Scherer
18 * Internal function for sorting arrays.
21 #ifndef __UARRSORT_H__
22 #define __UARRSORT_H__
24 #include "unicode/utypes.h"
28 * Function type for comparing two items as part of sorting an array or similar.
29 * Callback function for uprv_sortArray().
31 * @param context Application-specific pointer, passed through by uprv_sortArray().
32 * @param left Pointer to the "left" item.
33 * @param right Pointer to the "right" item.
34 * @return 32-bit signed integer comparison result:
41 typedef int32_t U_CALLCONV
42 UComparator(const void *context
, const void *left
, const void *right
);
46 * Array sorting function.
47 * Uses a UComparator for comparing array items to each other, and simple
48 * memory copying to move items.
50 * @param array The array to be sorted.
51 * @param length The number of items in the array.
52 * @param itemSize The size in bytes of each array item.
53 * @param cmp UComparator function used to compare two items each.
54 * @param context Application-specific pointer, passed through to the UComparator.
55 * @param sortStable If true, a stable sorting algorithm must be used.
56 * @param pErrorCode ICU in/out UErrorCode parameter.
61 uprv_sortArray(void *array
, int32_t length
, int32_t itemSize
,
62 UComparator
*cmp
, const void *context
,
63 UBool sortStable
, UErrorCode
*pErrorCode
);
66 * Convenience UComparator implementation for uint16_t arrays.
69 U_CAPI
int32_t U_EXPORT2
70 uprv_uint16Comparator(const void *context
, const void *left
, const void *right
);
73 * Convenience UComparator implementation for int32_t arrays.
76 U_CAPI
int32_t U_EXPORT2
77 uprv_int32Comparator(const void *context
, const void *left
, const void *right
);
80 * Convenience UComparator implementation for uint32_t arrays.
83 U_CAPI
int32_t U_EXPORT2
84 uprv_uint32Comparator(const void *context
, const void *left
, const void *right
);
87 * Much like Java Collections.binarySearch(list, key, comparator).
89 * Except: Java documents "If the list contains multiple elements equal to
90 * the specified object, there is no guarantee which one will be found."
92 * This version here will return the largest index of any equal item,
93 * for use in stable sorting.
95 * @return the index>=0 where the item was found:
96 * the largest such index, if multiple, for stable sorting;
97 * or the index<0 for inserting the item at ~index in sorted order
99 U_CAPI
int32_t U_EXPORT2
100 uprv_stableBinarySearch(char *array
, int32_t length
, void *item
, int32_t itemSize
,
101 UComparator
*cmp
, const void *context
);