SDDSlib
|
Useful routines for sorting, compatible with qsort() More...
Go to the source code of this file.
Functions | |
int | double_cmpasc (const void *a, const void *b) |
Compare two doubles in ascending order. | |
int | double_abs_cmpasc (const void *a, const void *b) |
Compare the absolute values of two doubles in ascending order. | |
int | double_cmpdes (const void *a, const void *b) |
Compare two doubles in descending order. | |
int | double_abs_cmpdes (const void *a, const void *b) |
Compare the absolute values of two doubles in descending order. | |
void | double_copy (void *a, void *b) |
int | float_cmpasc (const void *a, const void *b) |
int | float_abs_cmpasc (const void *a, const void *b) |
int | float_cmpdes (const void *a, const void *b) |
int | float_abs_cmpdes (const void *a, const void *b) |
void | float_copy (void *a, void *b) |
int | long_cmpasc (const void *a, const void *b) |
Compare two long integers in ascending order. | |
int | long_abs_cmpasc (const void *a, const void *b) |
Compare the absolute values of two long integers in ascending order. | |
int | long_cmpdes (const void *a, const void *b) |
int | long_abs_cmpdes (const void *a, const void *b) |
void | long_copy (void *a, void *b) |
int | string_cmpasc (const void *a, const void *b) |
Compare two strings in ascending order. | |
int | string_cmpdes (const void *a, const void *b) |
void | string_copy (void *a, void *b) |
Copy a string value. | |
int | unique (void *base, size_t n_items, size_t size, int(*compare)(const void *a, const void *b), void(*copy)(void *a, void *b)) |
Remove duplicate elements from a sorted array. | |
void | set_up_row_sort (int sort_by_column, size_t n_columns, size_t element_size, int(*compare)(const void *a, const void *b)) |
Set up parameters for row-based sorting. | |
int | row_compare (const void *av, const void *bv) |
Compare two rows based on the previously set sorting parameters. | |
void | row_copy (void *av, void *bv) |
int | CompareStringKeyedIndex (const void *ki1, const void *ki2) |
Compare two KEYED_INDEX structures based on string keys. | |
int | CompareDoubleKeyedIndex (const void *ki1, const void *ki2) |
Compare two KEYED_INDEX structures based on double keys. | |
int | CompareStringKeyedGroup (const void *kg1, const void *kg2) |
Compare two KEYED_EQUIVALENT groups based on string keys. | |
int | CompareDoubleKeyedGroup (const void *kg1, const void *kg2) |
Compare two KEYED_EQUIVALENT groups based on double keys. | |
KEYED_EQUIVALENT ** | MakeSortedKeyGroups (long *keyGroups, long keyType, void *data, long points) |
Create sorted key groups from data. | |
long | FindMatchingKeyGroup (KEYED_EQUIVALENT **keyGroup, long keyGroups, long keyType, void *searchKeyData, long reuse) |
Find a matching key group for a search key. | |
long * | sort_and_return_index (void *data, long type, long rows, long increaseOrder) |
Sort data and return the sorted index. | |
int | strcmp_skip (const char *s1, const char *s2, const char *skip) |
Compare two strings while skipping specified characters. | |
Variables | |
static int(* | item_compare )(const void *a, const void *b) |
static int | column_to_compare |
static int | size_of_element |
static int | number_of_columns |
static long | orderIndices |
Useful routines for sorting, compatible with qsort()
Definition in file sortfunctions.c.
int CompareDoubleKeyedGroup | ( | const void * | kg1, |
const void * | kg2 ) |
Compare two KEYED_EQUIVALENT groups based on double keys.
This function compares the first double key of two KEYED_EQUIVALENT
groups.
kg1 | Pointer to the first KEYED_EQUIVALENT group. |
kg2 | Pointer to the second KEYED_EQUIVALENT group. |
Definition at line 345 of file sortfunctions.c.
int CompareDoubleKeyedIndex | ( | const void * | ki1, |
const void * | ki2 ) |
Compare two KEYED_INDEX structures based on double keys.
This function compares two KEYED_INDEX
structures using their doubleKey
fields. If the double keys are identical and orderIndices
is set, it compares based on rowIndex
.
ki1 | Pointer to the first KEYED_INDEX. |
ki2 | Pointer to the second KEYED_INDEX. |
rowIndex
if keys are equal. Definition at line 311 of file sortfunctions.c.
int CompareStringKeyedGroup | ( | const void * | kg1, |
const void * | kg2 ) |
Compare two KEYED_EQUIVALENT groups based on string keys.
This function compares the first string key of two KEYED_EQUIVALENT
groups.
kg1 | Pointer to the first KEYED_EQUIVALENT group. |
kg2 | Pointer to the second KEYED_EQUIVALENT group. |
strcmp
on the first string keys. Definition at line 332 of file sortfunctions.c.
int CompareStringKeyedIndex | ( | const void * | ki1, |
const void * | ki2 ) |
Compare two KEYED_INDEX structures based on string keys.
This function compares two KEYED_INDEX
structures using their stringKey
fields. If the string keys are identical and orderIndices
is set, it compares based on rowIndex
.
ki1 | Pointer to the first KEYED_INDEX. |
ki2 | Pointer to the second KEYED_INDEX. |
rowIndex
if keys are equal. Definition at line 292 of file sortfunctions.c.
int double_abs_cmpasc | ( | const void * | a, |
const void * | b ) |
Compare the absolute values of two doubles in ascending order.
This function compares the absolute values of two double values pointed to by a
and b
.
a | Pointer to the first double. |
b | Pointer to the second double. |
Definition at line 43 of file sortfunctions.c.
int double_abs_cmpdes | ( | const void * | a, |
const void * | b ) |
Compare the absolute values of two doubles in descending order.
This function compares the absolute values of two double values pointed to by a
and b
in descending order.
a | Pointer to the first double. |
b | Pointer to the second double. |
Definition at line 75 of file sortfunctions.c.
int double_cmpasc | ( | const void * | a, |
const void * | b ) |
Compare two doubles in ascending order.
This function compares two double values pointed to by a
and b
.
a | Pointer to the first double. |
b | Pointer to the second double. |
Definition at line 27 of file sortfunctions.c.
int double_cmpdes | ( | const void * | a, |
const void * | b ) |
Compare two doubles in descending order.
This function compares two double values pointed to by a
and b
in descending order.
a | Pointer to the first double. |
b | Pointer to the second double. |
Definition at line 59 of file sortfunctions.c.
void double_copy | ( | void * | a, |
void * | b ) |
Definition at line 82 of file sortfunctions.c.
long FindMatchingKeyGroup | ( | KEYED_EQUIVALENT ** | keyGroup, |
long | keyGroups, | ||
long | keyType, | ||
void * | searchKeyData, | ||
long | reuse ) |
Find a matching key group for a search key.
This function searches for a key group that matches the provided search key.
keyGroup | Array of key groups. |
keyGroups | Number of key groups. |
keyType | The type of key (e.g., SDDS_STRING or SDDS_DOUBLE). |
searchKeyData | Pointer to the search key data. |
reuse | Flag indicating whether to allow reuse of key groups. |
Definition at line 448 of file sortfunctions.c.
int float_abs_cmpasc | ( | const void * | a, |
const void * | b ) |
Definition at line 94 of file sortfunctions.c.
int float_abs_cmpdes | ( | const void * | a, |
const void * | b ) |
Definition at line 108 of file sortfunctions.c.
int float_cmpasc | ( | const void * | a, |
const void * | b ) |
Definition at line 87 of file sortfunctions.c.
int float_cmpdes | ( | const void * | a, |
const void * | b ) |
Definition at line 101 of file sortfunctions.c.
void float_copy | ( | void * | a, |
void * | b ) |
Definition at line 115 of file sortfunctions.c.
int long_abs_cmpasc | ( | const void * | a, |
const void * | b ) |
Compare the absolute values of two long integers in ascending order.
This function compares the absolute values of two int32_t
values pointed to by a
and b
.
a | Pointer to the first long integer. |
b | Pointer to the second long integer. |
Definition at line 143 of file sortfunctions.c.
int long_abs_cmpdes | ( | const void * | a, |
const void * | b ) |
Definition at line 155 of file sortfunctions.c.
int long_cmpasc | ( | const void * | a, |
const void * | b ) |
Compare two long integers in ascending order.
This function compares two int32_t
values pointed to by a
and b
.
a | Pointer to the first long integer. |
b | Pointer to the second long integer. |
Definition at line 128 of file sortfunctions.c.
int long_cmpdes | ( | const void * | a, |
const void * | b ) |
Definition at line 149 of file sortfunctions.c.
void long_copy | ( | void * | a, |
void * | b ) |
Definition at line 161 of file sortfunctions.c.
KEYED_EQUIVALENT ** MakeSortedKeyGroups | ( | long * | keyGroups, |
long | keyType, | ||
void * | data, | ||
long | points ) |
Create sorted key groups from data.
This function generates sorted groups of keys from the provided data based on the specified key type.
keyGroups | Pointer to store the number of key groups created. |
keyType | The type of key (e.g., SDDS_STRING or SDDS_DOUBLE). |
data | Pointer to the data to be grouped. |
points | Number of data points. |
KEYED_EQUIVALENT
structures. Definition at line 366 of file sortfunctions.c.
int row_compare | ( | const void * | av, |
const void * | bv ) |
Compare two rows based on the previously set sorting parameters.
This static function is used internally to compare two rows during sorting.
av | Pointer to the first row. |
bv | Pointer to the second row. |
Definition at line 262 of file sortfunctions.c.
void row_copy | ( | void * | av, |
void * | bv ) |
Definition at line 270 of file sortfunctions.c.
void set_up_row_sort | ( | int | sort_by_column, |
size_t | n_columns, | ||
size_t | element_size, | ||
int(* | compare )(const void *a, const void *b) ) |
Set up parameters for row-based sorting.
This function initializes the sorting parameters for sorting 2D data by rows based on a specified column.
sort_by_column | The column index to sort by. |
n_columns | Total number of columns. |
element_size | Size of each element in a row. |
compare | Function pointer to the comparison function. |
Definition at line 241 of file sortfunctions.c.
long * sort_and_return_index | ( | void * | data, |
long | type, | ||
long | rows, | ||
long | increaseOrder ) |
Sort data and return the sorted index.
This function sorts the provided data based on the specified type and order, and returns an array of indices representing the sorted order.
data | Pointer to the data to be sorted. |
type | The data type (e.g., SDDS_STRING, SDDS_DOUBLE). |
rows | Number of rows in the data. |
increaseOrder | If non-zero, sort in increasing order; otherwise, sort in decreasing order. |
Definition at line 486 of file sortfunctions.c.
int strcmp_skip | ( | const char * | s1, |
const char * | s2, | ||
const char * | skip ) |
Compare two strings while skipping specified characters.
This function compares two null-terminated strings s1
and s2
, ignoring any characters found in the skip
string.
s1 | Pointer to the first string. |
s2 | Pointer to the second string. |
skip | String containing characters to be skipped during comparison. |
s1
< s2
, a positive value if s1
> s2
, and 0 if equal. Definition at line 611 of file sortfunctions.c.
int string_cmpasc | ( | const void * | a, |
const void * | b ) |
Compare two strings in ascending order.
This function compares two null-terminated strings pointed to by a
and b
using strcmp
.
a | Pointer to the first string. |
b | Pointer to the second string. |
Definition at line 174 of file sortfunctions.c.
int string_cmpdes | ( | const void * | a, |
const void * | b ) |
Definition at line 178 of file sortfunctions.c.
void string_copy | ( | void * | a, |
void * | b ) |
Copy a string value.
This function copies the string from the source pointed to by b
to the destination pointed to by a
. If the destination buffer is large enough, it uses strcpy_ss
; otherwise, it allocates memory using cp_str
.
a | Destination pointer where the string will be copied. |
b | Source pointer from where the string will be copied. |
Definition at line 191 of file sortfunctions.c.
int unique | ( | void * | base, |
size_t | n_items, | ||
size_t | size, | ||
int(* | compare )(const void *a, const void *b), | ||
void(* | copy )(void *a, void *b) ) |
Remove duplicate elements from a sorted array.
This function iterates through a sorted array and removes duplicate items based on the provided comparison function.
base | Pointer to the first element of the array. |
n_items | Number of items in the array. |
size | Size of each element in the array. |
compare | Function pointer to the comparison function. |
copy | Function pointer to the copy function. |
Definition at line 210 of file sortfunctions.c.
|
static |
Definition at line 227 of file sortfunctions.c.
|
static |
Definition at line 226 of file sortfunctions.c.
|
static |
Definition at line 229 of file sortfunctions.c.
|
static |
Definition at line 280 of file sortfunctions.c.
|
static |
Definition at line 228 of file sortfunctions.c.