Steve-
You can use SysBinarySearch to do this... but you have to build an array of char* to
the strings, as SysBinarySearch only supports FIXED-WIDTH elements. Fortunately, char*
is a 4-byte elem. and it's up to your COMPARE function to do the correct compare.
Here's some code where I do this.
// note. on OS 3.0, there is a bug in SysBinarySearch which will raise
illegal read/low mem read errors.
if (SysBinarySearch(gChooseDBFilter.dbNamesP, // array base. this is a
char** array which points to each string
gChooseDBFilter.dbsP->numDBs, //
number of elements in the aray
sizeof(*gChooseDBFilter.dbNamesP), //
data size
cmpC, // search
function
buf, // buffer to
search for
0, //
other data
&pos, // return index
true)) { // find first
matching
ListPtr listP = (ListPtr) GetObjectPtr(ChooseDBDBList);
LstSetSelection(listP, pos);
LstMakeItemVisible(listP, pos);
}
static Int cmpC(const void * lookFor, const void * elem, Long other)
{
char** listName = (char**) elem;
return StrNCaselessCompare( ((char*) lookFor), ((char*) *listName), 1);
}
Enjoy!
Alan
>I'd like to be able to use SysBinarySearch to search strings which are stored as an
>array of pointers to a set of variable-length strings to minimize storage space.
>
>-- The width parameter is defined in the docs as "width of an element comparison
>function". What the heck does that mean? I suspect it's supposed to mean the width of
>an element, implying that SysBinarySearch only works correctly with fixed length
>elements.
>
>-- Is this true, or can you use SysBinarySearch to search a set of variable-length
>strings by, perhaps, defining the width as the width of a pointer so it knows how to
>move thru the array, and you deal with the variable-length aspect in your comparison
>function.
>
>Any info from anyone who's used this routine would be welcome. It seems that none of
>the 3.5 sample code has any uses of SysBinarySearch, and there's nothing in the
>Knowledge base other than what's in the docs. Thanks.
>
>Regards,
>Steve Mann
>-------------------------------------------
>Creative Digital Publishing Inc.
>1315 Palm Street, San Luis Obispo, CA 93401-3117
>-------------------------------------------
>805.784.9461 805.784.9462 (fax)
>[EMAIL PROTECTED] http://www.cdpubs.com
>
>--
>For information on using the Palm Developer Forums, or to unsubscribe, please see
>http://www.palm.com/devzone/mailinglists.html
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html