Source

analytic_infall / grow_array.c

#include "grow_array.h"

static double *ga_location(ga_array *ga_array_ptr, size_t index) {
  size_t skips = index/GARRAYBLOCK;
  size_t subindex = index%GARRAYBLOCK;
  size_t i;
  ga_array *subarray;

  subarray = ga_array_ptr;

  for(i=0;i<skips;i++) {
    if(subarray->next==NULL) {
      subarray->next = malloc(sizeof(ga_array));
      if(subarray->next==NULL) return NULL;
      ga_init(subarray->next);
    }
      subarray=subarray->next;
  }

  return &(subarray->data[subindex]);
}

double ga_get(ga_array *array_ptr, size_t index) {
  double *loc;

  loc = ga_location(array_ptr,index);

  return *loc;
}

int ga_set(ga_array *array_ptr, size_t index, double data) {
  double *loc;

  loc = ga_location(array_ptr,index);

  if(loc==NULL) return -1;

  *loc = data;

  return 0;
}

double *ga_regularize(ga_array *array_ptr, size_t length) {
  double *result;
  size_t i;

  result = malloc(length*sizeof(double));
  if(result==NULL) return NULL;

  for(i=0;i<length;i++) {
    result[i] = ga_get(array_ptr,i);
  }

  return result;
}

void ga_free(ga_array *array_ptr) {
  ga_array *thisone;
  ga_array *nextone;

  thisone = array_ptr->next;

  while(thisone!=NULL) {
    nextone=thisone->next;
    free(thisone);
    thisone=nextone;
  }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.