Update of /cvsroot/monetdb/sql/src/common
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17711/common

Modified Files:
        sql_list.mx 
Log Message:
removed ugly e_exp and e_relation
added new flags DISTINCT, NO_NIL and ASCENDING 
add a few new list functions used by the relational version


Index: sql_list.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/common/sql_list.mx,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- sql_list.mx 11 Jan 2008 10:52:10 -0000      1.15
+++ sql_list.mx 27 Jan 2008 15:19:59 -0000      1.16
@@ -218,6 +218,55 @@
        return res;
 }
 
+int
+list_match(list *l1, list *l2, fcmp cmp)
+{
+       node *n, *m;
+       int chk = 0;
+
+       if (l1 == l2)
+               return 0;
+
+       if (!l1 || !l2 || (list_length(l1) != list_length(l2)))
+               return -1;
+
+       for (n = l1->h; n; n = n->next) {
+               int pos = 0, fnd = 0;
+               for (m = l2->h; m; m = m->next, pos++) {
+                       if (!(chk&(1<<pos)) && cmp(n->data, m->data) == 0) {
+                               chk &= 1<<pos;
+                               fnd = 1;
+                       }
+               }
+               if (!fnd)
+                       return -1;
+       }
+       return 0;
+}
+
+list *
+list_sort(list *l, fkeyvalue key, fdup dup)
+{
+       list *res = list_create(l->destroy);
+       node *n = NULL;
+       int i, j, *keys, *pos, cnt = list_length(l);
+
+       keys = (int*)alloca(cnt*sizeof(int));
+       pos = (int*)alloca(cnt*sizeof(int));
+       for (n = l->h, i = 0; n; n = n->next, i++) {
+               keys[i] = key(n->data);
+               pos[i] = i;
+       }
+       /* sort descending */
+       GDKqsort_rev(keys, pos, NULL, cnt, sizeof(int), sizeof(int), TYPE_int);
+       for(j=0; j<cnt; j++) {
+               for(n = l->h, i = 0; n && i != pos[j]; n = n->next, i++) 
+                       ;
+               list_append(res, dup(n->data));
+       }
+       return res;
+}
+
 list *
 list_select(list *l, void *key, fcmp cmp, fdup dup)
 {
@@ -256,7 +305,6 @@
        return res;
 }
 
-
 list *
 list_distinct(list *l, fcmp cmp, fdup dup)
 {
@@ -271,6 +319,35 @@
        return res;
 }
 
+static node *
+list_find2(list *l, void *data, void *key, fcmp2 cmp)
+{
+       node *n = NULL;
+
+       if (key) {
+               for (n = l->h; n; n = n->next) {
+                       if (cmp(data, n->data, key) == 0) {
+                               return n;
+                       }
+               }
+       }
+       return NULL;
+}
+
+list *
+list_distinct2(list *l, void *data, fcmp2 cmp, fdup dup)
+{
+       list *res = list_create(l->destroy);
+       node *n = NULL;
+
+       for (n = l->h; n; n = n->next) {
+               if (!list_find2(res, data, n->data, cmp)) {
+                       list_append(res, dup(n->data));
+               }
+       }
+       return res;
+}
+
 void *
 list_reduce(list *l, freduce red, fdup dup)
 {
@@ -296,7 +373,8 @@
        while (n) {
                void *v = map(n->data, data);
 
-               list_append(res, v);
+               if (v)
+                       list_append(res, v);
                n = n->next;
        }
        return res;


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to