Getsortedbyindex
void *Getsortedbyindex(t_sorted *sd,int index);
Locates
index-th
item in the table of the sorted data
sorted by address.
Parameters:
sd
index
(in) 0-based index
of the item in the sorted data
Return
values:
On
success, returns pointer to the element of sorted data. On error,
returns NULL.
Example:
Here
is the slightly modified code of the API function Findthreadbyordinal().
// Searches for thread with specified ordinal (1 for main, incremented by 1 for
// each new thread). Returns pointer to thread descriptor, or NULL on error.
// Uses linear search, but usually very fast because number of threads is
// limited.
stdapi (t_thread *) Findthreadbyordinal(int ordinal) {
int i;
t_thread *pthr;
for (i=0; i<thread.sorted.n; i++) {
pthr=(t_thread *)Getsortedbyindex(&(thread.sorted),i);
if (pthr==NULL) continue;
if (pthr->ordinal==ordinal) return pthr; };
return
NULL;
// No thread with given ordinal
};
See
also: