Changeset 89 for trunk/lib


Ignore:
Timestamp:
03/09/07 10:00:09 (18 years ago)
Author:
tim
Message:

Added contract comments to void_stack header. Minor cleanups in void_stack implementation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/void_stack.c

    r81 r89  
    105105
    106106
    107 unsigned short void_stack_size(void_stack* stack)
     107unsigned short void_stack_size(const void_stack* stack)
    108108{
    109109  return stack->top;
     110}
     111
     112
     113void* void_stack_pop(void_stack* stack)
     114{
     115  void* ret_val = NULL;
     116
     117  if(stack->top > 0)
     118  {
     119    ret_val = stack->elements[--(stack->top)];
     120    stack->elements[stack->top] = NULL;
     121  }
     122
     123  return ret_val;
    110124}
    111125
     
    123137
    124138
    125 void* void_stack_pop(void_stack* stack)
     139const void* void_stack_cur(const void_stack* stack)
    126140{
    127141  void* ret_val = NULL;
    128142
    129143  if(stack->top > 0)
    130   {
    131     ret_val = stack->elements[--(stack->top)];
    132     stack->elements[stack->top] = NULL;
    133   }
    134   else
    135     ret_val = NULL;
     144    ret_val = stack->elements[stack->top-1];
    136145
    137146  return ret_val;
     
    139148
    140149
    141 const void* void_stack_cur(void_stack* stack)
    142 {
    143   void* ret_val = NULL;
    144 
    145   if(stack->top > 0)
    146     ret_val = stack->elements[stack->top-1];
    147   else
    148     ret_val = NULL;
    149 
    150   return ret_val;
    151 }
    152 
    153 
    154 void_stack_iterator* void_stack_iterator_new(void_stack* stack)
     150void_stack_iterator* void_stack_iterator_new(const void_stack* stack)
    155151{
    156152  void_stack_iterator* ret_val = NULL;
    157153 
    158   ret_val = (void_stack_iterator*)malloc(sizeof(void_stack_iterator));
    159   if (ret_val != NULL)
     154  if(stack != NULL)
    160155  {
    161     ret_val->stack = stack;
    162     ret_val->cur = 0;
     156    ret_val = (void_stack_iterator*)malloc(sizeof(void_stack_iterator));
     157    if (ret_val != NULL)
     158    {
     159      ret_val->stack = stack;
     160      ret_val->cur = 0;
     161    }
    163162  }
    164163
Note: See TracChangeset for help on using the changeset viewer.