|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/uds-releases/jasper/src/uds/util/radixSort.h#1 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef RADIX_SORT_H
|
|
Packit Service |
310c69 |
#define RADIX_SORT_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* The implementation uses one large object allocated on the heap. This
|
|
Packit Service |
310c69 |
* large object can be reused as many times as desired. There is no
|
|
Packit Service |
310c69 |
* further heap usage by the sorting.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
typedef struct radixSorter RadixSorter;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Reserve the heap storage needed by the radixSort routine. The amount of
|
|
Packit Service |
310c69 |
* heap space is logarithmically proportional to the number of keys.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param count The maximum number of keys to be sorted
|
|
Packit Service |
310c69 |
* @param sorter The RadixSorter object is returned here
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeRadixSorter(unsigned int count, RadixSorter **sorter)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Free the heap storage needed by the radixSort routine.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param sorter The RadixSorter object to free
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeRadixSorter(RadixSorter *sorter);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Sort pointers to fixed-length keys (arrays of bytes) using a radix sort.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* The sort implementation is unstable--relative ordering of equal keys is not
|
|
Packit Service |
310c69 |
* preserved. The implementation does not use any heap allocation.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] sorter the heap storage used by the sorting
|
|
Packit Service |
310c69 |
* @param keys the array of key pointers to sort (modified in place)
|
|
Packit Service |
310c69 |
* @param [in] count the number of keys
|
|
Packit Service |
310c69 |
* @param [in] length the length of every key, in bytes
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int radixSort(RadixSorter *sorter,
|
|
Packit Service |
310c69 |
const unsigned char *keys[],
|
|
Packit Service |
310c69 |
unsigned int count,
|
|
Packit Service |
310c69 |
unsigned short length)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* RADIX_SORT_H */
|