void @TYPE@_vector_select_unique(@TYPE@_vector_type * vector) { @TYPE@_vector_assert_writable( vector ); { @TYPE@_vector_type * copy = @TYPE@_vector_alloc_copy( vector ); @TYPE@_vector_sort( copy ); @TYPE@_vector_reset( vector ); { int i; @TYPE@ previous_value = @TYPE@_vector_iget( copy , 0); @TYPE@_vector_append( vector , previous_value); for (i=1; i < copy->size; i++) { @TYPE@ value = @TYPE@_vector_iget( copy , i ); if (value != previous_value) @TYPE@_vector_append( vector , value); previous_value = value; } } @TYPE@_vector_free( copy ); } }
@TYPE@ @TYPE@_vector_del_value( @TYPE@_vector_type * vector , @TYPE@ del_value) { int index = 0; int del_count = 0; while (true) { if (index == vector->size) break; if (@TYPE@_vector_iget( vector , index) == del_value) { @TYPE@_vector_idel( vector , index); del_count++; } else index++; } return del_count; }
/** Should essentially implement Python sliced index lookup. */ @TYPE@_vector_type * @TYPE@_vector_alloc_strided_copy( const @TYPE@_vector_type * src , int start , int stop , int stride ) { @TYPE@_vector_type * copy = @TYPE@_vector_alloc( 0 , src->default_value ); if (start < 0) start = src->size - start; if (stop < 0) stop = src->size - stop; { int src_index = start; while (src_index < stop) { @TYPE@_vector_append( copy , @TYPE@_vector_iget( src , src_index )); src_index += stride; } } return copy; }
@TYPE@ @TYPE@_vector_idel( @TYPE@_vector_type * vector , int index) { @TYPE@ del_value = @TYPE@_vector_iget( vector , index ); @TYPE@_vector_idel_block( vector , index , 1 ); return del_value; }
/** Will abort is size == 0 */ @TYPE@ @TYPE@_vector_get_first(const @TYPE@_vector_type * vector) { return @TYPE@_vector_iget(vector , 0); }
/** Will abort is size == 0 */ @TYPE@ @TYPE@_vector_get_last(const @TYPE@_vector_type * vector) { return @TYPE@_vector_iget(vector , vector->size - 1); }
/* Will start counting from the reverse end, as negative indexing in python: vector_reverse_iget( v , -1 ) => The last element vector_reverse_iget( v , -2 ) => The second to last element */ @TYPE@ @TYPE@_vector_reverse_iget(const @TYPE@_vector_type * vector , int index) { return @TYPE@_vector_iget( vector , index + vector->size ); }