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 ***************************************************************************/
46 BucketIter(HashIndexNode
*head
) { iter
= head
;}
47 HashIndexNode
* next();
48 friend class BucketList
;
54 BucketList(){ head
= NULL
;}
55 BucketList(HashIndexNode
*h
){ head
= h
; }
56 DbRetVal
insert(Chunk
*chunk
, Database
*db
, void *key
, void *tuple
);
57 DbRetVal
remove(Chunk
*chunk
, Database
*db
, void *key
);
58 BucketIter
getIterator()
70 // create (one) object for each indexing mechanisms here
71 // Also need to make changes to getIndex() and destroy() methods
72 // accordingly for new index machanism.
73 static HashIndex
*hIdx
;
74 static long usageCount
;
76 static Index
* getIndex(IndexType type
);
77 static void init() { usageCount
++; }
78 static void destroy() {
81 if(!hIdx
) { delete hIdx
; hIdx
=NULL
; }
84 virtual DbRetVal
insert(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
)=0;
85 virtual DbRetVal
remove(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
)=0;
86 virtual DbRetVal
update(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
)=0;
88 class HashIndex
: public Index
92 DbRetVal
insert(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
93 DbRetVal
remove(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
94 DbRetVal
update(TableImpl
*tbl
, Transaction
*tr
, void *indexPtr
, IndexInfo
*info
, void *tuple
, bool undoFlag
);
95 static unsigned int computeHashBucket(DataType type
, void *key
, int noOfBuckets
);
112 //Used by TableImpl to cache information related to hash indexes on that table
113 class SingleFieldHashIndexInfo
:public IndexInfo
127 printf("SingleFieldHashIndexInfo fldname:%s type:%d indexPtr:%x noOfBuckets:%d buckets:%x isUnique:%d\n", fldName
, type
, indexPtr
, noOfBuckets
, buckets
, isUnique
);