pike.git / lib / modules / ADT.pmod / Stack.pike

version» Context lines:

pike.git/lib/modules/ADT.pmod/Stack.pike:1:   #pike __REAL_VERSION__    - // $Id: Stack.pike,v 1.5 2002/03/20 16:39:52 nilsson Exp $ + // $Id: Stack.pike,v 1.6 2002/03/25 22:39:07 nilsson Exp $      //! This class implements a simple stack. Instead of adding and removing   //! elements to an array, and thus making it vary in size for every push   //! and pop operation, this stack tries to keep the stack size constant.   //! If however the stack risks to overflow, it will allocate double its   //! current size, i.e. pushing an element on an full 32 slot stack will   //! result in a 64 slot stack with 33 elements.      int ptr;   array arr;
pike.git/lib/modules/ADT.pmod/Stack.pike:16:   void push(mixed val)   {    if(ptr == sizeof(arr)) {    arr += allocate(ptr);    }    arr[ptr++] = val;   }      //! Returns the top element from the stack, without   //! popping it. + //! @throws + //! Throws an error if called on an empty stack.   mixed top()   {    if (ptr) {    return(arr[ptr-1]);    }    error("Stack underflow\n");   }      //! Pops @[val] entries from the stack, or one entry   //! if no value is given. The popped entries are not
pike.git/lib/modules/ADT.pmod/Stack.pike:92:    ptr = 0;   }      //! An initial stack size can be given when   //! a stack is cloned. The default value is   //! 32.   void create(int|void initial_size)   {    arr = allocate(initial_size || 32);   } +  + //! + int _sizeof() { +  return ptr; + }