1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 ***************************************************************************/
54 //Note::after this array of pointer to tuples are stored
56 DbRetVal
insert(Database
*db
, IndexInfo
*info
, void *indexPtr
, void *tuple
);
57 DbRetVal
insert(int position
, Database
*db
, IndexInfo
*indInfo
, CINDEX
*iptr
, void *tuple
, TreeNode
*iter
);
58 DbRetVal
remove(Database
*db
, IndexInfo
*info
, void *indexPtr
, void *tuple
);
59 DbRetVal
update(Database
*db
, IndexInfo
*info
, void *indexPtr
, void *tuple
);
60 void displayAll(IndexInfo
*indInfo
, void *indexPtr
);
61 void displayAll(int offset
);
69 BucketIter(HashIndexNode
*head
) { iter
= head
;}
70 HashIndexNode
* next();
71 friend class BucketList
;
77 BucketList(){ head
= NULL
;}
78 BucketList(HashIndexNode
*h
){ head
= h
; }
79 void *getBucketListHead(){ return head
;}
80 DbRetVal
insert(Chunk
*chunk
, Database
*db
, void *key
, void *tuple
);
81 DbRetVal
remove(Chunk
*chunk
, Database
*db
, void *key
);
82 BucketIter
getIterator()
96 // create (one) object for each indexing mechanisms here
97 // Also need to make changes to getIndex() and destroy() methods
98 // accordingly for new index machanism.
99 static HashIndex
*hIdx
;
100 static TreeIndex
*tIdx
;
101 static long usageCount
;
103 static Index
* getIndex(IndexType type
);
104 static void init() { usageCount
++; }
105 static void destroy() {
108 if(!hIdx
) { delete hIdx
; hIdx
=NULL
; }
111 virtual DbRetVal
insert(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
)=0;
112 virtual DbRetVal
remove(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
)=0;
113 virtual DbRetVal
update(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
)=0;
115 class HashIndex
: public Index
119 DbRetVal
insert(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
120 DbRetVal
remove(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
121 DbRetVal
update(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
122 static unsigned int computeHashBucket(DataType type
, void *key
, int noOfBuckets
, int length
=0);
126 class TreeIndex
: public Index
129 TreeNode
* locateNode(TreeNode
*iter
, void *tuple
, IndexInfo
*indInfo
);
130 DbRetVal
removeElement(Database
*db
, TreeNode
*iter
, void *tuple
, HashIndexInfo
*info
);
132 DbRetVal
insert(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
133 DbRetVal
remove(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
134 DbRetVal
update(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
151 void* locateElement();
155 TreeIter(TreeNode
*head
) { iter
= head
; firstCall
= true; recordsOver
=false;}
156 void setSearchKey(void *key
, ComparisionOp cop
, bool ascending
= true)
158 searchKey
= key
; op
= cop
; asc
=ascending
;
160 void setFldOffset(int off
) { fldOffset
= off
; }
161 void setTypeLength(DataType t
, int l
) { type
=t
; length
=l
; }
179 //Used by TableImpl to cache information related to hash indexes on that table
180 class HashIndexInfo
:public IndexInfo
183 FieldList idxFldList
;
193 printf("HashIndexInfo indexPtr:%x noOfBuckets:%d buckets:%x \n",indexPtr
, noOfBuckets
, buckets
);