Changeset: d0f4b2dc4565 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d0f4b2dc4565
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        clients/Tests/exports.stable.out
        gdk/ChangeLog
        gdk/gdk.h
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        monetdb5/ChangeLog
        monetdb5/modules/kernel/bat5.c
        monetdb5/modules/kernel/bat5.h
        monetdb5/modules/kernel/bat5.mal
        monetdb5/modules/mal/Tests/inspect05.stable.out
        monetdb5/modules/mal/Tests/inspect05.stable.out.int128
Branch: default
Log Message:

Reimplemented bat.delete with two arguments.


diffs (truncated from 637 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -30848,6 +30848,14 @@ command bat.delete(b:bat[:oid,:any_1]):b
 address BKCdelete_all;
 comment Delete all entries.
 
+command bat.delete(b:bat[:oid,:any_1],d:bat[:oid,:oid]):bat[:oid,:any_1] 
+address BKCdelete_multi;
+comment Delete multiple BUN, shifting BUNs up
+
+command bat.delete(b:bat[:oid,:any_1],h:oid):bat[:oid,:any_1] 
+address BKCdelete;
+comment Delete BUN indicated by head value, exchanging with last BUN
+
 command bat.getName(b:bat[:oid,:any_1]):str 
 address BKCgetBBPname;
 comment Gives back the logical name of a BAT.
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -39817,6 +39817,14 @@ command bat.delete(b:bat[:oid,:any_1]):b
 address BKCdelete_all;
 comment Delete all entries.
 
+command bat.delete(b:bat[:oid,:any_1],d:bat[:oid,:oid]):bat[:oid,:any_1] 
+address BKCdelete_multi;
+comment Delete multiple BUN, shifting BUNs up
+
+command bat.delete(b:bat[:oid,:any_1],h:oid):bat[:oid,:any_1] 
+address BKCdelete;
+comment Delete BUN indicated by head value, exchanging with last BUN
+
 command bat.getName(b:bat[:oid,:any_1]):str 
 address BKCgetBBPname;
 comment Gives back the logical name of a BAT.
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -106,6 +106,7 @@ BAT *BATconst(BAT *l, int tt, const void
 BAT *BATconstant(int tt, const void *val, BUN cnt, int role);
 BAT *BATconvert(BAT *b, BAT *s, int tp, int abort_on_error);
 BUN BATcount_no_nil(BAT *b);
+gdk_return BATdel(BAT *b, BAT *d);
 BAT *BATdense(oid hseq, oid tseq, BUN cnt) __attribute__((warn_unused_result));
 void BATderiveProps(BAT *b, int expensive);
 void BATderiveTailProps(BAT *b, int expensive);
@@ -199,6 +200,7 @@ void BBPshare(bat b);
 gdk_return BBPsync(int cnt, bat *subcommit);
 void BBPunlock(const char *s);
 gdk_return BUNappend(BAT *b, const void *right, bit force);
+gdk_return BUNdelete(BAT *b, oid o);
 BUN BUNfnd(BAT *b, const void *right);
 gdk_return BUNinplace(BAT *b, BUN p, const void *right, bit force);
 BAT *COLcopy(BAT *b, int tt, int writeable, int role);
@@ -759,7 +761,9 @@ str BKCbat_inplace(bat *r, const bat *bi
 str BKCbat_inplace_force(bat *r, const bat *bid, const bat *rid, const bat 
*uid, const bit *force);
 str BKCbun_inplace(bat *r, const bat *bid, const oid *id, const void *t);
 str BKCbun_inplace_force(bat *r, const bat *bid, const oid *id, const void *t, 
const bit *force);
+str BKCdelete(bat *r, const bat *bid, const oid *h);
 str BKCdelete_all(bat *r, const bat *bid);
+str BKCdelete_multi(bat *r, const bat *bid, const bat *sid);
 str BKCdensebat(bat *ret, const wrd *size);
 str BKCgetAccess(str *res, const bat *bid);
 str BKCgetBBPname(str *ret, const bat *bid);
diff --git a/gdk/ChangeLog b/gdk/ChangeLog
--- a/gdk/ChangeLog
+++ b/gdk/ChangeLog
@@ -2,6 +2,12 @@
 # This file is updated with Maddlog
 
 * Fri Dec 18 2015 Sjoerd Mullender <sjo...@acm.org>
+- BUNdelete and BATdel don't accept a foce argument and only allow
+  deleting values that have not yet been committed.  BUNdelete exchanges
+  the deleted value with the last value (if the deleted value isn't the
+  last value).  BATdel compacts the BAT by shifting values after the
+  deleted values up.  The list of to-be-deleted values in BATdel must
+  be sorted and unique.
 - Removed BUNreplace from list of exported functions.  It wasn't used,
   and there is still BUNinplace and void_inplace that do more-or-less
   the same thing.
@@ -11,9 +17,6 @@
   the tail column).
 - Removed unused functions BATalpha, BATdelta, and BATprev.
 
-* Mon Dec 14 2015 Sjoerd Mullender <sjo...@acm.org>
-- Removed functions BATins, BATdel, BUNdel and BUNdelete.
-
 * Fri Dec 11 2015 Sjoerd Mullender <sjo...@acm.org>
 - Removed function VIEWcombine.  Use BATdense instead.
 - Removed "left" parameter from BUNinplace.  It wasn't used since the
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1258,6 +1258,9 @@ gdk_export gdk_return GDKupgradevarheap(
 gdk_export gdk_return BUNappend(BAT *b, const void *right, bit force);
 gdk_export gdk_return BATappend(BAT *b, BAT *c, bit force);
 
+gdk_export gdk_return BUNdelete(BAT *b, oid o);
+gdk_export gdk_return BATdel(BAT *b, BAT *d);
+
 gdk_export gdk_return BUNinplace(BAT *b, BUN p, const void *right, bit force);
 gdk_export gdk_return BATreplace(BAT *b, BAT *p, BAT *n, bit force);
 
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -1035,6 +1035,50 @@ BUNappend(BAT *b, const void *t, bit for
        return GDK_FAIL;
 }
 
+gdk_return
+BUNdelete(BAT *b, oid o)
+{
+       BUN p;
+       BATiter bi = bat_iterator(b);
+
+       assert(b->htype == TYPE_void);
+       assert(b->hseqbase != oid_nil || BATcount(b) == 0);
+       if (o < b->hseqbase || o >= b->hseqbase + BATcount(b)) {
+               /* value already not there */
+               return GDK_SUCCEED;
+       }
+       assert(BATcount(b) > 0); /* follows from "if" above */
+       p = o - b->hseqbase + BUNfirst(b);
+       if (p < b->batInserted) {
+               GDKerror("BUNdelete: cannot delete committed value\n");
+               return GDK_FAIL;
+       }
+       b->batDirty = 1;
+       ATOMunfix(b->ttype, BUNtail(bi, p));
+       ATOMdel(b->ttype, b->T->vheap, (var_t *) BUNtloc(bi, p));
+       if (p != BUNlast(b) - 1 &&
+           (b->ttype != TYPE_void || b->tseqbase != oid_nil)) {
+               /* replace to-be-delete BUN with last BUN; materialize
+                * void column before doing so */
+               if (b->ttype == TYPE_void &&
+                   BATmaterialize(b) != GDK_SUCCEED)
+                       return GDK_FAIL;
+               memcpy(Tloc(b, p), Tloc(b, BUNlast(b) - 1), Tsize(b));
+               /* no longer sorted */
+               b->tsorted = b->trevsorted = 0;
+       }
+       b->batCount--;
+       if (b->batCount <= 1) {
+               /* some trivial properties */
+               b->tkey |= 1;
+               b->tsorted = b->trevsorted = 1;
+               if (b->batCount == 0) {
+                       b->T->nil = 0;
+                       b->T->nonil = 1;
+               }
+       }
+       return GDK_SUCCEED;
+}
 
 /* @-  BUN replace
  * The last operation in this context is BUN replace. It assumes that
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -569,6 +569,115 @@ BATappend(BAT *b, BAT *n, bit force)
        return GDK_FAIL;
 }
 
+gdk_return
+BATdel(BAT *b, BAT *d)
+{
+       int (*unfix) (const void *) = BATatoms[b->ttype].atomUnfix;
+       void (*atmdel) (Heap *, var_t *) = BATatoms[b->ttype].atomDel;
+       BATiter bi = bat_iterator(b);
+
+       assert(BAThdense(b));
+       assert(BAThdense(d));
+       assert(ATOMtype(d->ttype) == TYPE_oid);
+       assert(d->tsorted);
+       assert(d->tkey & 1);
+       if (BATcount(d) == 0)
+               return GDK_SUCCEED;
+       if (BATtdense(d)) {
+               oid o = d->tseqbase;
+               BUN c = BATcount(d);
+
+               if (o + c <= b->hseqbase)
+                       return GDK_SUCCEED;
+               if (o < b->hseqbase) {
+                       c -= b->hseqbase - o;
+                       o = b->hseqbase;
+               }
+               if (o - b->hseqbase + BUNfirst(b) < b->batInserted) {
+                       GDKerror("BATdelete: cannot delete committed values\n");
+                       return GDK_FAIL;
+               }
+               if (o + c > b->hseqbase + BATcount(b))
+                       c = b->hseqbase + BATcount(b) - o;
+               if (c == 0)
+                       return GDK_SUCCEED;
+               if (unfix || atmdel) {
+                       BUN p = o - b->hseqbase + BUNfirst(b);
+                       BUN q = p + c;
+                       while (p < q) {
+                               if (unfix)
+                                       (*unfix)(BUNtail(bi, p));
+                               if (atmdel)
+                                       (*atmdel)(b->T->vheap, (var_t *) 
BUNtloc(bi, p));
+                               p++;
+                       }
+               }
+               if (BATtdense(b) && BATmaterialize(b) != GDK_SUCCEED)
+                       return GDK_FAIL;
+               if (o + c < b->hseqbase + BATcount(b)) {
+                       memmove(Tloc(b, o - b->hseqbase + BUNfirst(b)),
+                               Tloc(b, o + c - b->hseqbase + BUNfirst(b)),
+                               Tsize(b) * (BATcount(b) - (o + c - 
b->hseqbase)));
+               }
+               b->batCount -= c;
+       } else {
+               const oid *o = (const oid *) Tloc(d, BUNfirst(d));
+               const oid *s;
+               BUN c = BATcount(d);
+               BUN nd = 0;
+               char *p;
+
+               if (o[c - 1] <= b->hseqbase)
+                       return GDK_SUCCEED;
+               while (*o < b->hseqbase) {
+                       o++;
+                       c--;
+               }
+               if (*o - b->hseqbase + BUNfirst(b) < b->batInserted) {
+                       GDKerror("BATdelete: cannot delete committed values\n");
+                       return GDK_FAIL;
+               }
+               if (BATtdense(b) && BATmaterialize(b) != GDK_SUCCEED)
+                       return GDK_FAIL;
+               s = o;
+               p = Tloc(b, *o - b->hseqbase + BUNfirst(b));
+               while (c > 0 && *o < b->hseqbase + BATcount(b)) {
+                       size_t n;
+                       if (unfix)
+                               (*unfix)(BUNtail(bi, *o - b->hseqbase + 
BUNfirst(b)));
+                       if (atmdel)
+                               (*atmdel)(b->T->vheap, (var_t *) BUNtloc(bi, *o 
- b->hseqbase + BUNfirst(b)));
+                       o++;
+                       c--;
+                       nd++;
+                       if (c == 0 || *o - b->hseqbase >= BATcount(b))
+                               n = b->hseqbase + BATcount(b) - o[-1] - 1;
+                       else if ((oid) (o - s) > *o - *s)
+                               n = o[0] - o[-1] - 1;
+                       else
+                               n = 0;
+                       if (n > 0) {
+                               n *= Tsize(b);
+                               memmove(p,
+                                       Tloc(b, o[-1] + 1 - b->hseqbase + 
BUNfirst(b)),
+                                       n);
+                               p += n;
+                               s = o;
+                       }
+               }
+               b->batCount -= nd;
+       }
+       if (b->batCount <= 1) {
+               /* some trivial properties */
+               b->tkey |= 1;
+               b->tsorted = b->trevsorted = 1;
+               if (b->batCount == 0) {
+                       b->T->nil = 0;
+                       b->T->nonil = 1;
+               }
+       }
+       return GDK_SUCCEED;
+}
 
 #define TYPEcheck(t1,t2,func)                                          \
        do {                                                            \
diff --git a/monetdb5/ChangeLog b/monetdb5/ChangeLog
--- a/monetdb5/ChangeLog
+++ b/monetdb5/ChangeLog
@@ -6,9 +6,6 @@
   mat. newIterator, mat.project, mat.pack2, mat.sortReverse, mat.sort,
   and mat.slice.
 
-* Mon Dec 14 2015 Sjoerd Mullender <sjo...@acm.org>
-- Removed bat.delete with more than one argument.
-
 * Thu Dec 10 2015 Sjoerd Mullender <sjo...@acm.org>
 - Removed grouped aggregate functions from the aggr module in which the
   groups were indicated by the head column of the bat to be aggregated.
diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -240,6 +240,45 @@ BKCmirror(bat *ret, const bat *bid)
        throw(MAL, "bat.mirror", GDK_EXCEPTION);
 }
 
+char *
+BKCdelete(bat *r, const bat *bid, const oid *h)
+{
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to