Changeset 6b224a52 for src/tests/vector
- Timestamp:
- Aug 25, 2017, 12:11:53 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, stuck-waitfor-destruct, with_gc
- Children:
- bf7b9da7
- Parents:
- 135b431 (diff), f676b84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/tests/vector
- Files:
-
- 4 edited
-
array.h (modified) (1 diff)
-
vector_int.c (modified) (2 diffs)
-
vector_int.h (modified) (2 diffs)
-
vector_test.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/vector/array.h
r135b431 r6b224a52 21 21 // element has index 0. 22 22 trait array( otype array_type, otype elt_type ) { 23 lvalue elt_type?[?]( array_type, int );23 elt_type & ?[?]( array_type, int ); 24 24 }; 25 25 -
src/tests/vector/vector_int.c
r135b431 r6b224a52 20 20 #define DEFAULT_CAPACITY 20 21 21 22 void ?{}( vector_int *vec ) {22 void ?{}( vector_int & vec ) { 23 23 vec { DEFAULT_CAPACITY }; 24 24 } 25 25 26 void ?{}( vector_int *vec, int reserve ) {27 vec ->last = -1;28 vec ->capacity = reserve;29 vec ->data = malloc( sizeof( int ) * reserve );26 void ?{}( vector_int & vec, int reserve ) { 27 vec.last = -1; 28 vec.capacity = reserve; 29 vec.data = malloc( sizeof( int ) * reserve ); 30 30 } 31 31 32 void ?{}( vector_int *vec, vector_int other ) {33 vec ->last = other.last;34 vec ->capacity = other.capacity;35 vec ->data = malloc( sizeof( int ) * other.capacity );36 for (int i = 0; i < vec ->last; i++) {37 vec ->data[i] = other.data[i];32 void ?{}( vector_int & vec, vector_int other ) { 33 vec.last = other.last; 34 vec.capacity = other.capacity; 35 vec.data = malloc( sizeof( int ) * other.capacity ); 36 for (int i = 0; i < vec.last; i++) { 37 vec.data[i] = other.data[i]; 38 38 } 39 39 } 40 40 41 void ^?{}( vector_int *vec ) {42 free( vec ->data );41 void ^?{}( vector_int & vec ) { 42 free( vec.data ); 43 43 } 44 44 … … 61 61 // implement bounded_array 62 62 63 lvalue int?[?]( vector_int * vec, int index ) {63 int & ?[?]( vector_int * vec, int index ) { 64 64 return vec->data[ index ]; 65 65 } -
src/tests/vector/vector_int.h
r135b431 r6b224a52 24 24 } vector_int; 25 25 26 void ?{}( vector_int *); // allocate vector with default capacity27 void ?{}( vector_int *, int reserve ); // allocate vector with specified capacity28 void ?{}( vector_int * vec, vector_int other );// copy constructor29 void ^?{}( vector_int * );// deallocate vector's storage26 void ?{}( vector_int & ); // allocate vector with default capacity 27 void ?{}( vector_int &, int reserve ); // allocate vector with specified capacity 28 void ?{}( vector_int & vec, vector_int other ); // copy constructor 29 void ^?{}( vector_int & ); // deallocate vector's storage 30 30 31 31 void reserve( vector_int *vec, int reserve ); // reserve more capacity … … 34 34 // implement bounded_array 35 35 36 lvalue int ?[?]( vector_int * vec, int index );// access to arbitrary element (does not resize)37 int last( vector_int * vec ); // return last element36 int & ?[?]( vector_int * vec, int index ); // access to arbitrary element (does not resize) 37 int last( vector_int * vec ); // return last element 38 38 39 39 // Local Variables: // -
src/tests/vector/vector_test.c
r135b431 r6b224a52 9 9 // Author : Richard C. Bilson 10 10 // Created On : Wed May 27 17:56:53 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Apr 27 17:31:27 201613 // Update Count : 1 811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 24 08:15:38 2017 13 // Update Count : 19 14 14 // 15 15 … … 27 27 sout | "enter N elements and C-d on a separate line:" | endl; 28 28 for ( ;; ) { 29 sin | #29 sin | num; 30 30 if ( fail( sin ) || eof( sin ) ) break; 31 31 append( &vec, num );
Note:
See TracChangeset
for help on using the changeset viewer.