| 2177 | |
| 2178 | |
| 2179 | CV_IMPL schar* |
| 2180 | cvSeqSearch( CvSeq* seq, const void* _elem, CvCmpFunc cmp_func, |
| 2181 | int is_sorted, int* _idx, void* userdata ) |
| 2182 | { |
| 2183 | schar* result = 0; |
| 2184 | const schar* elem = (const schar*)_elem; |
| 2185 | int idx = -1; |
| 2186 | int i, j; |
| 2187 | |
| 2188 | if( _idx ) |
| 2189 | *_idx = idx; |
| 2190 | |
| 2191 | if( !CV_IS_SEQ(seq) ) |
| 2192 | CV_Error( !seq ? CV_StsNullPtr : CV_StsBadArg, "Bad input sequence" ); |
| 2193 | |
| 2194 | if( !elem ) |
| 2195 | CV_Error( CV_StsNullPtr, "Null element pointer" ); |
| 2196 | |
| 2197 | int elem_size = seq->elem_size; |
| 2198 | int total = seq->total; |
| 2199 | |
| 2200 | if( total == 0 ) |
| 2201 | return 0; |
| 2202 | |
| 2203 | if( !is_sorted ) |
| 2204 | { |
| 2205 | CvSeqReader reader; |
| 2206 | cvStartReadSeq( seq, &reader, 0 ); |
| 2207 | |
| 2208 | if( cmp_func ) |
| 2209 | { |
| 2210 | for( i = 0; i < total; i++ ) |
| 2211 | { |
| 2212 | if( cmp_func( elem, reader.ptr, userdata ) == 0 ) |
| 2213 | break; |
| 2214 | CV_NEXT_SEQ_ELEM( elem_size, reader ); |
| 2215 | } |
| 2216 | } |
| 2217 | else if( (elem_size & (sizeof(int)-1)) == 0 ) |
| 2218 | { |
| 2219 | for( i = 0; i < total; i++ ) |
| 2220 | { |
| 2221 | for( j = 0; j < elem_size; j += sizeof(int) ) |
| 2222 | { |
| 2223 | if( *(const int*)(reader.ptr + j) != *(const int*)(elem + j) ) |
| 2224 | break; |
| 2225 | } |
| 2226 | if( j == elem_size ) |
| 2227 | break; |
| 2228 | CV_NEXT_SEQ_ELEM( elem_size, reader ); |
| 2229 | } |
| 2230 | } |
| 2231 | else |
| 2232 | { |
| 2233 | for( i = 0; i < total; i++ ) |
| 2234 | { |
| 2235 | for( j = 0; j < elem_size; j++ ) |
| 2236 | { |
nothing calls this directly
no test coverage detected