1
0
Fork 0
C_lib/docs/misc_algorithms/search/binary_search.h.ms

42 lines
1.4 KiB
Plaintext

.DA
.TL
binary_search.h
.AU
Wael Karram
.AB no
Documentation for binary_search.h
.AE
.AD
.LP
This header defines a generic binary search function. Using the prepoccessor variable BINARY_SEARCH_H used as an include guard.
.LP
These are the compile-time constants declared by this header:
.br
BINARY_SEARCH_COMPARISON_LARGER_THAN, returned by the comparison function when the result is \[char34]larger than\[char34], evaluates to 1.
.br
BINARY_SEARCH_COMPARISON_LESS_THAN, returned by the comparison function when the result is \[char34]less than\[char34], evaluates to -1.
.br
BINARY_SEARCH_INDEX_NOT_FOUND, returned when the value isn't found, evaluated to -1.
.LP
These are the function defitions and input arguments for this file.
.br
.I "int binary_search(void *array, void *value, int (*comparison_function)(const void*, const void*), const int length, size_t size);"
.br
.I "void *array" " is the array to search in - if NULL the function will quit."
.br
.I "void *value" " is the value to look for - if NULL the function will quit."
.br
.I "int (*comparison_function)(const void*, const void*)" " is the comparison function used, if larger than returns 1, if less than returns -1, otherwise returns 0. If NULL - the function will exhibit undefined behavior."
.br
.I "const int length" " is the length of the array, must be positive."
.br
.I "size_t size" " is the size of a single object/element in the array, must be positive."