Like this? ([1:2,3:4,17:42])-({1}); (2) Result: ([ /* 2 elements */ 3: 4, 17: 42 ])
More like ([ 1:2, 3:4, 17:42 ]) - ({ 1, 3 }); but as in the result, yes. As in performance (okay, could test only under pike 7.4) the m_delete is much faster.
Testcode: array qresult = db->query("SELECT * FROM cvs_db_edit.search AS s ORDER BY utime_modified DESC LIMIT 1000"); array remove_indices = predef::filter(indices(qresult[0]), has_value, '.');
int aa_time; array qresult2; int a_time = gethrtime(); for (int i=0; i<1000; i++) { aa_time = gethrtime(); qresult2 = copy_value(qresult); a_time += (gethrtime()-aa_time); for (int i=0; i<sizeof(qresult2); i++) { qresult2[i] -= remove_indices; } } int b_time = gethrtime(); for (int i=0; i<1000; i++) { aa_time = gethrtime(); qresult2 = copy_value(qresult); b_time += (gethrtime()-aa_time); function l = lambda(string s, mapping m){m_delete(m,s);}; for (int i=0; i<sizeof(qresult2); i++) { map(remove_indices, l, qresult2[i]); } } int c_time = gethrtime(); for (int i=0; i<1000; i++) { aa_time = gethrtime(); qresult2 = copy_value(qresult); c_time += (gethrtime()-aa_time); for (int i=0; i<sizeof(qresult2); i++) { foreach(remove_indices, string idx) { m_delete(qresult2[i], idx); } } } int d_time = gethrtime(); for (int i=0; i<1000; i++) { aa_time = gethrtime(); qresult2 = copy_value(qresult); d_time += (gethrtime()-aa_time); for (int i=0; i<sizeof(qresult2); i++) { foreach(remove_indices;; string idx) { m_delete(qresult2[i], idx); } } } int e_time = gethrtime(); for (int i=0; i<1000; i++) { aa_time = gethrtime(); qresult2 = copy_value(qresult); e_time += (gethrtime()-aa_time); for (int i=0; i<sizeof(qresult2); i++) { m_delete(qresult2[i], remove_indices[*]); } } int f_time = gethrtime();
Stdio.stdout->write("1 took %.2f msec\n", (b_time-a_time)/1000.00); Stdio.stdout->write("2 took %.2f msec\n", (c_time-b_time)/1000.00); Stdio.stdout->write("3 took %.2f msec\n", (d_time-c_time)/1000.00); Stdio.stdout->write("4 took %.2f msec\n", (e_time-d_time)/1000.00); Stdio.stdout->write("5 took %.2f msec\n", (f_time-e_time)/1000.00);
Output: 1 took 19373.84 msec 2 took 11036.73 msec 3 took 7440.38 msec 4 took 7604.60 msec 5 took 7065.02 msec
I must admit I did not verify if the result is what it's supposed to be.
Regards,
Arjan