ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        ctor
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        gc_noraii
        jacob/cs343-translation
        jenkins-sandbox
        memory
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        string
        with_gc
      
      
        
          | Last change
 on this file since 145f1fc was             86bd7c1f, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago | 
        
          | 
licencing: eighth groups of files
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.5 KB | 
      
      
| Rev | Line |  | 
|---|
| [86bd7c1f] | 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 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
|  | 16 | #include "vector_int.h" | 
|---|
|  | 17 | extern "C" { | 
|---|
|  | 18 | #include <stdlib.h> | 
|---|
|  | 19 | #include <assert.h> | 
|---|
|  | 20 | } | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #define DEFAULT_CAPACITY 20 | 
|---|
|  | 23 |  | 
|---|
| [134b86a] | 24 | vector_int vector_int_allocate() { | 
|---|
| [86bd7c1f] | 25 | return vector_int_allocate( DEFAULT_CAPACITY ); | 
|---|
| [51b73452] | 26 | } | 
|---|
|  | 27 |  | 
|---|
| [134b86a] | 28 | vector_int vector_int_allocate( int reserve ) { | 
|---|
| [86bd7c1f] | 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; | 
|---|
| [51b73452] | 34 | } | 
|---|
|  | 35 |  | 
|---|
| [134b86a] | 36 | void vector_int_deallocate( vector_int vec ) { | 
|---|
| [86bd7c1f] | 37 | free( vec.data ); | 
|---|
| [51b73452] | 38 | } | 
|---|
|  | 39 |  | 
|---|
| [134b86a] | 40 | void reserve( vector_int *vec, int reserve ) { | 
|---|
| [86bd7c1f] | 41 | if ( reserve > vec->capacity ) { | 
|---|
|  | 42 | vec->data = realloc( vec->data, sizeof( int ) * reserve ); | 
|---|
|  | 43 | vec->capacity = reserve; | 
|---|
|  | 44 | } | 
|---|
| [51b73452] | 45 | } | 
|---|
|  | 46 |  | 
|---|
| [134b86a] | 47 | void append( vector_int *vec, int element ) { | 
|---|
| [86bd7c1f] | 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; | 
|---|
| [51b73452] | 54 | } | 
|---|
|  | 55 |  | 
|---|
|  | 56 | // implement bounded_array | 
|---|
|  | 57 |  | 
|---|
| [134b86a] | 58 | lvalue int ?[?]( vector_int vec, int index ) { | 
|---|
| [86bd7c1f] | 59 | return vec.data[ index ]; | 
|---|
| [51b73452] | 60 | } | 
|---|
|  | 61 |  | 
|---|
| [134b86a] | 62 | int last( vector_int vec ) { | 
|---|
| [86bd7c1f] | 63 | return vec.last; | 
|---|
| [51b73452] | 64 | } | 
|---|
|  | 65 |  | 
|---|
| [86bd7c1f] | 66 |  | 
|---|
|  | 67 | // Local Variables: // | 
|---|
|  | 68 | // tab-width: 4 // | 
|---|
|  | 69 | // compile-command: "cfa vector_int.c" // | 
|---|
|  | 70 | // End: // | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.