a580e1 | 2000-09-27 | Fredrik Hübinette (Hubbe) | | #pike __REAL_VERSION__
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
|
d3ffb2 | 2002-03-20 | Martin Nilsson | | #pragma strict_types
|
25616a | 2004-03-23 | Martin Nilsson | |
|
088e2e | 1998-02-12 | Mirar (Pontus Hagland) | | constant diff = __builtin.diff;
constant diff_longest_sequence = __builtin.diff_longest_sequence;
constant diff_compare_table = __builtin.diff_compare_table;
|
5bb99c | 1998-02-12 | Henrik Grubbström (Grubba) | | constant longest_ordered_sequence = __builtin.longest_ordered_sequence;
|
a7759e | 1998-11-17 | Henrik Grubbström (Grubba) | | constant interleave_array = __builtin.interleave_array;
|
088e2e | 1998-02-12 | Mirar (Pontus Hagland) | |
|
a8c8b8 | 2003-07-24 | Henrik Grubbström (Grubba) | | constant diff_dyn_longest_sequence = __builtin.diff_dyn_longest_sequence;
|
bb9a2f | 2003-04-29 | Martin Nilsson | | constant sort = predef::sort;
|
f7aff6 | 1998-04-14 | Henrik Wallin | | constant everynth = __builtin.everynth;
constant splice = __builtin.splice;
constant transpose = __builtin.transpose;
|
652d92 | 2000-04-19 | David Hedbor | | constant uniq = __builtin.uniq_array;
|
55683e | 2000-08-28 | Per Hedbor | |
|
5a3697 | 1999-07-27 | Mirar (Pontus Hagland) | | constant filter=predef::filter;
constant map=predef::map;
|
55683e | 2000-08-28 | Per Hedbor | | constant permute = __builtin.permute;
|
366509 | 2000-12-15 | Martin Nilsson | | constant enumerate = predef::enumerate;
|
3a89ab | 2002-11-07 | Marcus Comstedt | | constant Iterator = __builtin.array_iterator;
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
edcae2 | 2001-07-30 | Johan Sundström | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
56cd00 | 2001-10-28 | Martin Nilsson | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
be192f | 1999-07-26 | Marcus Comstedt | | mixed reduce(function fun, array arr, mixed|void zero)
|
662511 | 1999-07-25 | Marcus Comstedt | | {
if(sizeof(arr))
zero = arr[0];
for(int i=1; i<sizeof(arr); i++)
|
0662a9 | 2000-07-12 | Henrik Grubbström (Grubba) | | zero = ([function(mixed,mixed:mixed)]fun)(zero, arr[i]);
|
662511 | 1999-07-25 | Marcus Comstedt | | return zero;
}
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
edcae2 | 2001-07-30 | Johan Sundström | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
56cd00 | 2001-10-28 | Martin Nilsson | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
be192f | 1999-07-26 | Marcus Comstedt | | mixed rreduce(function fun, array arr, mixed|void zero)
|
662511 | 1999-07-25 | Marcus Comstedt | | {
if(sizeof(arr))
zero = arr[-1];
for(int i=sizeof(arr)-2; i>=0; --i)
|
0662a9 | 2000-07-12 | Henrik Grubbström (Grubba) | | zero = ([function(mixed,mixed:mixed)]fun)(arr[i], zero);
|
662511 | 1999-07-25 | Marcus Comstedt | | return zero;
}
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
0a96ae | 2002-08-03 | Martin Nilsson | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
56cd00 | 2001-10-28 | Martin Nilsson | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
b77d8d | 1998-02-28 | Henrik Grubbström (Grubba) | | array shuffle(array arr)
{
int i = sizeof(arr);
while(i) {
|
d88ed3 | 2002-08-26 | Martin Nilsson | | int j = random(i--);
|
b77d8d | 1998-02-28 | Henrik Grubbström (Grubba) | | if (j != i) {
mixed tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
|
33f4d0 | 2003-08-22 | Martin Nilsson | | return arr;
|
b77d8d | 1998-02-28 | Henrik Grubbström (Grubba) | | }
|
325052 | 2005-04-13 | Henrik Grubbström (Grubba) | |
array(array) combinations(array arr, int len)
{
if (len > sizeof(arr)) return ({});
if (len == sizeof(arr)) return ({arr+({})});
if (!len) return ({({})});
if (len < 0) error("Negative length.\n");
array(int) stack = allocate(len+1);
array selection = allocate(len);
array(array) res = allocate(Math.choose(sizeof(arr), len));
int depth;
int pos;
stack[0] = -1;
for (pos = 0; pos < sizeof(res); pos++) {
selection[depth] = arr[stack[depth+1]];
for(depth++;depth < len; depth++) {
selection[depth] = arr[stack[depth+1] = stack[depth]+1];
}
res[pos] = selection + ({});
do {
stack[depth--]++;
} while (depth && (stack[depth+1]+len == sizeof(arr)+depth+1));
}
return res;
}
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
56cd00 | 2001-10-28 | Martin Nilsson | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
a9d4a2 | 2002-03-02 | Martin Nilsson | | int search_array(array arr, string|function|int fun, mixed ... args)
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | {
int e;
if(stringp(fun))
{
for(e=0;e<sizeof(arr);e++)
|
0662a9 | 2000-07-12 | Henrik Grubbström (Grubba) | | if(([function(mixed...:mixed)]([array(object)]arr)[e][fun])(@args))
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | return e;
return -1;
}
else if(functionp(fun))
{
for(e=0;e<sizeof(arr);e++)
|
0662a9 | 2000-07-12 | Henrik Grubbström (Grubba) | | if(([function(mixed,mixed...:mixed)]fun)(arr[e],@args))
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | return e;
return -1;
}
else if(intp(fun))
{
for(e=0;e<sizeof(arr);e++)
|
0662a9 | 2000-07-12 | Henrik Grubbström (Grubba) | | if(([array(function(mixed...:mixed))]arr)[e](@args))
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | return e;
return -1;
}
|
a9d4a2 | 2002-03-02 | Martin Nilsson | |
error("Bad argument 2 to search_array().\n");
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | }
|
d3ffb2 | 2002-03-20 | Martin Nilsson | |
|
e5ef06 | 2003-04-01 | Martin Nilsson | |
|
d3ffb2 | 2002-03-20 | Martin Nilsson | | array sum_arrays(function(mixed ...:mixed) sum, array ... args)
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | {
|
d3ffb2 | 2002-03-20 | Martin Nilsson | | array ret = allocate(sizeof(args[0]));
for(int e=0; e<sizeof(args[0]); e++)
ret[e] = sum( @column(args, e) );
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | return ret;
}
|
574bc4 | 2002-09-18 | Martin Stjernholm | |
|
e5ef06 | 2003-04-01 | Martin Nilsson | |
|
574bc4 | 2002-09-18 | Martin Stjernholm | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
2b007a | 2002-12-19 | Martin Nilsson | |
|
5d6608 | 2000-12-13 | Henrik Grubbström (Grubba) | |
|
832504 | 2007-12-27 | Martin Nilsson | | array sort_array(array arr, function(mixed,mixed,mixed ...:int)|void cmp,
mixed ... args)
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | {
array bar,tmp;
int len,start;
int length;
int foop, fooend, barp, barend;
|
832504 | 2007-12-27 | Martin Nilsson | | arr+=({});
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | if(!cmp || cmp==`>)
{
|
832504 | 2007-12-27 | Martin Nilsson | | sort(arr);
return arr;
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | }
if(cmp == `<)
{
|
832504 | 2007-12-27 | Martin Nilsson | | sort(arr);
return reverse(arr);
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | }
|
832504 | 2007-12-27 | Martin Nilsson | | length=sizeof(arr);
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | |
bar=allocate(length);
for(len=1;len<length;len*=2)
{
start=0;
while(start+len < length)
{
foop=start;
barp=start+len;
fooend=barp;
barend=barp+len;
if(barend > length) barend=length;
|
edcae2 | 2001-07-30 | Johan Sundström | |
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | while(1)
{
|
832504 | 2007-12-27 | Martin Nilsson | | if(([function(mixed,mixed,mixed...:int)]cmp)(arr[foop],arr[barp],@args)
|
0662a9 | 2000-07-12 | Henrik Grubbström (Grubba) | | <= 0)
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | {
|
832504 | 2007-12-27 | Martin Nilsson | | bar[start++]=arr[foop++];
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | if(foop == fooend)
{
|
832504 | 2007-12-27 | Martin Nilsson | | while(barp < barend) bar[start++]=arr[barp++];
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | break;
}
}else{
|
832504 | 2007-12-27 | Martin Nilsson | | bar[start++]=arr[barp++];
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | if(barp == barend)
{
|
832504 | 2007-12-27 | Martin Nilsson | | while(foop < fooend) bar[start++]=arr[foop++];
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | break;
}
}
}
}
|
832504 | 2007-12-27 | Martin Nilsson | | while(start < length) bar[start]=arr[start++];
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | |
|
832504 | 2007-12-27 | Martin Nilsson | | tmp=arr;
arr=bar;
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | bar=tmp;
}
|
832504 | 2007-12-27 | Martin Nilsson | | return arr;
|
c2a406 | 1997-02-06 | Fredrik Hübinette (Hubbe) | | }
|
a8c8b8 | 2003-07-24 | Henrik Grubbström (Grubba) | |
array(array) columns(array x, array ind)
|
0dcb7f | 1998-01-31 | Fredrik Hübinette (Hubbe) | | {
|
cf46a7 | 2003-07-25 | Henrik Grubbström (Grubba) | | array(array) ret=allocate(sizeof(ind));
|
0dcb7f | 1998-01-31 | Fredrik Hübinette (Hubbe) | | for(int e=0;e<sizeof(ind);e++) ret[e]=column(x,ind[e]);
return ret;
}
|
905bb1 | 1998-01-31 | Fredrik Hübinette (Hubbe) | |
|
04a1a8 | 1998-11-30 | Martin Stjernholm | |
|
a8c8b8 | 2003-07-24 | Henrik Grubbström (Grubba) | |
|
04a1a8 | 1998-11-30 | Martin Stjernholm | | array(array(array)) diff3 (array a, array b, array c)
{
array(int) seq_ab = diff_longest_sequence (a, b);
array(int) seq_bc = diff_longest_sequence (b, c);
array(int) seq_ca = diff_longest_sequence (c, a);
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | array(int) aeq = allocate (sizeof (a) + 1);
array(int) beq = allocate (sizeof (b) + 1);
array(int) ceq = allocate (sizeof (c) + 1);
aeq[sizeof (a)] = beq[sizeof (b)] = ceq[sizeof (c)] = 7;
|
04a1a8 | 1998-11-30 | Martin Stjernholm | |
for (int i = 0, j = 0; j < sizeof (seq_ab); i++)
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | if (a[i] == b[seq_ab[j]]) aeq[i] |= 2, beq[seq_ab[j]] |= 1, j++;
|
04a1a8 | 1998-11-30 | Martin Stjernholm | | for (int i = 0, j = 0; j < sizeof (seq_bc); i++)
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | if (b[i] == c[seq_bc[j]]) beq[i] |= 2, ceq[seq_bc[j]] |= 1, j++;
|
04a1a8 | 1998-11-30 | Martin Stjernholm | | for (int i = 0, j = 0; j < sizeof (seq_ca); i++)
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | if (c[i] == a[seq_ca[j]]) ceq[i] |= 2, aeq[seq_ca[j]] |= 1, j++;
|
04a1a8 | 1998-11-30 | Martin Stjernholm | |
|
54e28f | 1999-05-31 | Martin Stjernholm | |
|
04a1a8 | 1998-11-30 | Martin Stjernholm | | array(array) ares = ({}), bres = ({}), cres = ({});
int ai = 0, bi = 0, ci = 0;
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | int prevodd = -2;
|
04a1a8 | 1998-11-30 | Martin Stjernholm | |
|
f17d2e | 1998-12-04 | Martin Stjernholm | | while (!(aeq[ai] & beq[bi] & ceq[ci] & 4)) {
|
54e28f | 1999-05-31 | Martin Stjernholm | |
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | array empty = ({}), apart = empty, bpart = empty, cpart = empty;
|
54e28f | 1999-05-31 | Martin Stjernholm | | int side = aeq[ai] & beq[bi] & ceq[ci];
if ((<1, 2>)[side]) {
int which, merge, inv_side = side ^ 3, i, oi;
array(int) eq, oeq;
array arr, oarr;
int atest = side == 1 ? ceq[ci] != 3 : beq[bi] != 3;
int btest = side == 1 ? aeq[ai] != 3 : ceq[ci] != 3;
int ctest = side == 1 ? beq[bi] != 3 : aeq[ai] != 3;
for (i = 0;; i++) {
int abreak = atest && aeq[ai] != aeq[ai + i];
int bbreak = btest && beq[bi] != beq[bi + i];
int cbreak = ctest && ceq[ci] != ceq[ci + i];
if (abreak + bbreak + cbreak > 1) {
if (side == 1) {
if (!atest) cbreak = 0;
if (!btest) abreak = 0;
if (!ctest) bbreak = 0;
}
else {
if (!atest) bbreak = 0;
if (!btest) cbreak = 0;
if (!ctest) abreak = 0;
}
switch (prevodd) {
case 0: if (abreak) bbreak = cbreak = 0; break;
case 1: if (bbreak) cbreak = abreak = 0; break;
case 2: if (cbreak) abreak = bbreak = 0; break;
}
}
if (abreak) {
which = 0, merge = (<0, -1>)[prevodd];
i = ai, eq = aeq, arr = a;
if (inv_side == 1) oi = bi, oeq = beq, oarr = b;
else oi = ci, oeq = ceq, oarr = c;
break;
}
if (bbreak) {
which = 1, merge = (<1, -1>)[prevodd];
i = bi, eq = beq, arr = b;
if (inv_side == 1) oi = ci, oeq = ceq, oarr = c;
else oi = ai, oeq = aeq, oarr = a;
break;
}
if (cbreak) {
which = 2, merge = (<2, -1>)[prevodd];
i = ci, eq = ceq, arr = c;
if (inv_side == 1) oi = ai, oeq = aeq, oarr = a;
else oi = bi, oeq = beq, oarr = b;
break;
}
}
int s = i, mask = eq[i];
do {
eq[i++] &= inv_side;
while (!(oeq[oi] & inv_side)) oi++;
oeq[oi] &= side;
}
while (eq[i] == mask);
if (merge && !eq[s]) {
array part = ({});
do part += ({arr[s++]}); while (!eq[s]);
switch (which) {
case 0: ai = s; ares[-1] += part; break;
case 1: bi = s; bres[-1] += part; break;
case 2: ci = s; cres[-1] += part; break;
}
}
}
|
04a1a8 | 1998-11-30 | Martin Stjernholm | |
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | if (aeq[ai] == 2 && beq[bi] == 1) {
do apart += ({a[ai++]}), bi++; while (aeq[ai] == 2 && beq[bi] == 1);
bpart = apart;
while (!ceq[ci]) cpart += ({c[ci++]});
prevodd = 2;
}
else if (beq[bi] == 2 && ceq[ci] == 1) {
do bpart += ({b[bi++]}), ci++; while (beq[bi] == 2 && ceq[ci] == 1);
cpart = bpart;
while (!aeq[ai]) apart += ({a[ai++]});
prevodd = 0;
}
else if (ceq[ci] == 2 && aeq[ai] == 1) {
do cpart += ({c[ci++]}), ai++; while (ceq[ci] == 2 && aeq[ai] == 1);
apart = cpart;
while (!beq[bi]) bpart += ({b[bi++]});
prevodd = 1;
|
04a1a8 | 1998-11-30 | Martin Stjernholm | | }
|
54e28f | 1999-05-31 | Martin Stjernholm | |
else if ((<1*2*3, 3*3*3>)[aeq[ai] * beq[bi] * ceq[ci]]) {
do apart += ({a[ai++]}), bi++, ci++;
while ((<0333, 0123, 0312, 0231>)[aeq[ai] << 6 | beq[bi] << 3 | ceq[ci]]);
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | cpart = bpart = apart;
|
bf779e | 2006-01-31 | Martin Stjernholm | | prevodd = -2;
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | }
|
54e28f | 1999-05-31 | Martin Stjernholm | |
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | else {
|
54e28f | 1999-05-31 | Martin Stjernholm | | switch (prevodd) {
case 0: apart = ares[-1], ares[-1] = ({}); break;
case 1: bpart = bres[-1], bres[-1] = ({}); break;
case 2: cpart = cres[-1], cres[-1] = ({}); break;
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | }
|
54e28f | 1999-05-31 | Martin Stjernholm | | prevodd = -1;
while (!aeq[ai]) apart += ({a[ai++]});
while (!beq[bi]) bpart += ({b[bi++]});
while (!ceq[ci]) cpart += ({c[ci++]});
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | }
|
34e2b3 | 1998-12-01 | Martin Stjernholm | |
|
54e28f | 1999-05-31 | Martin Stjernholm | |
|
f5c8ba | 1998-12-02 | Martin Stjernholm | | ares += ({apart}), bres += ({bpart}), cres += ({cpart});
|
04a1a8 | 1998-11-30 | Martin Stjernholm | | }
return ({ares, bres, cres});
}
|
edcae2 | 2001-07-30 | Johan Sundström | |
|
fe5844 | 2003-04-29 | Martin Nilsson | | int(-1..1) dwim_sort_func(string a, string b)
|
78762b | 1999-06-01 | Mirar (Pontus Hagland) | | {
|
20da98 | 2007-12-27 | Martin Nilsson | | if( a==b ) return 0;
string a_int,b_int;
string a_str,b_str;
while(1)
{
sscanf(a, "%[0-9]%[^0-9]%s", a_int,a_str,a);
sscanf(b, "%[0-9]%[^0-9]%s", b_int,b_str,b);
if( !sizeof(a_int) ^ !sizeof(b_int) )
return sizeof(a_int) ? -1 : 1;
if( a_int != b_int )
{
int ai = (int)a_int;
int bi = (int)b_int;
if( ai!=bi )
return ai<bi ? -1 : 1;
}
if( a_str != b_str )
return a_str<b_str ? -1 : 1;
if( !sizeof(a) || !sizeof(b) )
{
if( sizeof(a) ) return 1;
if( sizeof(b) ) return -1;
return 0;
}
}
|
78762b | 1999-06-01 | Mirar (Pontus Hagland) | | }
|
747358 | 1999-06-01 | Mirar (Pontus Hagland) | |
|
ff04e2 | 2001-07-15 | Per Hedbor | |
|
fe5844 | 2003-04-29 | Martin Nilsson | | int(-1..1) lyskom_sort_func(string a,string b)
|
747358 | 1999-06-01 | Mirar (Pontus Hagland) | | {
string a0=a,b0=b;
|
d228d5 | 1999-07-25 | Marcus Comstedt | | a=replace(lower_case(a),"][\\}{|"/1,"åäöåäö"/1);
b=replace(lower_case(b),"][\\}{|"/1,"åäöåäö"/1);
|
edcae2 | 2001-07-30 | Johan Sundström | |
|
747358 | 1999-06-01 | Mirar (Pontus Hagland) | | while (sscanf(a0=a,"%*[ \t](%*[^)])%*[ \t]%s",a)==4 && a0!=a);
while (sscanf(b0=b,"%*[ \t](%*[^)])%*[ \t]%s",b)==4 && b0!=b);
a0=b0="";
sscanf(a,"%[^ \t]%*[ \t](%*[^)])%*[ \t]%s",a,a0);
sscanf(b,"%[^ \t]%*[ \t](%*[^)])%*[ \t]%s",b,b0);
if (a>b) return 1;
|
fe5844 | 2003-04-29 | Martin Nilsson | | if (a<b) return -1;
|
747358 | 1999-06-01 | Mirar (Pontus Hagland) | | if (a0==b0) return 0;
return lyskom_sort_func(a0,b0);
}
|
13d6ac | 2000-05-03 | Fredrik Hübinette (Hubbe) | |
|
df8c5b | 2001-04-25 | Henrik Grubbström (Grubba) | |
|
ad34da | 2003-04-28 | Johan Sundström | |
|
f98720 | 2003-04-28 | Henrik Grubbström (Grubba) | |
|
e0d937 | 2003-04-28 | Henrik Grubbström (Grubba) | |
|
cfec3a | 2003-04-28 | Henrik Grubbström (Grubba) | | array flatten(array a, mapping(array:array)|void state)
|
13d6ac | 2000-05-03 | Fredrik Hübinette (Hubbe) | | {
|
f98720 | 2003-04-28 | Henrik Grubbström (Grubba) | | if (state && state[a]) return state[a];
if (!state) state = ([a:({})]);
else state[a] = ({});
|
efa498 | 2003-04-28 | Henrik Grubbström (Grubba) | | array res = allocate(sizeof(a));
foreach(a; int i; mixed b) {
res[i] = arrayp(b)?flatten([array]b, state):({b});
}
return state[a] = (res*({}));
|
13d6ac | 2000-05-03 | Fredrik Hübinette (Hubbe) | | }
|
a703e7 | 2001-04-25 | Mirar (Pontus Hagland) | |
|
fe5844 | 2003-04-29 | Martin Nilsson | |
|
a703e7 | 2001-04-25 | Mirar (Pontus Hagland) | | mixed sum(array a)
{
|
2fd538 | 2002-10-16 | Martin Nilsson | | if(a==({})) return 0;
|
2b007a | 2002-12-19 | Martin Nilsson | |
|
a703e7 | 2001-04-25 | Mirar (Pontus Hagland) | | if (sizeof(a)<1000)
return `+(@a);
else
|
df8c5b | 2001-04-25 | Henrik Grubbström (Grubba) | | {
|
a703e7 | 2001-04-25 | Mirar (Pontus Hagland) | | mixed mem=`+(@a[..999]);
int j=1000;
array v;
while (sizeof(v=a[j..j+999]))
mem=`+(mem,@v),j+=1000;
return mem;
}
}
|
229702 | 2001-05-19 | Mirar (Pontus Hagland) | |
|
edcae2 | 2001-07-30 | Johan Sundström | |
|
ff04e2 | 2001-07-15 | Per Hedbor | |
|
229702 | 2001-05-19 | Mirar (Pontus Hagland) | | array uniq2(array a)
{
array res;
mixed last;
if (!sizeof(a)) return ({});
res=({last=a[0]});
foreach (a,mixed v)
if (v!=last) last=v,res+=({v});
return res;
}
|
11e369 | 2001-06-06 | Mirar (Pontus Hagland) | |
|
2ad699 | 2001-07-30 | Johan Sundström | |
array arrayify(void|array|mixed x)
|
11e369 | 2001-06-06 | Mirar (Pontus Hagland) | | {
|
2ad699 | 2001-07-30 | Johan Sundström | | if(zero_type(x)) return ({});
|
d3ffb2 | 2002-03-20 | Martin Nilsson | | if(arrayp(x)) return [array]x;
|
2ad699 | 2001-07-30 | Johan Sundström | | return ({ x });
|
11e369 | 2001-06-06 | Mirar (Pontus Hagland) | | }
|
b51929 | 2001-08-28 | Honza Petrous | |
|
9614ff | 2007-12-27 | Martin Nilsson | |
|
2b007a | 2002-12-19 | Martin Nilsson | |
|
9614ff | 2007-12-27 | Martin Nilsson | | int(-1..1) oid_sort_func(string a, string b)
|
b51929 | 2001-08-28 | Honza Petrous | | {
int a1, b1;
|
9614ff | 2007-12-27 | Martin Nilsson | | sscanf(a, "%d.%s", a1, a);
sscanf(b, "%d.%s", b1, b);
|
b51929 | 2001-08-28 | Honza Petrous | | if (a1>b1) return 1;
|
9614ff | 2007-12-27 | Martin Nilsson | | if (a1<b1) return -1;
if (a==b) return 0;
return oid_sort_func(a,b);
|
b51929 | 2001-08-28 | Honza Petrous | | }
|
3bbf9a | 2002-03-18 | Johan Sundström | |
|
d3ffb2 | 2002-03-20 | Martin Nilsson | | static array(array(array)) low_greedy_diff(array(array) d1, array(array) d2)
|
3bbf9a | 2002-03-18 | Johan Sundström | | {
|
28aaf9 | 2002-03-18 | Henrik Grubbström (Grubba) | | array r1, r2, x, y, yb, b, c;
|
3bbf9a | 2002-03-18 | Johan Sundström | | r1 = r2 = ({});
int at, last, seen;
while(-1 != (at = search(d1, ({}), last)))
{
last = at + 1;
if(at < 2) continue;
b = d2[at-1]; yb = d2[at];
|
027574 | 2002-03-18 | Johan Sundström | | out:if(sizeof(yb) > sizeof(b))
|
3bbf9a | 2002-03-18 | Johan Sundström | | {
|
027574 | 2002-03-18 | Johan Sundström | | int i = sizeof(b), j = sizeof(yb);
while(i)
if(b[--i] != yb[--j])
break out;
|
3bbf9a | 2002-03-18 | Johan Sundström | | x = d2[at-2];
y = yb[..sizeof(yb)-sizeof(b)-1];
|
027574 | 2002-03-18 | Johan Sundström | | if(at+1 <= sizeof(d1))
|
3bbf9a | 2002-03-18 | Johan Sundström | | {
c = d2[at+1];
|
28aaf9 | 2002-03-18 | Henrik Grubbström (Grubba) | | array bc = b+c;
r1 += d1[seen..at-2] + ({ bc });
r2 += d2[seen..at-3] + ({ x+b+y }) + ({ bc });
|
3bbf9a | 2002-03-18 | Johan Sundström | | }
else
{
|
28aaf9 | 2002-03-18 | Henrik Grubbström (Grubba) | |
|
3bbf9a | 2002-03-18 | Johan Sundström | | r1 += d1[seen..at-2] + ({ b });
r2 += d2[seen..at-3] + ({ x+b+y }) + ({ b });
}
seen = at + 5;
}
}
|
28aaf9 | 2002-03-18 | Henrik Grubbström (Grubba) | | if(!seen)
return ({ d1, d2 });
|
d3ffb2 | 2002-03-20 | Martin Nilsson | | return ({ [array(array)]r1 + d1[seen..],
[array(array)]r2 + d2[seen..] });
|
3bbf9a | 2002-03-18 | Johan Sundström | | }
|
28aaf9 | 2002-03-18 | Henrik Grubbström (Grubba) | |
|
450986 | 2002-03-18 | Johan Sundström | |
|
e5ef06 | 2003-04-01 | Martin Nilsson | |
|
28aaf9 | 2002-03-18 | Henrik Grubbström (Grubba) | |
|
e5ef06 | 2003-04-01 | Martin Nilsson | |
|
d3ffb2 | 2002-03-20 | Martin Nilsson | | array(array(array)) greedy_diff(array from, array to)
|
28aaf9 | 2002-03-18 | Henrik Grubbström (Grubba) | | {
|
d3ffb2 | 2002-03-20 | Martin Nilsson | | array(array) d1, d2;
|
7e3446 | 2002-11-26 | Martin Nilsson | | [d1, d2] = diff(from, to);
|
450986 | 2002-03-18 | Johan Sundström | | [d2, d1] = low_greedy_diff(d2, d1);
return low_greedy_diff(d1, d2);
|
28aaf9 | 2002-03-18 | Henrik Grubbström (Grubba) | | }
|
9eb9b2 | 2002-04-17 | Martin Nilsson | |
|
95c68e | 2002-04-18 | Johan Sundström | |
|
c805a6 | 2002-04-18 | Johan Sundström | |
|
95c68e | 2002-04-18 | Johan Sundström | |
|
c805a6 | 2002-04-18 | Johan Sundström | |
|
95c68e | 2002-04-18 | Johan Sundström | | int|mapping(mixed:int) count(array|mapping|multiset haystack,
mixed|void needle)
|
c805a6 | 2002-04-18 | Johan Sundström | | {
if(zero_type(needle))
{
|
debf1b | 2002-05-15 | Henrik Grubbström (Grubba) | | mapping(mixed:int) res = ([]);
|
95c68e | 2002-04-18 | Johan Sundström | | if(mappingp(haystack))
|
debf1b | 2002-05-15 | Henrik Grubbström (Grubba) | | haystack = values([mapping]haystack);
foreach((array)haystack, mixed what)
|
c805a6 | 2002-04-18 | Johan Sundström | | res[what]++;
return res;
}
|
95c68e | 2002-04-18 | Johan Sundström | | return sizeof(filter(haystack, `==, needle));
|
c805a6 | 2002-04-18 | Johan Sundström | | }
|
02b531 | 2002-09-16 | Johan Schön | |
array common_prefix(array(array) arrs)
{
if(!sizeof(arrs))
|
b3884f | 2002-09-16 | Johan Schön | | return ({});
|
02b531 | 2002-09-16 | Johan Schön | |
array arrs0 = arrs[0];
int n, i;
catch
{
for(n = 0; n < sizeof(arrs0); n++)
for(i = 1; i < sizeof(arrs); i++)
if(!equal(arrs[i][n],arrs0[n]))
return arrs0[0..n-1];
};
return arrs0[0..n-1];
}
|
e259c2 | 2003-09-04 | Johan Sundström | |
|
f95c7a | 2003-09-05 | Johan Sundström | | int(0..1) all( array a, function(mixed, mixed ...:mixed) predicate,
|
7fd556 | 2003-09-04 | Martin Nilsson | | mixed ... extra_args )
|
e259c2 | 2003-09-04 | Johan Sundström | | {
foreach( a, mixed elem )
if( !predicate( elem, @extra_args ) )
return 0;
return 1;
}
|
f95c7a | 2003-09-05 | Johan Sundström | | int(0..1) any( array a, function(mixed, mixed ...:mixed) predicate,
|
7fd556 | 2003-09-04 | Martin Nilsson | | mixed ... extra_args )
|
e259c2 | 2003-09-04 | Johan Sundström | | {
foreach( a, mixed elem )
if( predicate( elem, @extra_args ) )
return 1;
return 0;
}
|
4d218b | 2003-09-04 | Johan Sundström | |
|
00d380 | 2003-09-06 | Johan Sundström | |
|
4d218b | 2003-09-04 | Johan Sundström | |
|
f95c7a | 2003-09-05 | Johan Sundström | | array(array) partition( array a, function(mixed, mixed ...:mixed) arbiter,
|
7fd556 | 2003-09-04 | Martin Nilsson | | mixed ... extra_args )
|
4d218b | 2003-09-04 | Johan Sundström | | {
array first = ({}), second = ({});
foreach( a, mixed elem )
if( arbiter( elem, @extra_args ) )
first += ({ elem });
else
second += ({ elem });
return ({ first, second });
}
|
d4f8f2 | 2005-09-26 | H. William Welliver III | |
array push(array list, mixed element) {
return list + ({ element });
}
array pop(array list) {
if (sizeof(list) == 1)
return ({ list[0], ({}) });
else if (sizeof(list) > 1) {
mixed elem = list[sizeof(list)-1];
|
8a531a | 2006-11-04 | Martin Nilsson | | list = list[..<1];
|
d4f8f2 | 2005-09-26 | H. William Welliver III | | return ({ elem, list });
}
}
array shift(array list) {
if (sizeof(list))
return ({ list[0], list[1..] });
else
return 0;
}
array unshift(array list, mixed element) {
return ({ element }) + list;
}
|