Revision 2c47b73,
1.3 KB
checked in by Hal Finkel <hfinkel@…>, 6 years ago
(diff) |
more work on adding SZ (latest version)
|
-
Property mode set to
100644
|
Line | |
---|
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 "DynamicDoubleArray.h" |
---|
14 | |
---|
15 | void new_DDA(DynamicDoubleArray **dda, size_t cap) { |
---|
16 | *dda = (DynamicDoubleArray *)malloc(sizeof(DynamicDoubleArray)); |
---|
17 | (*dda)->size = 0; |
---|
18 | (*dda)->capacity = cap; |
---|
19 | (*dda)->array = (double*)malloc(sizeof(double)*cap); |
---|
20 | } |
---|
21 | |
---|
22 | void convertDDAtoDoubles(DynamicDoubleArray *dba, double **data) |
---|
23 | { |
---|
24 | int size = dba->size; |
---|
25 | if(size>0) |
---|
26 | *data = (double*)malloc(size * sizeof(double)); |
---|
27 | else |
---|
28 | *data = NULL; |
---|
29 | memcpy(*data, dba->array, size*sizeof(double)); |
---|
30 | } |
---|
31 | |
---|
32 | void free_DDA(DynamicDoubleArray *dda) |
---|
33 | { |
---|
34 | free(dda->array); |
---|
35 | free(dda); |
---|
36 | } |
---|
37 | |
---|
38 | double getDDA_Data(DynamicDoubleArray *dda, size_t pos) |
---|
39 | { |
---|
40 | if(pos>=dda->size) |
---|
41 | { |
---|
42 | printf("Error: wrong position of DIA.\n"); |
---|
43 | exit(0); |
---|
44 | } |
---|
45 | return dda->array[pos]; |
---|
46 | } |
---|
47 | |
---|
48 | void addDDA_Data(DynamicDoubleArray *dda, double value) |
---|
49 | { |
---|
50 | if(dda->size==dda->capacity) |
---|
51 | { |
---|
52 | dda->capacity *= 2; |
---|
53 | dda->array = (double *)realloc(dda->array, dda->capacity*sizeof(double)); |
---|
54 | } |
---|
55 | dda->array[dda->size] = value; |
---|
56 | dda->size ++; |
---|
57 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.