Changeset: 9e3b6795954c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9e3b6795954c Modified Files: gdk/gdk_firstn.c monetdb5/mal/mal_linker.c Branch: default Log Message:
Merge with Jul2017 branch. diffs (69 lines): diff --git a/gdk/gdk_firstn.c b/gdk/gdk_firstn.c --- a/gdk/gdk_firstn.c +++ b/gdk/gdk_firstn.c @@ -422,25 +422,48 @@ BATfirstn_unique_with_groups(BAT *b, BAT oid item; BUN pos, childpos; - if (BATtdense(g)) { - /* trivial: g determines ordering, return initial - * slice of s */ - return BATslice(s, 0, n); - } - CANDINIT(b, s, start, end, cnt, cand, candend); + cnt = cand ? (BUN) (candend - cand) : end - start; if (n > cnt) n = cnt; - if (cand && n > (BUN) (candend - cand)) - n = (BUN) (candend - cand); if (n == 0) { /* candidate list might refer only to values outside * of the bat and hence be effectively empty */ + if (lastp) + *lastp = 0; + if (lastgp) + *lastgp = 0; return BATdense(0, 0, 0); } + if (BATtdense(g)) { + /* trivial: g determines ordering, return reference to + * initial part of b (or slice of s) */ + if (lastgp) + *lastgp = g->tseqbase + n - 1; + if (cand) { + if (lastp) + *lastp = cand[n - 1]; + bn = COLnew(0, TYPE_oid, n, TRANSIENT); + if (bn == NULL) + return NULL; + memcpy(Tloc(bn, 0), cand, n * sizeof(oid)); + BATsetcount(bn, n); + bn->tsorted = 1; + bn->trevsorted = n <= 1; + bn->tkey = 1; + bn->tseqbase = (bn->tdense = n <= 1) != 0 ? cand[0] : oid_nil; + bn->tnil = 0; + bn->tnonil = 1; + return bn; + } + if (lastp) + *lastp = b->hseqbase + start + n - 1; + return BATdense(0, b->hseqbase + start, n); + } + bn = COLnew(0, TYPE_oid, n, TRANSIENT); if (bn == NULL) return NULL; @@ -763,7 +786,7 @@ BATfirstn_grouped_with_groups(BAT **topn BBPunfix(bn1->batCacheid); return GDK_FAIL; } - bn4 = BATselect(b, bn3, BUNtail(bi, BUNlast(b) - b->hseqbase), NULL, 1, 0, 0); + bn4 = BATselect(b, bn3, BUNtail(bi, last - b->hseqbase), NULL, 1, 0, 0); BBPunfix(bn3->batCacheid); if (bn4 == NULL) { BBPunfix(bn1->batCacheid); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list