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

version» Context lines:

pike.git/lib/modules/ADT.pmod/Table.pmod:1:   // Table.pmod by Fredrik Noring, 1998 - // $Id: Table.pmod,v 1.11 1999/12/21 12:06:47 noring Exp $ + // $Id: Table.pmod,v 1.12 1999/12/21 20:12:43 noring Exp $      #define TABLE_ERR(msg) throw(({ "(Table) "+msg+"\n", backtrace() }))      class table {    static private mapping fieldmap;    static private array table, fields, types;       static private array|int remap(array|string|int cs, int|void forgive)    {    array v = ({});
pike.git/lib/modules/ADT.pmod/Table.pmod:215:    if(arrayp(v))    for(int i = 0; i < sizeof(v); i++)    t[r][cs[i]] = v[i];    else    t[r][cs[0]] = v;    }    }    return copy(t, fields, types);    }    -  object sort(int|string ... cs) +  static private object _sort(int is_reversed, int|string ... cs)    {    if(!sizeof(cs))    return this_object();    int c;    array t = copy_value(table); -  if(!catch(c = remap(cs[-1]))) { +  if(!catch(c = remap(cs[-1]))) +  {    mapping m = ([]); -  for(int r = 0; r < sizeof(t); r++) { +  for(int r = 0; r < sizeof(t); r++) +  {    mixed d;    if(!m[d = t[r][c]])    m[d] = ({ t[r] });    else    m[d] += ({ t[r] });    }    array i = indices(m), v = values(m);    predef::sort(i, v); -  t = v*({}); +  t = (is_reversed ? predef::reverse(v) : v)*({});    } -  return copy(t, fields, types)->sort(@cs[0..(sizeof(cs)-2)]); +  return is_reversed ? +  copy(t, fields, types)->rsort(@cs[0..(sizeof(cs)-2)]) : +  copy(t, fields, types)->sort(@cs[0..(sizeof(cs)-2)]);    }    -  +  object sort(int|string ... cs) +  { +  return _sort(0, @cs); +  } +     object rsort(int|string ... cs)    { -  return sort(@cs)->reverse(); +  return _sort(1, @cs);    }       object limit(int n)    {    return copy(table[0..(n-1)], fields, types);    }       object rename(string|int from, string to)    {    array a = copy_value(fields);