Changeset: fe8414af420e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fe8414af420e
Modified Files:
gdk/gdk.h
gdk/gdk_col.c
gdk/gdk_heap.c
gdk/gdk_private.h
gdk/gdk_setop.c
monetdb5/extras/crackers/crackers_sortmerge.mx
Branch: headless
Log Message:
Various changes, see below.
- COLelement() now returns a void * (since you need to cast it anyway).
- COLkey(), COLmode(), COLcol_name(), COLseqbase(), COLpropcheck() now
return GDK_FAIL or GDK_SUCCEED (not that anybody was listening).
- small fix in COLunique_select().
- various other mostly cosmetic changes.
diffs (truncated from 635 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1021,7 +1021,6 @@
gdk_export COL *COLnewdensecol(oid size);
/* internal */
-gdk_export COL *COLcreatedesc(int tp, int heapnames);
gdk_export chr ATOMelmshift(int sz);
/*
@@ -1435,7 +1434,7 @@
/* new semantics ! */
#define headsize(b,p) ((b)->type?((size_t)(p))<<(b)->shift:0)
-#define COLelement(b, p) ((char*)(b)->heap.base+((p)<<(b)->shift))
+#define COLelement(b, p)
((void*)((char*)(b)->heap.base+((p)<<(b)->shift)))
#if SIZEOF_VAR_T < SIZEOF_VOID_P
/* NEW 11/4/2009: when compiled with 32-bits oids/var_t on 64-bits
@@ -1586,11 +1585,11 @@
gdk_export void COLsetcapacity(COL *b, oid cnt);
gdk_export void COLsetcount(COL *b, oid cnt);
gdk_export oid COLgrows(COL *b);
-gdk_export COL *COLkey(COL *b, int onoff);
-gdk_export COL *COLmode(COL *b, int onoff);
-gdk_export COL *COLcol_name(COL *b, const char *nme);
+gdk_export int COLkey(COL *b, int onoff);
+gdk_export int COLmode(COL *b, int onoff);
+gdk_export int COLcol_name(COL *b, const char *nme);
gdk_export int COLname(COL *b, const char *nme);
-gdk_export COL *COLseqbase(COL *b, oid o);
+gdk_export int COLseqbase(COL *b, oid o);
gdk_export COL *COLsetaccess(COL *b, int mode);
gdk_export void COLsetreadonly(COL *b);
gdk_export int COLgetaccess(COL *b);
@@ -2849,7 +2848,7 @@
*/
gdk_export int ALIGNsynced(COL *b1, COL *b2);
-gdk_export COL *COLpropcheck(COL *b, int mode);
+gdk_export int COLpropcheck(COL *b, int mode);
#define COLPROPS_QUICK 0 /* only derive easy (non-resource consuming)
properties */
#define COLPROPS_ALL 1 /* derive all possible properties; no matter
what cost (key=hash) */
diff --git a/gdk/gdk_col.c b/gdk/gdk_col.c
--- a/gdk/gdk_col.c
+++ b/gdk/gdk_col.c
@@ -430,18 +430,11 @@
COLclear(COL *b)
{
oid p, q;
- int voidbat;
COLcheck(b, "COLclear");
- voidbat = 0;
-
- if (COLdense(b) && b->type == TYPE_void) {
- voidbat = 1;
- }
-
/* small COL: delete all elements by hand */
- if (!voidbat && b->count < 20) {
+ if (b->type != TYPE_void && b->count < 20) {
COLloopDEL(b, p, q) {
p = BUNdelete(b, p, FALSE);
}
@@ -719,23 +712,28 @@
/* case (2): a void result => nothing to copy! */
bn->heap.free = 0;
} else if (bunstocopy == BUN_NONE) {
- /* case (3): just copy the heaps; if possible with
copy-on-write VM support */
- int remap = writable == 2;
- int hremap = remap && COLrestricted(b) != COL_WRITE &&
ht != TYPE_void;
- int hvremap = hremap && ATOMstorage(ht) == TYPE_str &&
!GDK_ELIMDOUBLES(b->vheap);
+ /* case (3): just copy the heaps; if possible
+ * with copy-on-write VM support */
+ int remap = writable == 2 &&
+ COLrestricted(b) != COL_WRITE &&
+ ht != TYPE_void;
+ int vremap = remap &&
+ ATOMstorage(ht) == TYPE_str &&
+ !GDK_ELIMDOUBLES(b->vheap);
oid cap = 0;
Heap bhhp, hhp;
memset(&bhhp, 0, sizeof(Heap));
memset(&hhp, 0, sizeof(Heap));
- if ((b->type && heapcopy(bn, "tail", &bhhp, &b->heap,
&hremap) < 0) ||
- (bn->vheap && heapcopy(bn, "theap", &hhp, b->vheap,
&hvremap) < 0)) {
+ if ((b->type && heapcopy(bn, "tail", &bhhp, &b->heap,
&remap) < 0) ||
+ (bn->vheap && heapcopy(bn, "theap", &hhp, b->vheap,
&vremap) < 0)) {
HEAPfree(&hhp);
HEAPfree(&bhhp);
CBPreclaim(bn);
return NULL;
}
- /* succeeded; replace dummy small heaps by the real
ones */
+ /* succeeded; replace dummy small heaps by the
+ * real ones */
heapfree(&bn->heap, &bhhp);
hhp.parentid = bn->cacheid;
if (bn->vheap)
@@ -745,12 +743,15 @@
cap = (oid) (bn->type ? bn->heap.size >> bn->shift : 0);
bn->capacity = cap;
- /* first/inserted must point equally far into the heap
as in the source */
+ /* first/inserted must point equally far into
+ * the heap as in the source */
bn->first = b->first;
bn->inserted = b->inserted;
- /* if we have copy-on-write heaps, bn is a logical view
on b to ensure the heaps stay stable */
- if (hremap || hvremap) {
+ /* if we have copy-on-write heaps, bn is a
+ * logical view on b to ensure the heaps stay
+ * stable */
+ if (remap || vremap) {
bn->lview = TRUE;
CBPshare(bn->heap.parentid = b->cacheid);
}
@@ -778,9 +779,8 @@
} else {
/* case (4): optimized for simple array copy */
int tpe = ATOMstorage(ht);
- oid p = b->first;
- char *cur = COLelement(b, p);
- char *d = COLelement(bn, 0);
+ void *cur = COLelement(b, b->first);
+ void *d = COLelement(bn, 0);
bn->heap.free = bunstocopy * bn->width;
@@ -881,19 +881,18 @@
oid
MAXoid(COL *i)
{
- COLiter ii = col_iterator(i);
oid o = i->seqbase - 1;
if (i->count) {
if (i->revsorted)
- o = *(oid *) BUNhead(ii, i->first);
+ o = COLget_OID(i, 0);
else {
- o = *(oid *) BUNhead(ii, COLlast(i) - 1);
+ o = COLget_OID(i, i->count - 1);
if (!i->sorted) {
- oid r, s, v;
+ oid r, v;
- COLloop(i, r, s) {
- if ((v = *(oid *) BUNhead(ii, r)) > o)
+ for (r = 0; r < i->count; i++) {
+ if ((v = COLget_OID(i, r)) > o)
o = v;
}
}
@@ -909,8 +908,10 @@
* using the BUNappendCheck.
*/
int
-BUNappendCheck(COL *b, oid incr){
- if ( (lng)(COLlast(b)) + incr >= (lng) BUN_MAX || (lng)(b->count) ==
(lng) BUN_MAX ) {
+BUNappendCheck(COL *b, oid incr)
+{
+ assert(incr <= BUN_MAX); /* i.e. not BUN_NONE */
+ if (COLlast(b) >= BUN_MAX - incr) {
GDKerror("BUNappend: column becomes too large for this
system\n");
return -1;
}
@@ -921,7 +922,6 @@
BUNappend(COL *b, ptr t, bit force)
{
oid i;
- oid p;
int countonly;
size_t tsize = 0;
@@ -931,25 +931,24 @@
return b;
}
- p = COLlast(b); /* insert at end */
- if ( BUNappendCheck(b, 1) )
+ if (BUNappendCheck(b, 1))
return NULL;
- i = p;
+ i = COLlast(b); /* insert at end */
ALIGNapp(b, "BUNappend", force);
b->dirty = 1;
countonly = b->type == TYPE_void;
if (b->hash && b->vheap)
tsize = b->vheap->size;
- if (p > b->first) {
+ if (b->count > 0) {
COLiter bi = col_iterator(b);
if (b->type != TYPE_void) {
- int cmp = 0;
+ int cmp;
if (b->sorted) {
- ptr prv = BUNhead(bi, p - 1);
+ ptr prv = BUNhead(bi, i - 1);
cmp = atom_CMP(t, prv, b->type);
if (cmp < 0) {
@@ -960,7 +959,8 @@
b->nodense = i;
}
} else if (cmp > 0) {
- if (b->dense && *(oid *) t != 1 + *(oid
*) prv) {
+ if (b->dense &&
+ *(oid *) prv + 1 != *(oid *) t) {
b->nodense = i;
b->dense = FALSE;
}
@@ -995,7 +995,7 @@
b->dense = FALSE;
}
} else if (b->revsorted) {
- ptr prv = BUNhead(bi, p - 1);
+ ptr prv = BUNhead(bi, i - 1);
cmp = atom_CMP(t, prv, b->type);
if (cmp > 0) {
@@ -1467,7 +1467,7 @@
* association head.
*
*/
-COL *
+int
COLkey(COL *b, int flag)
{
bat parent;
@@ -1477,12 +1477,14 @@
if (b->type == TYPE_void) {
if (b->seqbase == oid_nil && flag == BOUND2BTRUE) {
GDKerror("COLkey: nil-column cannot be kept unique.\n");
+ return GDK_FAIL;
}
if (b->seqbase != oid_nil && flag == FALSE) {
GDKerror("COLkey: dense column must be unique.\n");
+ return GDK_FAIL;
}
if (b->seqbase == oid_nil || flag == FALSE) {
- return b;
+ return GDK_SUCCEED;
}
}
if (flag)
@@ -1493,12 +1495,12 @@
if (!flag)
b->dense = 0;
if (flag && parent && ALIGNsynced(b, CBP_cache(parent)))
- COLkey(CBP_cache(parent), TRUE);
- return b;
+ return COLkey(CBP_cache(parent), TRUE);
+ return GDK_SUCCEED;
}
-COL *
+int
COLseqbase(COL *b, oid o)
{
COLcheck(b, "COLseqbase");
@@ -1528,7 +1530,7 @@
}
}
}
- return b;
+ return GDK_SUCCEED;
}
/*
@@ -1568,7 +1570,7 @@
}
-COL *
+int
COLcol_name(COL *b, const char *nme)
{
COLcheck(b, "COLcol_name");
@@ -1578,7 +1580,7 @@
b->id = GDKstrdup(nme);
else
b->id = COLstring;
- return b;
+ return GDK_SUCCEED;
}
/*
@@ -1655,7 +1657,7 @@
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list