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

version» Context lines:

pike.git/lib/modules/ADT.pmod/Stack.pike:116:   //! @[create]   void reset(int|void initial_size)   {    arr = allocate(initial_size || 32);    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) + protected void create(int|void initial_size)   {    arr = allocate(initial_size || 32);   }      //! Sets the stacks content to the provided array.   void set_stack(array stack) {    arr = stack;    ptr = sizeof(arr);   }      //! @[sizeof] on a stack returns the number of entries   //! in the stack. - int _sizeof() { + protected int _sizeof() {    return ptr;   }      //! @[values] on a stack returns all the entries in   //! the stack, in order. - array _values() { + protected array _values() {    return arr[..ptr-1];   }      //! Return the stack-depth to @[item].   //!   //! This function makes it possible to use   //! eg @[search()] and @[has_value()] on the stack.   protected int _search(mixed item)   {    int i;    for (i = ptr; i--;) {    if (arr[i] == item) return ptr-(i+1);    }    return -1;   }      //! A stack added with another stack yields a new   //! stack with all the elements from both stacks,   //! and the elements from the second stack at the   //! top of the new stack. - this_program `+(this_program s) { + protected this_program `+(this_program s) {    array elem = arr[..ptr-1]+values(s);    this_program ns = this_program(1);    ns->set_stack(elem);    return ns;   }      protected mixed cast(string to)   {    if( to=="array" )    return _values();    return UNDEFINED;   }    - string _sprintf(int t) { + protected string _sprintf(int t) {    return t=='O' && sprintf("%O%O", this_program, _values());   }