sort_link *sort_getmatch(sort_info *i, long post, long overlap, int value) { sort_link *ret; if (i->sortbegin == -1) sort_sort(i, i->lo, i->hi); /* * Now we reuse lo and hi */ post = max(0, min(i->size, post)); i->val = value + 32768; i->lo = max(0, post - overlap); /* absolute position */ i->hi = min(i->size, post + overlap); /* absolute position */ ret = i->head[i->val]; while (ret) { if (ipos(i, ret) < i->lo) { ret = ret->next; } else { if (ipos(i, ret) >= i->hi) ret = NULL; break; } } /* i->head[i->val]=ret; */ return (ret); }
sort_link_t * sort_getmatch(sort_info_t *i, long post, long overlap, int value) { sort_link_t *ret; /* If the vector hasn't been indexed yet, index it now. */ if (i->sortbegin==-1) sort_sort(i,i->lo,i->hi); /* Now we reuse lo and hi */ /* We'll only return samples within (overlap) samples of (post). * Clamp the boundaries to search to the boundaries of the array, * convert the signed sample to an unsigned offset, and store the * state so that future calls to sort_nextmatch do the right thing. * * Reusing lo and hi this way is awful. */ post=max(0,min(i->size,post)); i->val=value+32768; i->lo=max(0,post-overlap); /* absolute position */ i->hi=min(i->size,post+overlap); /* absolute position */ /* Walk through the linked list of samples with this value, until * we find the first one within the bounds specified. If there * aren't any, return NULL. */ ret=i->head[i->val]; while (ret) { /* ipos() calculates the offset (in terms of the original vector) * of this hit. */ if (ipos(i,ret)<i->lo) { ret=ret->next; } else { if (ipos(i,ret)>=i->hi) ret=NULL; break; } } /*i->head[i->val]=ret;*/ return(ret); }