changing tmp file to /dev/null
[csql.git] / include / Index.h
bloba7451eb6f8860028ac48eed87d2ca2d2f68ccf0f
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 void *getBucketListHead(){ return head;}
57 DbRetVal insert(Chunk *chunk, Database *db, void *key, void *tuple);
58 DbRetVal remove(Chunk *chunk, Database *db, void *key);
59 BucketIter getIterator()
61 BucketIter it;
62 it.iter = head;
63 return it;
67 class HashIndex;
68 class IndexInfo;
69 class Index
71 // create (one) object for each indexing mechanisms here
72 // Also need to make changes to getIndex() and destroy() methods
73 // accordingly for new index machanism.
74 static HashIndex *hIdx;
75 static long usageCount;
76 public:
77 static Index* getIndex(IndexType type);
78 static void init() { usageCount++; }
79 static void destroy() {
80 usageCount--;
81 if(!usageCount) {
82 if(!hIdx) { delete hIdx; hIdx=NULL; }
85 virtual DbRetVal insert(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag)=0;
86 virtual DbRetVal remove(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag)=0;
87 virtual DbRetVal update(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag)=0;
89 class HashIndex : public Index
92 public:
93 DbRetVal insert(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag);
94 DbRetVal remove(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag);
95 DbRetVal update(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *info, void *tuple, bool undoFlag);
96 static unsigned int computeHashBucket(DataType type, void *key, int noOfBuckets, int length=0);
100 enum IndexIntType
102 hashOneField = 1,
103 hash = 2,
104 tree = 3
107 class IndexInfo
109 public:
110 IndexType type;
113 //Used by TableImpl to cache information related to hash indexes on that table
114 class HashIndexInfo :public IndexInfo
116 public:
117 FieldList idxFldList;
118 char *indexPtr;
119 int noOfBuckets;
120 Bucket* buckets;
121 int fldOffset;
122 bool isUnique;
123 DataType type;
124 int compLength;
125 void print()
127 printf("HashIndexInfo indexPtr:%x noOfBuckets:%d buckets:%x \n",indexPtr, noOfBuckets, buckets);
130 #endif