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

version» Context lines:

pike.git/lib/modules/ADT.pmod/History.pike:30:   void create(int max_size) {    stack = allocate(max_size);    maxsize = max_size;    /*    int top = 0;    int size = 0;    int latest_entry_num = 0;    */   }    + array _encode() + { +  array elems = stack[..top-1]; +  if (size == maxsize) { +  elems = stack[top..] + elems; +  } +  return ({ maxsize, elems, latest_entry_num, no_adjacent_duplicates }); + } +  + void _decode(array encoded) + { +  if ((sizeof(encoded) < 4) || +  !intp(encoded[0]) || !arrayp(encoded[1]) || +  !intp(encoded[2]) || !intp(encoded[3])) { +  error("Unsupported encoding.\n"); +  } +  [maxsize, stack, latest_entry_num, no_adjacent_duplicates] = encoded[..3]; +  top = size = sizeof(stack); +  if (top == maxsize) { +  top = 0; +  } else { +  stack += allocate(maxsize - size); +  } + } +    //! Change how the History object should treat two   //! identical values in a row. If 1 than only unique   //! values are allowed after each other.   //! @seealso   //! @[query_no_adjacent_duplicates]   void set_no_adjacent_duplicates(int(0..1) i) {    no_adjacent_duplicates = i;   }      //! Tells if the History object allows adjacent equal