Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/vector_int.c

    r1ad1c99 r86bd7c1f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // vector_int.c --
     7// vector_int.c -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Wed May 27 17:56:53 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Apr 27 17:27:12 2016
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:38:05 2015
    1313// Update Count     : 3
    1414//
     
    2222#define DEFAULT_CAPACITY 20
    2323
    24 void ?{}( vector_int * vec ) {
    25         vec { DEFAULT_CAPACITY };
     24vector_int vector_int_allocate() {
     25        return vector_int_allocate( DEFAULT_CAPACITY );
    2626}
    2727
    28 void ?{}( vector_int * vec, int reserve ) {
    29         vec->last = -1;
    30         vec->capacity = reserve;
    31         vec->data = malloc( sizeof( int ) * reserve );
     28vector_int vector_int_allocate( int reserve ) {
     29        vector_int new_vector;
     30        new_vector.last = -1;
     31        new_vector.capacity = reserve;
     32        new_vector.data = malloc( sizeof( int ) * reserve );
     33        return new_vector;
    3234}
    3335
    34 void ?{}( vector_int * vec, vector_int other ) {
    35         vec->last = other.last;
    36         vec->capacity = other.capacity;
    37         vec->data = malloc( sizeof( int ) * other.capacity );
    38         for (int i = 0; i < vec->last; i++) {
    39                 vec->data[i] = other.data[i];
    40         }
    41 }
    42 
    43 void ^?{}( vector_int * vec ) {
    44         free( vec->data );
     36void vector_int_deallocate( vector_int vec ) {
     37        free( vec.data );
    4538}
    4639
     
    6356// implement bounded_array
    6457
    65 lvalue int ?[?]( vector_int * vec, int index ) {
    66         return vec->data[ index ];
     58lvalue int ?[?]( vector_int vec, int index ) {
     59        return vec.data[ index ];
    6760}
    6861
    69 int last( vector_int * vec ) {
    70         return vec->last;
     62int last( vector_int vec ) {
     63        return vec.last;
    7164}
    7265
Note: See TracChangeset for help on using the changeset viewer.