Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 2003-2013, International Business Machines |
michael@0 | 5 | * Corporation and others. All Rights Reserved. |
michael@0 | 6 | * |
michael@0 | 7 | ******************************************************************************* |
michael@0 | 8 | * file name: uarrsort.h |
michael@0 | 9 | * encoding: US-ASCII |
michael@0 | 10 | * tab size: 8 (not used) |
michael@0 | 11 | * indentation:4 |
michael@0 | 12 | * |
michael@0 | 13 | * created on: 2003aug04 |
michael@0 | 14 | * created by: Markus W. Scherer |
michael@0 | 15 | * |
michael@0 | 16 | * Internal function for sorting arrays. |
michael@0 | 17 | */ |
michael@0 | 18 | |
michael@0 | 19 | #ifndef __UARRSORT_H__ |
michael@0 | 20 | #define __UARRSORT_H__ |
michael@0 | 21 | |
michael@0 | 22 | #include "unicode/utypes.h" |
michael@0 | 23 | |
michael@0 | 24 | U_CDECL_BEGIN |
michael@0 | 25 | /** |
michael@0 | 26 | * Function type for comparing two items as part of sorting an array or similar. |
michael@0 | 27 | * Callback function for uprv_sortArray(). |
michael@0 | 28 | * |
michael@0 | 29 | * @param context Application-specific pointer, passed through by uprv_sortArray(). |
michael@0 | 30 | * @param left Pointer to the "left" item. |
michael@0 | 31 | * @param right Pointer to the "right" item. |
michael@0 | 32 | * @return 32-bit signed integer comparison result: |
michael@0 | 33 | * <0 if left<right |
michael@0 | 34 | * ==0 if left==right |
michael@0 | 35 | * >0 if left>right |
michael@0 | 36 | * |
michael@0 | 37 | * @internal |
michael@0 | 38 | */ |
michael@0 | 39 | typedef int32_t U_CALLCONV |
michael@0 | 40 | UComparator(const void *context, const void *left, const void *right); |
michael@0 | 41 | U_CDECL_END |
michael@0 | 42 | |
michael@0 | 43 | /** |
michael@0 | 44 | * Array sorting function. |
michael@0 | 45 | * Uses a UComparator for comparing array items to each other, and simple |
michael@0 | 46 | * memory copying to move items. |
michael@0 | 47 | * |
michael@0 | 48 | * @param array The array to be sorted. |
michael@0 | 49 | * @param length The number of items in the array. |
michael@0 | 50 | * @param itemSize The size in bytes of each array item. |
michael@0 | 51 | * @param cmp UComparator function used to compare two items each. |
michael@0 | 52 | * @param context Application-specific pointer, passed through to the UComparator. |
michael@0 | 53 | * @param sortStable If true, a stable sorting algorithm must be used. |
michael@0 | 54 | * @param pErrorCode ICU in/out UErrorCode parameter. |
michael@0 | 55 | * |
michael@0 | 56 | * @internal |
michael@0 | 57 | */ |
michael@0 | 58 | U_CAPI void U_EXPORT2 |
michael@0 | 59 | uprv_sortArray(void *array, int32_t length, int32_t itemSize, |
michael@0 | 60 | UComparator *cmp, const void *context, |
michael@0 | 61 | UBool sortStable, UErrorCode *pErrorCode); |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * Convenience UComparator implementation for uint16_t arrays. |
michael@0 | 65 | * @internal |
michael@0 | 66 | */ |
michael@0 | 67 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 68 | uprv_uint16Comparator(const void *context, const void *left, const void *right); |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Convenience UComparator implementation for int32_t arrays. |
michael@0 | 72 | * @internal |
michael@0 | 73 | */ |
michael@0 | 74 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 75 | uprv_int32Comparator(const void *context, const void *left, const void *right); |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * Convenience UComparator implementation for uint32_t arrays. |
michael@0 | 79 | * @internal |
michael@0 | 80 | */ |
michael@0 | 81 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 82 | uprv_uint32Comparator(const void *context, const void *left, const void *right); |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * Much like Java Collections.binarySearch(list, key, comparator). |
michael@0 | 86 | * |
michael@0 | 87 | * Except: Java documents "If the list contains multiple elements equal to |
michael@0 | 88 | * the specified object, there is no guarantee which one will be found." |
michael@0 | 89 | * |
michael@0 | 90 | * This version here will return the largest index of any equal item, |
michael@0 | 91 | * for use in stable sorting. |
michael@0 | 92 | * |
michael@0 | 93 | * @return the index>=0 where the item was found: |
michael@0 | 94 | * the largest such index, if multiple, for stable sorting; |
michael@0 | 95 | * or the index<0 for inserting the item at ~index in sorted order |
michael@0 | 96 | */ |
michael@0 | 97 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 98 | uprv_stableBinarySearch(char *array, int32_t length, void *item, int32_t itemSize, |
michael@0 | 99 | UComparator *cmp, const void *context); |
michael@0 | 100 | |
michael@0 | 101 | #endif |