int insert(struct node_st **tree, int data) { struct node_st *newnode, *p; newnode = malloc(sizeof(*newnode)); if (newnode == NULL) { return -1; } newnode->data = data; newnode->color = RED; newnode->l = newnode->r = &nil; p = find_p(*tree, data); if (p == &nil) { newnode->p = &nil; newnode->color = BLACK; *tree = newnode; return 0; } if (data <= p->data) { p->l = newnode; } else { p->r = newnode; } newnode->p = p; insert_balance(tree, newnode); return 0; }
static struct node_st *find_p(struct node_st *tree, int data) { if (tree == &nil) { return &nil; } if (data < tree->data) { if (tree->l == &nil) { return tree; } return find_p(tree->l, data); } if (tree->r == &nil) { return tree; } return find_p(tree->r, data); }
void remove_fb(float *yp,float *ym,int n,short *scaler,short *shft) /* Find Scale and timeshift Yp = data trace Ym = wavelet F=min(Yp(x) - Ym(x)*a)^2 is a function to minimize for scaler find shift first with xcorrelation then solve for a - scaler */ { #define RAMPR 5 void find_p(float *ym,float *yp,float *a,int *b,int n); int it,ir; float a=1.0; int b=0; int ramps; float *a_ramp; ramps=NINT(n-n/RAMPR); find_p(ym,yp,&a,&b,n); a_ramp = ealloc1float(n); for(it=0;it<ramps;it++) a_ramp[it]=1.0; for(it=ramps,ir=0;it<n;it++,ir++) { a_ramp[it]=1.0-(float)ir/(float)(n-ramps-1); } if (b<0) { for(it=0;it<n+b;it++) yp[it-b] -=ym[it]*a*a_ramp[it-b]; } else { for(it=0;it<n-b;it++) yp[it] -=ym[it-b]*a*a_ramp[it+b]; } *scaler = NINT((1.0-a)*100.0); *shft = b; free1float(a_ramp); }
void MatchTrie::find_p(MatchTrie::TrieNode *n, int depth, const char *s, int len, int errorCount, std::vector <MatchTrie::Result> &result){ if (!n || errorCount < 0) return; if (depth == len){ for (std::set <Result>::iterator it = n -> data.begin(); it != n -> data.end(); it ++) result.push_back(*it); } else { for (int i = 0; i < 4; i ++) find_p(n -> next[i], depth + 1, s, len, errorCount - (dnaToInt(s[depth]) != i), result); } }
std::vector <MatchTrie::Result> MatchTrie::find(const char *s, int len, int maxErrorCount){ std::vector <Result> ret; find_p(_root, 0, s, len, maxErrorCount, ret); return ret; }