Back to index

php5  5.3.10
Classes | Functions
fpm_arrays.h File Reference
#include <stdlib.h>
#include <string.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fpm_array_s

Functions

static struct fpm_array_sfpm_array_init (struct fpm_array_s *a, unsigned int sz, unsigned int initial_num)
static void * fpm_array_item (struct fpm_array_s *a, unsigned int n)
static void * fpm_array_item_last (struct fpm_array_s *a)
static int fpm_array_item_remove (struct fpm_array_s *a, unsigned int n)
static void * fpm_array_push (struct fpm_array_s *a)
static void fpm_array_free (struct fpm_array_s *a)

Class Documentation

struct fpm_array_s

Definition at line 11 of file fpm_arrays.h.

Class Members
size_t allocated
void * data
size_t sz
size_t used

Function Documentation

static void fpm_array_free ( struct fpm_array_s a) [inline, static]

Definition at line 107 of file fpm_arrays.h.

{
       free(a->data);
       a->data = 0;
       a->sz = 0;
       a->used = a->allocated = 0;
}

Here is the caller graph for this function:

static struct fpm_array_s* fpm_array_init ( struct fpm_array_s a,
unsigned int  sz,
unsigned int  initial_num 
) [static, read]

Definition at line 18 of file fpm_arrays.h.

{
       void *allocated = 0;

       if (!a) {
              a = malloc(sizeof(struct fpm_array_s));

              if (!a) {
                     return 0;
              }

              allocated = a;
       }

       a->sz = sz;

       a->data = calloc(sz, initial_num);

       if (!a->data) {
              free(allocated);
              return 0;
       }

       a->allocated = initial_num;
       a->used = 0;

       return a;
}

Here is the caller graph for this function:

static void* fpm_array_item ( struct fpm_array_s a,
unsigned int  n 
) [inline, static]

Definition at line 48 of file fpm_arrays.h.

{
       char *ret;

       ret = (char *) a->data + a->sz * n;

       return ret;
}

Here is the caller graph for this function:

static void* fpm_array_item_last ( struct fpm_array_s a) [inline, static]

Definition at line 58 of file fpm_arrays.h.

{
       return fpm_array_item(a, a->used - 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int fpm_array_item_remove ( struct fpm_array_s a,
unsigned int  n 
) [inline, static]

Definition at line 64 of file fpm_arrays.h.

{
       int ret = -1;

       if (n < a->used - 1) {
              void *last = fpm_array_item(a, a->used - 1);
              void *to_remove = fpm_array_item(a, n);

              memcpy(to_remove, last, a->sz);

              ret = n;
       }

       --a->used;

       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void* fpm_array_push ( struct fpm_array_s a) [inline, static]

Definition at line 83 of file fpm_arrays.h.

{
       void *ret;

       if (a->used == a->allocated) {
              size_t new_allocated = a->allocated ? a->allocated * 2 : 20;
              void *new_ptr = realloc(a->data, a->sz * new_allocated);

              if (!new_ptr) {
                     return 0;
              }

              a->data = new_ptr;
              a->allocated = new_allocated;
       }

       ret = fpm_array_item(a, a->used);

       ++a->used;

       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function: