Ignore:
Timestamp:
May 27, 2015, 8:33:19 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
00cc023
Parents:
52ac3b4
Message:

licencing: eighth groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/vector_int.c

    r52ac3b4 r86bd7c1f  
    1 // "cfa vector_int.c"
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// vector_int.c --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Wed May 27 17:56:53 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed May 27 18:38:05 2015
     13// Update Count     : 3
     14//
    215
    316#include "vector_int.h"
     
    1023
    1124vector_int vector_int_allocate() {
    12     return vector_int_allocate( DEFAULT_CAPACITY );
     25        return vector_int_allocate( DEFAULT_CAPACITY );
    1326}
    1427
    1528vector_int vector_int_allocate( int reserve ) {
    16     vector_int new_vector;
    17     new_vector.last = -1;
    18     new_vector.capacity = reserve;
    19     new_vector.data = malloc( sizeof( int ) * reserve );
    20     return new_vector;
     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;
    2134}
    2235
    2336void vector_int_deallocate( vector_int vec ) {
    24     free( vec.data );
     37        free( vec.data );
    2538}
    2639
    2740void reserve( vector_int *vec, int reserve ) {
    28     if ( reserve > vec->capacity ) {
    29         vec->data = realloc( vec->data, sizeof( int ) * reserve );
    30         vec->capacity = reserve;
    31     }
     41        if ( reserve > vec->capacity ) {
     42                vec->data = realloc( vec->data, sizeof( int ) * reserve );
     43                vec->capacity = reserve;
     44        }
    3245}
    3346
    3447void append( vector_int *vec, int element ) {
    35     vec->last++;
    36     if ( vec->last == vec->capacity ) {
    37         vec->capacity *= 2;
    38         vec->data = realloc( vec->data, sizeof( int ) * vec->capacity );
    39     }
    40     vec->data[ vec->last ] = element;
     48        vec->last++;
     49        if ( vec->last == vec->capacity ) {
     50                vec->capacity *= 2;
     51                vec->data = realloc( vec->data, sizeof( int ) * vec->capacity );
     52        }
     53        vec->data[ vec->last ] = element;
    4154}
    4255
     
    4457
    4558lvalue int ?[?]( vector_int vec, int index ) {
    46     return vec.data[ index ];
     59        return vec.data[ index ];
    4760}
    4861
    4962int last( vector_int vec ) {
    50     return vec.last;
     63        return vec.last;
    5164}
    5265
     66
     67// Local Variables: //
     68// tab-width: 4 //
     69// compile-command: "cfa vector_int.c" //
     70// End: //
Note: See TracChangeset for help on using the changeset viewer.