コード例 #1
0
ファイル: vector_template.c プロジェクト: PETECLAM/ResInsight
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 );
  }
}
コード例 #2
0
ファイル: vector_template.c プロジェクト: YingfangZhou/ert
@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;
}
コード例 #3
0
ファイル: vector_template.c プロジェクト: PETECLAM/ResInsight
/**
   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;
}
コード例 #4
0
ファイル: vector_template.c プロジェクト: PETECLAM/ResInsight
@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;
}
コード例 #5
0
ファイル: vector_template.c プロジェクト: PETECLAM/ResInsight
/** Will abort is size == 0 */
@TYPE@ @TYPE@_vector_get_first(const @TYPE@_vector_type * vector) {
  return @TYPE@_vector_iget(vector , 0);
}
コード例 #6
0
ファイル: vector_template.c プロジェクト: PETECLAM/ResInsight
/** Will abort is size == 0 */
@TYPE@ @TYPE@_vector_get_last(const @TYPE@_vector_type * vector) {
  return @TYPE@_vector_iget(vector , vector->size - 1);
}
コード例 #7
0
ファイル: vector_template.c プロジェクト: PETECLAM/ResInsight
/* 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 );
}