faststack.h File Reference

Implementation of a fast stack with smart memory management. More...

Go to the source code of this file.

Data Structures

struct  stack_level
struct  stack_wrapper


#define top_data(s)   (s->top->data)
#define empty_stack(s)   (s->top == NULL)


typedef stack_level stack_lvl_t
typedef stack_wrapper faststack_t


faststack_tmake_stack ()
void destroy_stack (faststack_t *s)
faststack_tpush (faststack_t *cur_stack, void *data)
stack_lvl_tpop (faststack_t *s)

Detailed Description

Implementation of a fast stack with smart memory management.

Define Documentation

#define empty_stack  )     (s->top == NULL)

Given a stack s, check to see if the stack is empty or not. Value is boolean true or false.

#define top_data  )     (s->top->data)

Given a stack s, examine the data pointer at the top.

Typedef Documentation

typedef struct stack_wrapper faststack_t

Wrapper around the stack levels - keeps a pointer to the current top and bottom of the stack and a count of the current height. This allows the top to have non-null above pointer resulting from previously allocated stack levels that may be recycled later without malloc overhead.

typedef struct stack_level stack_lvl_t

Structure representing a single level in the stack. Has a pointer to the level above and below itself and a pointer to a generic blob of data associated with this level.

Function Documentation

void destroy_stack faststack_t s  ) 

Given a stack structure, destroy it and free all of the stack levels. Important note : This function does not free the data pointed to from each level of the stack - the user is responsible for freeing this data themselves before calling this function to prevent memory leakage.

faststack_t* make_stack  ) 

Return a pointer to an empty stack structure. If the return value is NULL, one should check sexp_errno to determine why.

stack_lvl_t* pop faststack_t s  ) 

Given a stack, pop a level off and return a pointer to that level. The user is responsible for extracting the data, but the stack_lvl_t structures pointed to from the level (above and below) should be left alone. If NULL is returned, either the stack contained nothing, or the incoming stack s was NULL. Consult sexp_errno to determine which was the case -- SEXP_ERR_BAD_STACK indicates a null stack was passed in.

faststack_t* push faststack_t cur_stack,
void *  data

Given a stack, push a new level on referring to the data pointer. If a new level cannot be allocated, NULL is returned and sexp_errno is set with the appropriate error condition. Memory allocation errors will result in SEXP_ERR_MEMORY, while a null stack will result in SEXP_ERR_BAD_STACK.

Generated on Thu Oct 25 01:19:37 2007 for Small, Fast S-Expression Library by  doxygen 1.4.6