static BL d_vlpk(OpParam &p,BL cmpf(S a,S b)) { I dpeaks = (I)(p.frames*p.peaks.density); if(dpeaks < 1) dpeaks = 1; I cnt; do { cnt = 0; I i; BS *rdst = p.rddt,*rsrc = p.rsdt; BS *idst = p.iddt,*isrc = p.isdt; if(!p.peaks.cx || !idst) idst = rdst,p.ids = p.rds; if(!p.peaks.cx || !isrc) isrc = rsrc,p.iss = p.rss; // preset sample values S d1 = -1,d0 = -1,dn = -1; // search first non-null sample _D_LOOP(i,p.frames) if((dn = sqabs(rsrc[i*p.rss],isrc[i*p.iss])) != 0) break; // non-null -> break! else rdst[i*p.rds] = idst[i*p.ids] = 0; // copy null samples to dst _E_LOOP // i points to first non-null sample _D_WHILE(i < p.frames) // current samples -> previous samples d1 = d0,d0 = dn; // save current index I ci = i; // search next non-null sample dn = -1; while(++i < p.frames) if((dn = sqabs(rsrc[i*p.rss],isrc[i*p.iss])) != 0) { break; // non-null -> break! } else rdst[i*p.rds] = idst[i*p.ids] = 0; if((d1 < 0 || cmpf(d0,d1)) && (dn < 0 || cmpf(d0,dn))) { // is peak/valley rdst[ci*p.rds] = rsrc[ci*p.rss]; idst[ci*p.ids] = isrc[ci*p.iss]; ++cnt; } else rdst[ci*p.rds] = idst[ci*p.ids] = 0; _E_WHILE } while(cnt > dpeaks); p.peaks.density = p.frames?(R)cnt/p.frames:(cnt?1:0); return true; }
/* retrieve an item from a bucket's list */ htitem_td *hashitem_get(htitem_td *list, void *key, size_t size, int(cmpf)(void*, void*, size_t)) { while(list->n != NULL) { if(cmpf(list->key, key, size) == 0) return list; list = list->n; } if(cmpf(list->key, key, size) == 0) return list; return NULL; }
//olyan él keresése, ahol az első ID megegyezik a megadottal unsigned int edges_findfirst(edges* e, uint32_t p1) { unsigned int i = 0; //"tipp" unsigned int di = e->nedges; //!! e->nedges uint64_t típus int found = 0; while(1) { int r = cmpf(e->e,i,p1); if(r == 0) { found = 1; break; } //megtaláltuk if(r < 0) { //visszafelé kell menni di /= 2; if(di == 0) di = 1; if(di == 1) { if(i==0) break; if(p1 > e->e[i-1].p1) break; //i és i-1 között kellene lennie } if(di > i) i = 0; else i -= di; } else { //növelni kell i-t di /= 2; if(di == 0) di = 1; if(di == 1) { if(i == e->nedges - 1) break; if(p1 < e->e[i+1].p1) break; //i és i+1 között kellene lennie } if(di > (e->nedges - i)) i = e->nedges - 1; else i += di; } } if(found) return i; return e->nedges; }
/* * Find the position of an item in a sorted dynarray. * @pda: sorted dynamic array to search. * @item: item contained within whose array index is desired. * @cmpf: comparison routine. * Returns the item's index into the array. If the item is not in the * dynarray, the index value returned is the position the element should * take on to maintain sort order. * * XXX this should be changed to use bsearch_ceil(). */ int psc_dynarray_bsearch(const struct psc_dynarray *pda, const void *item, int (*cmpf)(const void *, const void *)) { int rc, min, max, mid; void *p; min = mid = 0; max = psc_dynarray_len(pda) - 1; while (min <= max) { mid = (max + min) / 2; p = psc_dynarray_getpos(pda, mid); rc = cmpf(item, p); if (rc < 0) max = mid - 1; else if (rc > 0) { min = mid + 1; /* * If the item doesn't exist, inform caller that * the position the item should take on is after * this mid index. */ mid++; } else break; } return (mid); }
void ft_lstdelcmp(t_list **root, void *ct, int (*cmpf)(void*, void*), void (*del)(void*, size_t)) { if (!*root) ; else if (cmpf((*root)->content, ct) != 0) ft_lstdelcmp(&((*root)->next), ct, cmpf, del); else ft_lstdelone(root, del); }
static void frustumf( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, ogles_context_t* c) { if (cmpf(left,right) || cmpf(top, bottom) || cmpf(zNear, zFar) || isZeroOrNegativef(zNear) || isZeroOrNegativef(zFar)) { ogles_error(c, GL_INVALID_VALUE); return; } const GLfloat r_width = reciprocalf(right - left); const GLfloat r_height = reciprocalf(top - bottom); const GLfloat r_depth = reciprocalf(zNear - zFar); const GLfloat x = mul2f(zNear * r_width); const GLfloat y = mul2f(zNear * r_height); const GLfloat A = mul2f((right + left) * r_width); const GLfloat B = (top + bottom) * r_height; const GLfloat C = (zFar + zNear) * r_depth; const GLfloat D = mul2f(zFar * zNear * r_depth); GLfloat f[16]; f[ 0] = x; f[ 5] = y; f[ 8] = A; f[ 9] = B; f[10] = C; f[14] = D; f[11] = -1.0f; f[ 1] = f[ 2] = f[ 3] = f[ 4] = f[ 6] = f[ 7] = f[12] = f[13] = f[15] = 0.0f; matrixf_t rhs; rhs.set(f); c->transforms.current->multiply(rhs); c->transforms.invalidate(); }
void *btree_search_item(t_btree *root, void *data_ref, int (*cmpf)(void *, void *)) { if (root) { btree_search_item(root->left, data_ref, cmpf); if (cmpf(root->item, data_ref) == 0) return (root->item); btree_search_item(root->right, data_ref, cmpf); } return (NULL); }
unsigned comps_hslist_values_equal(COMPS_HSList *hlist1, COMPS_HSList *hlist2, char (*cmpf)(void*, void*)) { COMPS_HSListItem *it, *it2; for (it = hlist1->first, it2 = hlist2->first; it != NULL && it2 != NULL; it = it->next, it2 = it2->next) { if (!cmpf(it->data, it2->data)) return 0; } if (it != NULL || it2 != NULL) return 0; return 1; }
static void orthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, ogles_context_t* c) { if (cmpf(left,right) || cmpf(top, bottom) || cmpf(zNear, zFar)) { ogles_error(c, GL_INVALID_VALUE); return; } const GLfloat r_width = reciprocalf(right - left); const GLfloat r_height = reciprocalf(top - bottom); const GLfloat r_depth = reciprocalf(zFar - zNear); const GLfloat x = mul2f(r_width); const GLfloat y = mul2f(r_height); const GLfloat z = -mul2f(r_depth); const GLfloat tx = -(right + left) * r_width; const GLfloat ty = -(top + bottom) * r_height; const GLfloat tz = -(zFar + zNear) * r_depth; GLfloat f[16]; f[ 0] = x; f[ 5] = y; f[10] = z; f[12] = tx; f[13] = ty; f[14] = tz; f[15] = 1.0f; f[ 1] = f[ 2] = f[ 3] = f[ 4] = f[ 6] = f[ 7] = f[ 8] = f[ 9] = f[11] = 0.0f; matrixf_t rhs; rhs.set(f); c->transforms.current->multiply(rhs); c->transforms.invalidate(); }
void *btree_search_item(t_btree *root, void *data_ref, int (*cmpf)(void *, void *)) { void *result; result = NULL; if (root == NULL) return (NULL); if (root->left) result = btree_search_item(root->left, data_ref, cmpf); if (cmpf(root->item, data_ref) == 0) return (root->item); if (result == NULL && root->right != NULL) result = btree_search_item(root->right, data_ref, cmpf); return (result); }
void *ft_btree_search_item(t_btree **root, void *data_ref, int (*cmpf)(void *, void *)) { t_btree *result; result = NULL; if ((*root)->left) if ((result = ft_btree_search_item(&(*root)->left, data_ref, cmpf))) return (result); if (cmpf(data_ref, (*root)->content) == 0) return (*root); if ((*root)->right) if ((result = ft_btree_search_item(&(*root)->right, data_ref, cmpf))) return (result); return (NULL); }
// unique supports the following attributes: // order - usual stuff // fields - list of fields to consider for uniqueness // retry - number of time sto retry getting unique row DataSource * DSUnique :: FromXML( const ALib::XMLElement * e ) { RequireChildren( e ); AllowAttrs( e, AttrList( ORDER_ATTRIB,FIELDS_ATTRIB, RETRY_ATTRIB, 0 ) ); string fl = e->AttrValue( FIELDS_ATTRIB, "" ); FieldList cmpf( fl ); int retry = GetInt( e, RETRY_ATTRIB, ALib::Str( UNIQUE_RETRY) ); if ( retry < 0 ) { throw XMLError( ALib::SQuote( RETRY_ATTRIB ) + " cannot be negative", e ); } std::auto_ptr <DSUnique> c( new DSUnique( GetOrder( e ), cmpf , retry )); c->AddChildSources( e ); return c.release(); }
void *n_list_lookup_ex(const tn_list *l, const void *data, t_fn_cmp cmpf) { register struct list_node *node; if (cmpf == NULL) cmpf = l->cmp_fn; if (cmpf == NULL) { trurl_die("n_list_lookup: cmpf function is NULL\n"); return NULL; } for (node = l->head; node != NULL; node = node->next) { if (cmpf(node->data, data) == 0) return node->data; } return NULL; }
tn_array *n_array_remove_ex(tn_array *arr, const void *data, t_fn_cmp cmpf) { register int i, items, n; register void *ptr; trurl_die__if_frozen(arr); if (arr->items == 0) return arr; if (cmpf == NULL) cmpf = arr->cmp_fn; n_assert(cmpf != NULL); i = arr->start_index; items = arr->items; while ((size_t)i < arr->allocated) { ptr = arr->data[i]; if (ptr == NULL || cmpf(ptr, data) != 0) { i++; continue; } /* if slot is not empty, free node data */ if (arr->free_fn != NULL) arr->free_fn(ptr); n = arr->allocated - 1 - i; n_assert(n >= 0); if (n > 0) memmove(&arr->data[i], &arr->data[i + 1], n * sizeof(*arr->data)); arr->data[arr->allocated - 1] = NULL; items--; } arr->items = items; return arr; }
SgList *sg_list_insert_sorted(SgList *ls, SgCmpFun cmpf, void *data) { SgList *c, *p, *q = sg_alloc(sizeof(SgList) + sizeof(void*)); q->data[0] = data; for (c = ls, p = NULL; ; p = c) { if (!c) { q->prev = p; q->next = NULL; break; } if (cmpf(data, c->data[0]) < 0) { q->prev = c->prev; q->next = c; c->prev = q; break; } } if (!p) return q; return ls; }
void *n_tuple_bsearch_ex(const tn_tuple *tu, const void *data, t_fn_cmp cmpf) { int idx; void **base; if (tu->size == 0) return NULL; base = (void**)tu->data; if (tu->size > 1) { idx = bsearch_voidp_tu(base, tu->size, data, cmpf); } else { idx = -1; if (cmpf(base[0], data) == 0) idx = 0; } return idx < 0 ? NULL : base[idx]; }
int cmpPoint_y(const void *a, const void *b) { return cmpf( ((point *)a)->y, ((point *)b)->y ); }
int cmpPoint_x(const void *a, const void *b) { return cmpf( ((point*)a)->x, ((point*)b)->x ); }