SDDS ToolKit Programs and Libraries for C and Python
|
Binary search and insertion functions.
This file provides implementations for binary search and insertion operations on arrays of pointers or data values.
Definition in file binsert.c.
#include "mdb.h"
Go to the source code of this file.
Functions | |
long | binaryInsert (void **array, long members, void *newMember, int(*compare)(const void *c1, const void *c2), int32_t *duplicate) |
Inserts a new member into a sorted array using binary search. | |
long | binaryIndexSearch (void **array, long members, void *key, int(*compare)(const void *c1, const void *c2), long bracket) |
Searches for a key in a sorted array of pointers using binary search. | |
long | binaryArraySearch (void *array, size_t elemSize, long members, void *key, int(*compare)(const void *c1, const void *c2), long bracket) |
Searches for a key in a sorted array of data values using binary search. | |
long binaryArraySearch | ( | void * | array, |
size_t | elemSize, | ||
long | members, | ||
void * | key, | ||
int(* | compare )(const void *c1, const void *c2), | ||
long | bracket ) |
Searches for a key in a sorted array of data values using binary search.
This function performs a binary search on an array of data values (not pointers) to find the index of the key. If the key is not found and the bracket flag is set, it returns the index of the nearest element less than or equal to the key.
array | Pointer to the array of data values. |
elemSize | The size of each element in the array. |
members | The number of members in the array. |
key | Pointer to the key to search for. |
compare | Comparison function that defines the order of the elements. |
bracket | If non-zero, returns the nearest index if the key is not found. |
Definition at line 156 of file binsert.c.
long binaryIndexSearch | ( | void ** | array, |
long | members, | ||
void * | key, | ||
int(* | compare )(const void *c1, const void *c2), | ||
long | bracket ) |
Searches for a key in a sorted array of pointers using binary search.
This function performs a binary search to find the index of the key in the array. If the key is not found and the bracket flag is set, it returns the index of the nearest element less than or equal to the key.
array | Pointer to the array of pointers to members. |
members | The number of members in the array. |
key | Pointer to the key to search for. |
compare | Comparison function that defines the order of the elements. |
bracket | If non-zero, returns the nearest index if the key is not found. |
Definition at line 98 of file binsert.c.
long binaryInsert | ( | void ** | array, |
long | members, | ||
void * | newMember, | ||
int(* | compare )(const void *c1, const void *c2), | ||
int32_t * | duplicate ) |
Inserts a new member into a sorted array using binary search.
This function performs a binary search to find the appropriate position for the new member in the sorted array. If a duplicate is found, it sets the duplicate flag and does not insert the new member.
array | Pointer to the array of pointers to members. |
members | The number of members currently in the array. |
newMember | Pointer to the new member to be inserted. |
compare | Comparison function that defines the order of the elements. |
duplicate | Pointer to an integer that is set to 1 if a duplicate is found. |
Definition at line 39 of file binsert.c.