MCPcopy Create free account
hub / github.com/creatale/node-dv / cvSeqInsert

Function cvSeqInsert

deps/opencv/modules/core/src/datastructs.cpp:1243–1357  ·  view source on GitHub ↗

Insert new element in middle of sequence: */

Source from the content-addressed store, hash-verified

1241
1242/* Insert new element in middle of sequence: */
1243CV_IMPL schar*
1244cvSeqInsert( CvSeq *seq, int before_index, const void *element )
1245{
1246 int elem_size;
1247 int block_size;
1248 CvSeqBlock *block;
1249 int delta_index;
1250 int total;
1251 schar* ret_ptr = 0;
1252
1253 if( !seq )
1254 CV_Error( CV_StsNullPtr, "" );
1255
1256 total = seq->total;
1257 before_index += before_index < 0 ? total : 0;
1258 before_index -= before_index > total ? total : 0;
1259
1260 if( (unsigned)before_index > (unsigned)total )
1261 CV_Error( CV_StsOutOfRange, "" );
1262
1263 if( before_index == total )
1264 {
1265 ret_ptr = cvSeqPush( seq, element );
1266 }
1267 else if( before_index == 0 )
1268 {
1269 ret_ptr = cvSeqPushFront( seq, element );
1270 }
1271 else
1272 {
1273 elem_size = seq->elem_size;
1274
1275 if( before_index >= total >> 1 )
1276 {
1277 schar *ptr = seq->ptr + elem_size;
1278
1279 if( ptr > seq->block_max )
1280 {
1281 icvGrowSeq( seq, 0 );
1282
1283 ptr = seq->ptr + elem_size;
1284 assert( ptr <= seq->block_max );
1285 }
1286
1287 delta_index = seq->first->start_index;
1288 block = seq->first->prev;
1289 block->count++;
1290 block_size = (int)(ptr - block->data);
1291
1292 while( before_index < block->start_index - delta_index )
1293 {
1294 CvSeqBlock *prev_block = block->prev;
1295
1296 memmove( block->data + elem_size, block->data, block_size - elem_size );
1297 block_size = prev_block->count * elem_size;
1298 memcpy( block->data, prev_block->data + block_size - elem_size, elem_size );
1299 block = prev_block;
1300

Callers

nothing calls this directly

Calls 3

cvSeqPushFunction · 0.85
cvSeqPushFrontFunction · 0.85
icvGrowSeqFunction · 0.85

Tested by

no test coverage detected