Changeset: 9ee739b9f5cd for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9ee739b9f5cd
Modified Files:
        monetdb5/extras/crackers/Makefile.ag
        monetdb5/extras/crackers/crackers.mx
        monetdb5/extras/crackers/crackers_select_ops.mx
Branch: holindex
Log Message:

Updates: fix code.


diffs (truncated from 595 to 300 lines):

diff --git a/monetdb5/extras/crackers/Makefile.ag 
b/monetdb5/extras/crackers/Makefile.ag
--- a/monetdb5/extras/crackers/Makefile.ag
+++ b/monetdb5/extras/crackers/Makefile.ag
@@ -34,6 +34,7 @@ lib_crackers = {
                          crackers_AVL_index.mx \
                          crackers_AVL_tree.mx \
                          crackers_index.mx \
+                         crackers_validation.mx \
                          crackers_core_unordered.mx \
                          crackers_select_ops.mx \
                          crackers_holistic.c \
diff --git a/monetdb5/extras/crackers/crackers.mx 
b/monetdb5/extras/crackers/crackers.mx
--- a/monetdb5/extras/crackers/crackers.mx
+++ b/monetdb5/extras/crackers/crackers.mx
@@ -152,6 +152,7 @@ module crackers;
 @:TypeSwitch_1(Select)@
 @:TypeSwitch_1(Index)@
 @:TypeSwitch_1(CoreUnordered)@
+@:TypeSwitch_1(Validate)@
 @:TypeSwitch_1(Updates)@
 
 #
@@ -375,6 +376,39 @@ comment "Break a BAT into three pieces w
         tail<=low, low<tail<=hgh, tail>hgh,
         respectively.";
 @
+@= Validate
+@:crack_validate(@2,Ordered,; maintaining the head-oid order within each 
piece)@
+@:crack_validate(@2,Unordered,)@
+
+command verifyCrackerIndex(b:bat[:any_1,:@2]):void
+address CRKverifyCrackerIndex_@2
+comment "Check the cracker index and column, whether each value is in the 
correct chunk";
+@
+@= crack_validate
+command zcrack@2_validate (b:bat[:oid,:@1], mid:@1) :bit
+address CRKcrack@2Zero_validate_@1
+comment "Validate whether a BAT is correctly broken into two pieces with
+        tail<=mid, tail>mid,
+        respectively@3.";
+
+command crack@2_validate (b:bat[:oid,:@1], mid:@1) :bit
+address CRKcrack@2One_validate_@1
+comment "Validate whether a BAT is correctly broken into three pieces with
+        tail<mid, tail==mid, tail>mid,
+        respectively@3.";
+
+command crack@2_validate (b:bat[:oid,:@1], low:@1, hgh:@1) :bit
+address CRKcrack@2Two_validate_@1
+comment "Validate whether a BAT is correctly broken into five pieces with
+        tail<low, tail==low, low<tail<hgh, tail==hgh, tail>hgh,
+        respectively@3.";
+
+command zcrack@2_validate (b:bat[:oid,:@1], low:@1, hgh:@1) :bit
+address CRKcrack@2Three_validate_@1
+comment "Validate whether a BAT is correctly broken into three pieces with
+        tail<=low, low<tail<=hgh, tail>hgh,
+        respectively@3.";
+@
 
  
 @h
@@ -399,6 +433,7 @@ comment "Break a BAT into three pieces w
 
 #include "mtime.h"
 #include "crackers_index.h"
+#include "crackers_validation.h"
 #include "crackers_select_ops.h"
 #include "crackers_selectst_ops.h"
 #include "crackers_selecthol_ops.h"
diff --git a/monetdb5/extras/crackers/crackers_select_ops.mx 
b/monetdb5/extras/crackers/crackers_select_ops.mx
--- a/monetdb5/extras/crackers/crackers_select_ops.mx
+++ b/monetdb5/extras/crackers/crackers_select_ops.mx
@@ -32,7 +32,6 @@ All Rights Reserved.
  * @- Type expansion
  */
 @= TypeSwitch
-@:@1(bte,simple,,bte)@
 @:@1(sht,simple,,sht)@
 @:@1(int,simple,,int)@
 @:@1(lng,simple,,lng)@
@@ -231,6 +230,15 @@ CRKthetauselect_@1(int *vid, int *bid, @
 #ifdef CRACK_DEBUG
        fprintf(stderr,"AFTER CRKcrackUnorderedZero vl= "OIDFMT"  \n", vl );    
 #endif
+       if (vl < cl1){
+               /*then the left piece is empty*/
+               gapL = -1;
+       }
+       if (vl > ch1){
+               /*then the right piece is empty*/
+               /*vl--;*/
+               gapL = -1;
+       }
 
        vl++; /* We need to take next position because the crack function 
always returns the last bun of the left piece.
                Instead we want the first bun of the right piece*/
@@ -245,6 +253,16 @@ CRKthetauselect_@1(int *vid, int *bid, @
                CRKcrackUnorderedZero@2_LE_@1(b,*hgh, cl2, ch2,&vh);
        else
                CRKcrackUnorderedZero@2_RE_@1(b,*hgh, cl2, ch2,&vh);
+       /*check for gaps*/
+       if (vh < cl2)
+               /*then the left piece is empty*/
+               gapH = -1;
+       if (vh > ch2){
+               /*then the right piece is empty*/
+               gapH = -1;
+               /*vh--;*/
+       }
+
 @
 @= CreateResult
 createView:
@@ -276,6 +294,11 @@ createView:
        bit HBound, foundLow=0, foundHgh=0;
        bit LBound=FALSE;
        int *t;
+       int gapL = 1;
+       int gapH = 1;
+       bit rippledDeletions = FALSE;
+       struct Node *lowNode=NULL, *hghNode=NULL, *lowNodeNext=NULL, *temp;
+       BUN idxFirst;
        bit copy=TRUE;
        
        if (@2_GT(low,hgh,@3@1))
@@ -417,10 +440,41 @@ createView:
        if ((b = BATdescriptor(CrackerIndex[m].cbid)) == NULL)
                throw(MAL, "crackers.crackRange", "Cannot access crack index");
 
-       /*idxFirst = BUNfirst(c);*/
+       idxFirst = BUNfirst(c);
 
        /* deal with pending deletions if any */
 
+       if (CrackerIndex[m].mergeDeletions >= 0){
+               str msg = selectMergeDeletionsPart_@1(bid, low, inclusiveLow, 
hgh, inclusiveHgh, &rippledDeletions, m);
+               if (msg != NULL)
+                       throw(MAL, "crackers.crackRange", "%s", msg);
+       }
+       
+       if (CrackerIndex[m].mergeDeletions == 2 && rippledDeletions == FALSE){
+               lowNode = findNodeL_@1(*low, *inclusiveLow, 
CrackerIndex[m].Tree, c, idxFirst, NULL);
+                if (lowNode == NULL){
+                        lowNodeNext = NULL;
+                        temp = CrackerIndex[m].Tree;
+                        if (temp->deleted == FALSE)
+                                lowNodeNext = temp;
+                        while (temp->left != NULL){
+                                temp = temp->left;
+                                if (temp->deleted == FALSE)
+                                        lowNodeNext = temp;
+                        }
+                } else
+                        lowNodeNext = findNextPiece(lowNode);
+
+               shiftHoles_@1(lowNode, lowNodeNext, b, c, idxFirst, hgh, 
inclusiveHgh, m);      
+       }
+
+       /* deal with pending insertions if any */
+       if (CrackerIndex[m].mergeInsertions >= 0){
+               str msg;
+               msg = selectMergeInsertionsPart_@1(bid, low, inclusiveLow, hgh, 
inclusiveHgh, m);
+                if (msg != NULL)
+                        throw(MAL, "crackers.crackRange", "%s", msg);
+       }
 
        
 
@@ -450,6 +504,38 @@ createView:
        fprintf(stderr,"cl1= "OIDFMT" ch1= "OIDFMT" cl2= "OIDFMT" ch2= "OIDFMT" 
vl= "OIDFMT" vh= "OIDFMT" \n\n", cl1,ch1,cl2,ch2,vl,vh );
 #endif
 
+       /* find the hols if any in the pieces to crack so that cracking does 
not touch deleted buns */
+        if (CrackerIndex[m].mergeDeletions == 2){
+               oid holsLow = 0, holsHgh = 0;
+               /* if not done before while shifting hols find lowNode and 
lowNodeNext */
+               if (rippledDeletions == TRUE){
+                       lowNode = findNodeL_@1(*low, *inclusiveLow, 
CrackerIndex[m].Tree, c, idxFirst, NULL);
+                               if (lowNode == NULL){
+                               lowNodeNext = NULL;
+                               temp = CrackerIndex[m].Tree;
+                               if (temp->deleted == FALSE)
+                                       lowNodeNext = temp;
+                               while (temp->left != NULL){
+                                       temp = temp->left;
+                                       if (temp->deleted == FALSE)
+                                               lowNodeNext = temp;
+                               }
+                       } else
+                               lowNodeNext = findNextPiece(lowNode);
+               }
+
+               hghNode = findNodeH_@1(*hgh, *inclusiveHgh, 
CrackerIndex[m].Tree, c, idxFirst, NULL);
+               if (lowNodeNext != NULL)
+                       holsLow = lowNodeNext->hols;
+
+               if (hghNode != NULL)
+                       holsHgh = hghNode->hols;
+
+               /* so if there are hols the positions where we crack are 
appropriately decreased */
+               ch1 -= holsLow;
+               ch2 -= holsHgh;
+       }
+
        /* If one or both of the result view bounds were not found using the
        index then we have to crack */
        if (foundLow == 0 || foundHgh == 0) {
@@ -468,8 +554,8 @@ createView:
                                        _vl = vl - 1;
                                else
                                        _vl = vl;
-                               addCrackerIndex_@1(m, low, *inclusiveLow, _vl, 
c);
-                               addCrackerIndex_@1(m, hgh, HBound, vh, c);
+                               if (gapL>0) addCrackerIndex_@1(m, low, 
*inclusiveLow, _vl, c);
+                               if (gapH>0) addCrackerIndex_@1(m, hgh, HBound, 
vh, c);
                                if ((vl == 1) && (*t == *low) && (*inclusiveLow 
== TRUE))
                                        vl = vl - 1;
                        }
@@ -481,7 +567,7 @@ createView:
                                        _vl = vl - 1;
                                else
                                        _vl = vl;
-                               addCrackerIndex_@1(m, low, *inclusiveLow, _vl, 
c);
+                               if (gapL>0) addCrackerIndex_@1(m, low, 
*inclusiveLow, _vl, c);
                                if ((vl == 1) && (*t == *low) && (*inclusiveLow 
== TRUE))
                                        vl = vl - 1;
                        }
@@ -490,7 +576,7 @@ createView:
                        @:crkTwoRTree@5(@1,@5)@
                        t = (int *) Tloc(b, BUNfirst(b));
                        if (IndexSize < IndexStop)
-                               addCrackerIndex_@1(m, hgh, HBound, vh, c);
+                               if (gapH>0) addCrackerIndex_@1(m, hgh, HBound, 
vh, c);
                        vl = cl1;
                        if ((vl == 0) && (*t < *low) && (*inclusiveLow == TRUE))
                                vl = vl + 1;
@@ -508,6 +594,285 @@ createView:
 @
 @= crackOperations
 
+static oid
+shiftHoles_@1(struct Node *lowNode, struct Node *lowNodeNext, BAT *b, BAT *c, 
BUN idxFirst, @1 *hgh, bit *inclusiveHgh, int position){
+       oid holSize = 0, LposCr = 0, HposCr = 0, holPiece = 0, buns;
+       oid *fh;
+       @1 *ft;
+       oid *hghPos = NULL;
+       struct Node *hghNode, *stopNode;
+
+       fh = (oid*)Hloc(b, BUNfirst(b));
+       ft = (@1 *)Tloc(b, BUNfirst(b));
+       stopNode = findNodeH_@1(*hgh, *inclusiveHgh, 
CrackerIndex[position].Tree, c, idxFirst, NULL);
+
+       while (1){
+               if (lowNode == NULL)
+                       hghNode = lowNodeNext;
+                else
+                       hghNode = findNextPiece(lowNode);
+               
+               /* find deletes that belong in this piece */
+               if (lowNode != NULL && hghNode != NULL){
+                               hghPos = (oid*)Hloc(c, idxFirst + 
hghNode->position);
+                       LposCr = *(oid*)Hloc(c, idxFirst + lowNode->position) + 
holSize;
+                       HposCr = *hghPos;
+               } else
+               if (lowNode == NULL && hghNode != NULL){
+                               hghPos = (oid*)Hloc(c, idxFirst + 
hghNode->position);
+                       LposCr = 0;
+                               HposCr = *hghPos;
+               } else
+               if (lowNode != NULL && hghNode == NULL){
+                       LposCr = *(oid*)Hloc(c, idxFirst + lowNode->position) + 
holSize;
+                               HposCr = BATcount(b)-1;
+               }
+
+               if (hghNode != NULL)
+                       holPiece = hghNode->hols;
+               else
+                       holPiece = 0;
+
+               HposCr -= holPiece;
+               buns = HposCr - LposCr;
+               /* no need to to shift if nothing has been deleted from 
previous pieces */
+               if (holSize > 0 && buns > 0){
+                       if (holSize >= buns){
+                               memcpy(fh+(LposCr-(holSize-1)), fh+(LposCr+1), 
buns*sizeof(oid));
+                               memcpy(ft+(LposCr-(holSize-1)), ft+(LposCr+1), 
buns*sizeof(@1 ));
+                       }
+                       else{
+                               memcpy(fh+(LposCr-(holSize-1)), 
fh+(LposCr+1+(buns-holSize)), holSize*sizeof(oid));
+                               memcpy(ft+(LposCr-(holSize-1)), 
ft+(LposCr+1+(buns-holSize)), holSize*sizeof(@1 ));
+                       }
+               }
+               holSize += holPiece;
+               if (hghNode != NULL){
+                       if (hghNode == stopNode)
+                               break;
+                       hghNode->hols = 0;
+                       lowNode = hghNode;
+                       *hghPos = *hghPos - holSize;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to