2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 ANSI C function bsearch().
10 /*****************************************************************************
23 int (* comparefunction
)(const void *, const void *))
26 Search in a sorted array for an entry key.
29 key - Look for this key.
30 base - This is the address of the first element in the array
31 to be searched. Note that the array *must* be sorted.
32 count - The number of elements in the array
33 size - The size of one element
34 comparefunction - The function which is called when two elements
35 must be compared. The function gets the addresses of two
36 elements of the array and must return 0 is both are equal,
37 < 0 if the first element is less than the second and > 0
41 A pointer to the element which equals key in the array or NULL if
42 no such element could be found.
54 ******************************************************************************/
56 char * base2
= (char *)base
;
62 /* Any elements to search ? */
67 /* Find the middle element between a and b */
70 /* Look if key is equal to this element */
71 if ((d
= (*comparefunction
)(key
, &base2
[size
* c
])) == 0)
72 return &base2
[size
* c
];
75 If the middle element equals the lower seach bounds, then
76 there are no more elements in the array which could be
77 searched (c wouldn't change anymore).
83 The middle element is not equal to the key. Is it smaller
84 or larger than the key ? If it's smaller, then c is our
85 new lower bounds, otherwise c is our new upper bounds.