NAME

int_binary_search - Finds an element in a sorted array

SYNOPSIS

#include "l/l_sort.h"

Example compile flags (system dependent):
  -DLINUX_X86_64 -DLINUX_X86_64_OPTERON  -DGNU_COMPILER 
   -I/home/kobus/include
   -L/home/kobus/misc/load/linux_x86_64_opteron -L/usr/lib/x86_64-linux-gnu
  -lKJB                               -lfftw3  -lgsl -lgslcblas -ljpeg  -lSVM -lstdc++                    -lpthread -lSLATEC -lg2c    -lacml -lacml_mv -lblas -lg2c      -lncursesw 


int int_binary_search
(
	const void *array,
	int num_elements,
	size_t element_size,
	size_t element_offset,
	int search_key
);

DESCRIPTION

This routine finds an element with integer key search_key in the sorted array "array" by binary search in the special case where the key is an integer. This routine avoids the call backs on the assumption that the key is an integer at offset key_pos (see offsetof()). This routine is barely legal ANSI-C and might fail on some bizzare system (but not anything common). The operation in question is whether:

       (int*)((void*)((char*)array + element_size*n + key_pos))

evaluates to a valid pointer to the n'th integer key, where key_pos is offsetof() the integer key, and element_size is sizeof(<element-type>). (I don't know of any systems where this is not the case). This routine is only meant to provide a faster search in this specialized case, so if you don't want to take a chance with the above then binary_search can be used.

RETURNS

On success, this routine returns an index into the array. If the element is not found, then it returns NOT_FOUND.

DISCLAIMER

This software is not adequatedly tested. It is recomended that results are checked independantly where appropriate.

AUTHOR

Kobus Barnard

DOCUMENTER

Kobus Barnard

SEE ALSO

kjb_sort , check_sort , int_sort , long_sort , binary_search , long_binary_search , binary_search_int_array , binary_search_long_array , linear_search , int_linear_search , long_linear_search , linear_search_int_array , linear_search_long_array