include/Index.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015   ***************************************************************************/
00016 #ifndef INDEX_H
00017 #define INDEX_H
00018 #include<DataType.h>
00019 #include<Debug.h>
00020 #include<Info.h>
00021 
00022 
00023 class Chunk;
00024 class Database;
00025 class Transaction;
00026 class TableImpl;
00027 
00028 class Bucket
00029 {
00030     public:
00031     Mutex mutex_;
00032     void *bucketList_;
00033 };
00034 class HashIndexNode
00035 {
00036     public:
00037     void *ptrToKey_;
00038     void *ptrToTuple_;
00039     HashIndexNode *next_;
00040 };
00041 class BucketIter
00042 {
00043     HashIndexNode *iter;
00044     public:
00045     BucketIter(){}
00046     BucketIter(HashIndexNode *head) { iter = head;}
00047     HashIndexNode* next();
00048     friend class BucketList;
00049 };
00050 class BucketList
00051 {
00052     HashIndexNode *head;
00053     public:
00054     BucketList(){ head = NULL;}
00055     BucketList(HashIndexNode *h){ head = h; }
00056     DbRetVal insert(Chunk *chunk, Database *db, void *key, void *tuple);
00057     DbRetVal remove(Chunk *chunk, Database *db, void *key);
00058     BucketIter getIterator()
00059     {
00060         BucketIter it;
00061         it.iter = head;
00062         return it;
00063     }
00064 
00065 };
00066 class HashIndex;
00067 class IndexInfo;
00068 class Index
00069 {
00070     // create (one) object for each indexing mechanisms here 
00071     // Also need to make changes to getIndex() and destroy() methods 
00072     // accordingly for new index machanism.
00073     static HashIndex *hIdx;
00074     static long usageCount;
00075     public:
00076     static Index* getIndex(IndexType type);
00077     static void init() { usageCount++; }
00078     static void destroy() { 
00079          usageCount--;
00080          if(!usageCount) {
00081             if(!hIdx) { delete hIdx; hIdx=NULL; }
00082          }
00083     }
00084     virtual DbRetVal insert(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag)=0;
00085     virtual DbRetVal remove(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag)=0; 
00086     virtual DbRetVal update(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag)=0;
00087 };
00088 class HashIndex : public Index
00089 {
00090 
00091     public:
00092     DbRetVal insert(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag);
00093     DbRetVal remove(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag);
00094     DbRetVal update(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag);
00095     static unsigned int computeHashBucket(DataType type, void *key, int noOfBuckets);
00096 
00097 };
00098 
00099 enum IndexIntType
00100 {
00101         hashOneField = 1,
00102         hash = 2,
00103         tree = 3
00104 
00105 };
00106 class IndexInfo
00107 {
00108     public:
00109     IndexType type;
00110 };
00111 
00112 //Used by TableImpl to cache information related to hash indexes on that table
00113 class SingleFieldHashIndexInfo :public IndexInfo
00114 {
00115     public:
00116     char  *fldName;
00117     DataType type ;
00118     char *indexPtr;
00119     int noOfBuckets;
00120     Bucket* buckets;
00121     int fldPos;
00122     bool isUnique;
00123     int offset;
00124     int length;
00125     void print() 
00126     {
00127         printf("SingleFieldHashIndexInfo fldname:%s type:%d indexPtr:%x noOfBuckets:%d buckets:%x isUnique:%d\n", fldName, type, indexPtr, noOfBuckets, buckets, isUnique);
00128     }
00129 };
00130 #endif
00131 

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7