bool @TYPE@_vector_init_range(@TYPE@_vector_type * vector , @TYPE@ min_value , @TYPE@ max_value , @TYPE@ delta) { if (max_value >= min_value) { @TYPE@ current_value = min_value; @TYPE@_vector_reset( vector ); while (current_value < max_value) { @TYPE@_vector_append( vector , current_value ); current_value += delta; } @TYPE@_vector_append( vector , max_value ); return true; } else return false; }
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 ); } }
/** 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; }
void @TYPE@_vector_range_fill(@TYPE@_vector_type * vector , @TYPE@ limit1 , @TYPE@ delta , @TYPE@ limit2) { @TYPE@ current_value = limit1; if (delta == 0) util_abort("%s: sorry can not have delta == 0 \n",__func__); @TYPE@_vector_reset( vector ); while (true) { @TYPE@_vector_append( vector , current_value ); current_value += delta; if (delta > 0 && current_value > limit2) break; if (delta < 0 && current_value < limit2) break; } }
void @TYPE@_vector_append_default(@TYPE@_vector_type * vector , @TYPE@ default_value) { @TYPE@_vector_append( vector , default_value ); @TYPE@_vector_set_default( vector , default_value ); }