cpg-stack

cpg-stack — Simple stack

Synopsis

CpgStack *          cpg_stack_new                       (guint size);
void                cpg_stack_init                      (CpgStack *stack,
                                                         guint size);
void                cpg_stack_destroy                   (CpgStack *stack);
void                cpg_stack_free                      (CpgStack *stack);
guint               cpg_stack_size                      (CpgStack *stack);
guint               cpg_stack_count                     (CpgStack *stack);
void                cpg_stack_push                      (CpgStack *stack,
                                                         gdouble value);
gdouble             cpg_stack_pop                       (CpgStack *stack);
void                cpg_stack_reset                     (CpgStack *stack);
gdouble             cpg_stack_at                        (CpgStack *stack,
                                                         gint idx);
                    CpgStack;

Description

Very simple/efficient stack implementation for double numbers.

Details

cpg_stack_new ()

CpgStack *          cpg_stack_new                       (guint size);

Create a new stack with the given size.

size :

the stack size

Returns :

A CpgStack

cpg_stack_init ()

void                cpg_stack_init                      (CpgStack *stack,
                                                         guint size);

Initialize the stack to a certain size (useful when a stack is allocated statically).

stack :

A CpgStack

size :

the stack size

cpg_stack_destroy ()

void                cpg_stack_destroy                   (CpgStack *stack);

Destroy the stack. This resizes the stack to 0. To free the whole stack, use cpg_stack_free.

stack :

A CpgStack

cpg_stack_free ()

void                cpg_stack_free                      (CpgStack *stack);

Free the stack.

stack :

A CpgStack

cpg_stack_size ()

guint               cpg_stack_size                      (CpgStack *stack);

Get the size of the stack. This is the maximum number of items that the stack can hold. Use cpg_stack_count to get the number of items currently on the stack

stack :

A CpgStack

Returns :

the stack size

cpg_stack_count ()

guint               cpg_stack_count                     (CpgStack *stack);

Count the number of items on the stack.

stack :

A CpgStack

Returns :

the number of items on the stack

cpg_stack_push ()

void                cpg_stack_push                      (CpgStack *stack,
                                                         gdouble value);

Push a value on the stack. The stack will not be automatically resized, thus be sure to know that you are not exceeding the stack size.

stack :

A CpgStack

value :

the value

cpg_stack_pop ()

gdouble             cpg_stack_pop                       (CpgStack *stack);

Pop a value of the stack. Note: this function does not check whether there are still values on the stack, be sure to either know, or check the stack yourself.

stack :

A CpgStack

Returns :

the last value on the stack

cpg_stack_reset ()

void                cpg_stack_reset                     (CpgStack *stack);

Reset the stack.

stack :

A CpgStack

cpg_stack_at ()

gdouble             cpg_stack_at                        (CpgStack *stack,
                                                         gint idx);

Get a value from the stack at the specified index idx.

stack :

A CpgStack

idx :

The index

Returns :

The stack value at index idx

CpgStack

typedef struct {
} CpgStack;