int SearchProxy::find( const QString & searchTerm, int searchFields ) { ProxyBase::find( searchTerm, searchFields ); m_currentSearchTerm = searchTerm; m_currentSearchFields = searchFields; for( int row = 0; row < rowCount(); row++ ) { if( rowMatch( row, searchTerm, searchFields ) ) return row; } return -1; }
int SearchProxy::findNext( const QString & searchTerm, int selectedRow, int searchFields ) { m_currentSearchTerm = searchTerm; m_currentSearchFields = searchFields; int firstMatch = -1; for( int row = 0; row < rowCount(); row++ ) { if( rowMatch( row, searchTerm, searchFields ) ) { if( firstMatch == -1 ) firstMatch = row; if( row > selectedRow ) return row; } } // We have searched through everything without finding anything that matched _below_ // the selected index. So we return the first one found above it (wrap around). return firstMatch; }
int SearchProxy::findPrevious( const QString & searchTerm, int selectedRow, int searchFields ) { m_currentSearchTerm = searchTerm; m_currentSearchFields = searchFields; int lastMatch = -1; for( int row = rowCount() - 1; row >= 0; row-- ) { if( rowMatch( row, searchTerm, searchFields ) ) { if( lastMatch == -1 ) lastMatch = row; if( row < selectedRow ) return row; } } // We have searched through everything without finding anything that matched _above_ // the selected index. So we return the first one found above it (wrap around). return lastMatch; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* [keyOut,valOut,k] = spot_mex_msspoly_make_canonical_combine_coeff(key,val) * * key -- m-by-n array, identical rows must be contiguous (e.g. key is sorted) * val -- m-by-1 array * * keyOut -- m-by-n array * valOut -- m-by-1 array * k -- 1-by-1 non-negative integer. * * k is the nubmer of unique rows in key. keyOut(1:k,:) contains the unique rows * valOut(j) = sum_{ i | key(i,:)=keyOut(j,:)} val(i). * */ mxArray *mx_key; mxArray *mx_val; int m,n; double *key; double *valR; double *valI; // Take in arguments. getArgSized(&mx_key,"double",0,nrhs,prhs,-1,-1); key = mxGetPr(mx_key); m = mxGetM(mx_key); n = mxGetN(mx_key); getArgSized(&mx_val,"double",1,nrhs,prhs,m,1); valR = mxGetPr(mx_val); valI = mxGetPi(mx_val); int i,j; mxArray *mx_keyOut; mxArray *mx_valOut; int k; double *keyOut; double *valOutR; double *valOutI; bool flag = mxIsComplex(mx_val); mx_keyOut = mxCreateDoubleMatrix(m,n,mxREAL); keyOut = mxGetPr(mx_keyOut); mx_valOut = mxCreateDoubleMatrix(m,1,flag ? mxCOMPLEX : mxREAL); valOutR = mxGetPr(mx_valOut); valOutI = mxGetPi(mx_valOut); k=-1; for(i = 0; i < m; i++){ if( i == 0 || !rowMatch(keyOut,k,key,i,m,n)){ k++; for(j = 0; j < n; j++){ keyOut[j*m+k] = key[j*m+i]; } valOutR[k] = valR[i]; if(flag == mxCOMPLEX) valOutI[k] = valI[i]; } else { valOutR[k] += valR[i]; if(flag == mxCOMPLEX) valOutI[k] += valI[i]; } } if(nlhs > 0) plhs[0] = mxCreateDoubleScalar(k+1); if(nlhs > 1) plhs[1] = mx_keyOut; if(nlhs > 2) plhs[2] = mx_valOut; }