Revision 9ee2ce3,
1.2 KB
checked in by Hal Finkel <hfinkel@…>, 6 years ago
(diff) |
importing new SZ files
|
-
Property mode set to
100644
|
Rev | Line | |
---|
[2c47b73] | 1 | /** |
---|
| 2 | * @file DynamicFloatArray.c |
---|
| 3 | * @author Sheng Di |
---|
| 4 | * @date May, 2016 |
---|
| 5 | * @brief Dynamic Float Array |
---|
| 6 | * (C) 2015 by Mathematics and Computer Science (MCS), Argonne National Laboratory. |
---|
| 7 | * See COPYRIGHT in top-level directory. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include <stdlib.h> |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <string.h> |
---|
| 13 | #include "DynamicFloatArray.h" |
---|
| 14 | |
---|
| 15 | void new_DFA(DynamicFloatArray **dfa, size_t cap) { |
---|
| 16 | *dfa = (DynamicFloatArray *)malloc(sizeof(DynamicFloatArray)); |
---|
| 17 | (*dfa)->size = 0; |
---|
| 18 | (*dfa)->capacity = cap; |
---|
| 19 | (*dfa)->array = (float*)malloc(sizeof(float)*cap); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | void convertDFAtoFloats(DynamicFloatArray *dfa, float **data) |
---|
| 23 | { |
---|
[9ee2ce3] | 24 | size_t size = dfa->size; |
---|
[2c47b73] | 25 | if(size>0) |
---|
| 26 | *data = (float*)malloc(size * sizeof(float)); |
---|
| 27 | else |
---|
| 28 | *data = NULL; |
---|
| 29 | memcpy(*data, dfa->array, size*sizeof(float)); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | void free_DFA(DynamicFloatArray *dfa) |
---|
| 33 | { |
---|
| 34 | free(dfa->array); |
---|
| 35 | free(dfa); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | float getDFA_Data(DynamicFloatArray *dfa, size_t pos) |
---|
| 39 | { |
---|
| 40 | if(pos>=dfa->size) |
---|
| 41 | { |
---|
| 42 | printf("Error: wrong position of DIA.\n"); |
---|
| 43 | exit(0); |
---|
| 44 | } |
---|
| 45 | return dfa->array[pos]; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void addDFA_Data(DynamicFloatArray *dfa, float value) |
---|
| 49 | { |
---|
| 50 | if(dfa->size==dfa->capacity) |
---|
| 51 | { |
---|
| 52 | dfa->capacity *= 2; |
---|
| 53 | dfa->array = (float *)realloc(dfa->array, dfa->capacity*sizeof(float)); |
---|
| 54 | } |
---|
| 55 | dfa->array[dfa->size] = value; |
---|
| 56 | dfa->size++; |
---|
| 57 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.