13.3.2 Finding Items
It is often useful to be able to determine whether or not a List contains a particular item. The simplest function for
determining whether a particular item exists is XmListItemExists(), which takes the following form:
Boolean
XmListItemExists(list_w, item)
Widget list_w;
XmString item;
This function performs a linear search on the list for the specified item. If you are maintaining your list in a particular
order, you may want to search the list yourself using another type of search to improve performance. The List's
internal search function does not convert the compound strings to C strings. The search routine does a direct
byte−by−byte comparison of the strings using XmStringByteCompare(), which is much more efficient than
converting the compound strings to C strings for comparison. However, the linear search is still slower than a binary
search by orders of magnitude. And unfortunately, XmStringByteCompare() does not return which string is of
greater or lesser value. The routine just returns whether the strings are different, so we cannot use it to alphabetize the
items in a List.
If you need to know the position of an item in the List, you can use XmListItemPos(). This routine takes the
following form:
int
XmListItemPos(list_w, item)
Widget list_w;
XmString item;
This function returns the position of the first occurrence of item in the List, with 1 being the first position. If the
function returns 0, the element is not in the List. If a List contains duplicate entries, ...