Changeset: 37da5edac249 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=37da5edac249
Added Files:
        monetdb5/extras/crackers/crackers_holistic.c
        monetdb5/extras/crackers/crackers_holistic.h
        monetdb5/extras/crackers/crackers_selecthol_ops.mx
        monetdb5/extras/crackers/opt_selcrackhol.mx
Branch: holindex
Log Message:

New files for holistic indexing.
I added a new optimizer for holistic indexing (opt_selcrackhol.mx), the files 
with the necessary structure (crackers_holistic.*) and a file with new 
operators (crackers_selecthol_ops.mx).


diffs (truncated from 1173 to 300 lines):

diff --git a/monetdb5/extras/crackers/crackers_holistic.c 
b/monetdb5/extras/crackers/crackers_holistic.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/crackers/crackers_holistic.c
@@ -0,0 +1,86 @@
+#include "monetdb_config.h"
+#include "crackers_holistic.h"
+#include "gdk.h"
+
+
+int 
+existsFrequencyStruct(FrequencyNode* head)
+{
+       if(head == NULL)
+               return 0;
+       else
+               return 1;
+}
+FrequencyNode* 
+createFrequencyStruct()
+{
+       FrequencyNode *x;
+       x=(FrequencyNode *) GDKmalloc(sizeof(FrequencyNode)); 
+       x->bid=0;       
+       x->c=0;
+       x->f1=0;
+       x->f2=0;
+       x->weight=0.0;
+       x->next=NULL;
+       return x;
+}
+FrequencyNode* 
+push(int bat_id,FrequencyNode* head)
+{
+       FrequencyNode* new_node;
+       new_node=(FrequencyNode *) GDKmalloc(sizeof(FrequencyNode));
+       new_node->bid=bat_id;
+       new_node->c=0;
+       new_node->f1=0;
+       new_node->f2=0;
+       new_node->weight=0.0;
+       new_node->next=head->next;
+       head->next=new_node;
+       return new_node; 
+}
+FrequencyNode*
+pop(FrequencyNode* head)
+{
+       FrequencyNode* dummy;
+       dummy=head->next;
+       head->next=head->next->next;
+       GDKfree(dummy);
+       return head;
+}
+void 
+printFrequencyStruct(FrequencyNode* head)
+{
+       int i=0;
+       FrequencyNode* temp;
+       temp=head;
+       while(temp != NULL)
+       {
+               fprintf(stderr,"Item No. %d:Bid=%d c=%d f1=%d f2=%d W=%lf  
\n",i++,temp->bid,temp->c,temp->f1,temp->f2,temp->weight);
+               temp=temp->next;
+       }
+}
+FrequencyNode* 
+searchBAT(FrequencyNode* head,int bat_id)
+{
+       FrequencyNode* temp;
+       temp=head;
+       while((temp->bid != bat_id))
+       {
+               temp=temp->next;
+       }
+       return temp;
+}
+double
+changeWeight(FrequencyNode* node,int N,int L1)
+{
+       int p; /*number of pieces in the index*/
+       double Sp; /*average size of each piece*/
+       double d; /*distance from optimal piece(L1)*/
+       p = 2 * (node->c);
+       Sp =((double)N)/p;      
+       d = ABS(Sp - L1);
+       node->weight = ((node->f2)/(node->f1)) * d;
+
+       return node->weight;
+
+}
diff --git a/monetdb5/extras/crackers/crackers_holistic.h 
b/monetdb5/extras/crackers/crackers_holistic.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/crackers/crackers_holistic.h
@@ -0,0 +1,22 @@
+#ifndef _CRACKERS_HOLISTIC_H_
+#define _CRACKERS_HOLISTIC_H_
+
+typedef struct frequency{
+
+       int             bid;            /* The base BAT */
+
+       int             c;              /*number of times the column was 
cracked*/
+       int             f1;             /*number of queries that triggered 
cracking*/
+       int             f2;             /*number of queries that did not 
trigger cracking(because the value already existed in the index)*/
+       double          weight;
+       struct frequency *next;
+}FrequencyNode;
+
+int existsFrequencyStruct(FrequencyNode* head);
+FrequencyNode* createFrequencyStruct();
+FrequencyNode* push(int bat_id,FrequencyNode* head);
+FrequencyNode* pop(FrequencyNode* head);
+void printFrequencyStruct(FrequencyNode* head);
+FrequencyNode* searchBAT(FrequencyNode* head,int bat_id);
+double changeWeight(FrequencyNode* node,int N,int L1);
+#endif /*crackers_holistic*/ 
diff --git a/monetdb5/extras/crackers/crackers_selecthol_ops.mx 
b/monetdb5/extras/crackers/crackers_selecthol_ops.mx
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/crackers/crackers_selecthol_ops.mx
@@ -0,0 +1,793 @@
+@/
+The contents of this file are subject to the MonetDB Public License
+Version 1.1 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+http://www.monetdb.org/Legal/MonetDBLicense
+
+Software distributed under the License is distributed on an "AS IS"
+basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+License for the specific language governing rights and limitations
+under the License.
+
+The Original Code is the MonetDB Database System.
+
+The Initial Developer of the Original Code is CWI.
+Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+Copyright August 2008-2012 MonetDB B.V.
+All Rights Reserved.
+@
+
+@f crackers_selecthol_ops
+
+@c
+/*
+ * @a Martin Kersten, Stratos Idreos, Stefan Manegold
+ * @d March 2006 - July 2007
+ * @* Select Operators
+ *
+ *
+ * @+ Interface
+ *
+ *
+ * @- Type expansion
+ */
+@= TypeSwitch
+@:@1(bte,simple,,bte)@
+@:@1(sht,simple,,sht)@
+@:@1(int,simple,,int)@
+@:@1(lng,simple,,lng)@
+@:@1(flt,simple,,flt)@
+@:@1(dbl,simple,,dbl)@
+@:@1(date,atom,TYPE_,loc)@
+@
+@h
+/*
+ * @- Header file
+ */
+#ifndef _CRACKERS_SELECTHOL_H_
+#define _CRACKERS_SELECTHOL_H_
+
+/* Exported signatures */
+@:TypeSwitch(SelectholFunctions_decl)@
+
+#endif /* _CRACKERS_SELECTHOL_H */
+/*
+ * @- Exported signatures
+ */
+@= SelectholFunctions_decl
+crackers_export str CRKselectholBounds_@1(int *vid, int *bid, @1 *low, @1 
*hgh, bit *inclusiveLow, bit *inclusiveHgh);
+crackers_export str CRKuselectholBounds_@1(int *vid, int *bid, @1 *low, @1 
*hgh, bit *inclusiveLow, bit *inclusiveHgh);
+crackers_export str CRKselectholValue_@1(int *vid, int *bid, @1 *value);
+crackers_export str CRKuselectholValue_@1(int *vid, int *bid, @1 *value);
+crackers_export str CRKselecthol_@1(int *vid, int *bid, @1 *low, @1 *hgh);
+crackers_export str CRKuselecthol_@1(int *vid, int *bid, @1 *low, @1 *hgh);
+crackers_export str CRKthetaselecthol_@1(int *vid, int *bid, @1 *val, str *op);
+crackers_export str CRKthetauselecthol_@1(int *vid, int *bid, @1 *val, str 
*op);
+crackers_export str CRKinitFrequencyStruct_@1(int *vid,int *bid);
+@
+@c
+/*
+ * @+ Implementation
+ *
+ *
+ * @- C file
+ */
+#include "monetdb_config.h"
+#include "crackers.h"
+
+/*This function picks randomly 5 oids and their respective values and then 
chooses the median*/
+@= FndMedian
+       static @1 FndMedian_@1(BAT *c,oid a,oid b)
+       {
+               @1 *t;
+               @1 arr[5]={0,0,0,0,0};
+               int i, j, k; 
+               @1 temp;
+               
+               oid p;
+               int cnt=0;
+               t=(@1 *)Tloc(c,BUNfirst(c));
+               for(cnt=0;cnt<5;cnt++)
+               {
+                       p=(rand()%(b-a+1))+a;
+                       arr[cnt]=t[p];
+               }
+               for ( i = 1 ; i <= 4 ; i++ )
+               {
+                       for ( j = 0 ; j < i ; j++ )
+                       {
+                               if ( arr[j] > arr[i] )
+                               {
+                                       temp = arr[j] ;
+                                       arr[j] = arr[i] ;
+
+                                       for ( k = i ; k > j ; k-- )
+                                               arr[k] = arr[k - 1] ;
+
+                                       arr[k + 1] = temp ;
+                               }
+                       }
+               }
+               
+               return arr[2];
+       }
+@c
+
+@:TypeSwitch(FndMedian)@
+
+
+/* Local support functions and macros */
+@:TypeSwitch(crackOperations)@
+
+/* Exported functions */
+@:TypeSwitch(SelectholFunctions_impl)@
+/*
+ * @- Exported functions
+ */
+@= SelectholFunctions_impl
+
+str
+CRKselectholBounds_@1(int *vid, int *bid, @1 *low, @1 *hgh, bit *inclusiveLow, 
bit *inclusiveHgh){             
+       if (@2_EQ(low,ATOMnilptr(TYPE_@1),@3@1))
+               return CRKRangeLeftNilTree_@1(vid, bid, hgh, inclusiveHgh, 
TRUE);
+       else if (@2_EQ(hgh,ATOMnilptr(TYPE_@1),@3@1))
+               return CRKRangeRightNilTree_@1(vid, bid, low, inclusiveLow, 
TRUE);
+       else
+               return CRKRangeTree_@1(vid, bid, low, hgh, inclusiveLow, 
inclusiveHgh, TRUE);
+}
+
+str
+CRKuselectholBounds_@1(int *vid, int *bid, @1 *low, @1 *hgh, bit 
*inclusiveLow, bit *inclusiveHgh){
+       if (@2_EQ(low,ATOMnilptr(TYPE_@1),@3@1))
+               return CRKRangeLeftNilTree_@1(vid, bid, hgh, inclusiveHgh, 
FALSE);
+       else if (@2_EQ(hgh,ATOMnilptr(TYPE_@1),@3@1))
+               return CRKRangeRightNilTree_@1(vid, bid, low, inclusiveLow, 
FALSE);
+       else
+               return CRKRangeTree_@1(vid, bid, low, hgh, inclusiveLow, 
inclusiveHgh, FALSE);
+}
+
+str
+CRKselectholValue_@1(int *vid, int *bid, @1 *value){
+       bit inclusive = TRUE;
+       return CRKuselectholBounds_@1(vid, bid, value, value, &inclusive, 
&inclusive);
+}
+
+str
+CRKuselectholValue_@1(int *vid, int *bid, @1 *value){
+       bit inclusive = TRUE;
+       return CRKuselectholBounds_@1(vid, bid, value, value, &inclusive, 
&inclusive);
+}
+
+str
+CRKselecthol_@1(int *vid, int *bid, @1 *low, @1 *hgh){
+       bit inclusive = TRUE;
+       return CRKselectholBounds_@1(vid, bid, low, hgh, &inclusive, 
&inclusive);
+}
+
+str
+CRKuselecthol_@1(int *vid, int *bid, @1 *low, @1 *hgh){
+       bit inclusive = TRUE;
+       return CRKuselectholBounds_@1(vid, bid, low, hgh, &inclusive, 
&inclusive);
+}
+
+str
+CRKthetaselecthol_@1(int *vid, int *bid, @1 *val, str *OP){
+       ptr nilptr = ATOMnilptr(TYPE_@1); 
+       char *op = *OP; 
+       bit lin = TRUE, rin = TRUE;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to