Though select fails, it return the tuple. This is because curTuple_ is not set in...
[csql.git] / include / Index.h
blob87059a22d158b871d0bcd5d163d8fc3e6285764a
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
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. *
9 * *
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. *
14 * *
15 ***************************************************************************/
16 #ifndef INDEX_H
17 #define INDEX_H
18 #include<DataType.h>
19 #include<Debug.h>
20 #include<Info.h>
23 class Chunk;
24 class Database;
25 class Transaction;
26 class TableImpl;
28 class Bucket
30 public:
31 Mutex mutex_;
32 void *bucketList_;
34 class HashIndexNode
36 public:
37 void *ptrToKey_;
38 void *ptrToTuple_;
39 HashIndexNode *next_;
41 class BucketIter
43 HashIndexNode *iter;
44 public:
45 BucketIter(){}
46 BucketIter(HashIndexNode *head) { iter = head;}
47 HashIndexNode* next();
48 friend class BucketList;
50 class BucketList
52 HashIndexNode *head;
53 public:
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()
60 BucketIter it;
61 it.iter = head;
62 return it;
66 class HashIndex;
68 class Index
70 //create (one) object for each indexing mechanisms here
71 static HashIndex *hIdx;
72 public:
73 static Index* getIndex(IndexType type);
74 static void destroy() { delete hIdx; }
75 virtual DbRetVal insert(TableImpl *tbl, Transaction *tr, void *indexPtr, void *tuple)=0;
76 virtual DbRetVal remove(TableImpl *tbl, Transaction *tr, void *indexPtr, void *tuple)=0;
77 virtual DbRetVal update(TableImpl *tbl, Transaction *tr, void *indexPtr, void *tuple)=0;
80 class HashIndex : public Index
83 public:
84 DbRetVal insert(TableImpl *tbl, Transaction *tr, void *indexPtr, void *tuple);
85 DbRetVal remove(TableImpl *tbl, Transaction *tr, void *indexPtr, void *tuple);
86 DbRetVal update(TableImpl *tbl, Transaction *tr, void *indexPtr, void *tuple);
87 static unsigned int computeHashBucket(DataType type, void *key, int noOfBuckets);
91 enum IndexIntType
93 hashOneField = 1,
94 hash = 2,
95 tree = 3
98 class IndexInfo
100 public:
101 IndexType type;
104 //Used by TableImpl to cache information related to hash indexes on that table
105 class SingleFieldHashIndexInfo :public IndexInfo
107 public:
108 char *fldName;
109 DataType type ;
110 char *indexPtr;
111 int noOfBuckets;
112 Bucket* buckets;
113 int fldPos;
114 bool isUnique;
116 #endif