src/ccpp_fields_idx.c File Reference
Routines and functions to generate and lookup fields/variables needed for the physics routines.
More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <sysexits.h>
#include <assert.h>
#include "ccpp_fields_idx.h"
Detailed Description
Routines and functions to generate and lookup fields/variables needed for the physics routines.
The fields are stored in an array of C pointers within the ccpp_t type. There is also an index array in this type. We poppulate this index array with the standard name of each variable in the fields array. We use a binary search on the sorted index array to retreive the array index for the field witin the fields array.
TODO
- Test the sort and lookup times for qsort() and bsearch().
- Implement this as a hash-map instead.
Function Documentation
int ccpp_field_idx_add |
( |
const char * |
name, |
|
|
void ** |
index | |
|
) |
| | |
Add/Insert a field into the index.
- Parameters:
-
[in] | name | The name to add to the index array. |
[in,out] | index | The index array. |
- Return values:
-
| > | 0 The index location. |
| -1 | If there was an error. |
int ccpp_field_idx_find |
( |
const char * |
name, |
|
|
void ** |
index | |
|
) |
| | |
Find the index number of a field.
- Parameters:
-
[in] | name | The field name to find the index array. |
[in,out] | index | The index array. |
- Return values:
-
| > | 0 The position in the index array of the requested field. |
| -1 | If there was an error. |
int ccpp_field_idx_fini |
( |
void ** |
index |
) |
|
Finialization routine.
Deallocates the field indices array.
- Parameters:
-
[in] | index | The index array. |
- Return values:
-
int ccpp_field_idx_grow |
( |
void ** |
index |
) |
|
Grow the index field array.
- Parameters:
-
[in,out] | index | The index array. |
- Return values:
-
int ccpp_field_idx_init |
( |
void ** |
index |
) |
|
Initialization routine.
Allocates an array for the field indices.
- Parameters:
-
[in,out] | index | The index array. |
- Return values:
-
| 0 | If it was sucessful. |
| 1 | If there was an error. |
int ccpp_field_idx_max |
( |
void ** |
index |
) |
|
Get the maximum number of fields the index array can hold.
- Parameters:
-
[in,out] | index | The index array. |
- Return values:
-
| >= | 0 The maximum number of fields. |
int ccpp_field_idx_sort |
( |
void ** |
index |
) |
|
Sort the index by calling qsort() and using cmp() as the comparison function.
- Parameters:
-
[in,out] | index | The index array. |
- Return values:
-