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

version» Context lines:

pike.git/lib/modules/ADT.pmod/Stack.pike:24:    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. + //! @seealso + //! @[peek()]   mixed top()   {    if (ptr) {    return arr[ptr-1];    }    error("Stack underflow\n");   }    -  + //! Returns an element from the stack, without popping it. + //! + //! @param offset + //! The number of elements from the top of the stack to skip. + //! + //! @throws + //! Throws an error if called on an empty stack. + //! + //! @seealso + //! @[top()] + mixed peek(int|void offset) + { +  if ((offset >= 0) && ((ptr-offset) > 0)) { +  return arr[ptr-offset-1]; +  } +  error("Stack underflow\n"); + } +    //! Pops @[val] entries from the stack, or one entry   //! if no value is given. The popped entries are not   //! actually freed, only the stack pointer is moved.   void quick_pop(void|int val)   {    if (val) {    if (ptr < val) {    ptr = 0;    } else {    ptr -= val;