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 ***************************************************************************/
22 //No iterators for variable size allocators
23 ChunkIterator
Chunk::getIterator()
26 iter
.chunkID_
= chunkID_
;
27 iter
.allocSize_
= allocSize_
;
28 iter
.allocType_
= allocType_
;
29 iter
.iterPage_
= (PageInfo
*)firstPage_
;
31 iter
.noOfNodes_
= os::floor((PAGE_SIZE
- sizeof(PageInfo
)) / allocSize_
);
33 iter
.iterPageEnd
= ((char*)firstPage_
) +PAGE_SIZE
;
34 printDebug(DM_Iterator
,"ChunkID:%d FirstPage is %x",
35 chunkID_
, iter
.iterPage_
);
39 void* ChunkIterator::nextElement()
41 /*if(NULL == iterPage_)
43 printError(ErrNotExists,"No iter page exists.");
46 //PageInfo* pageInfo = (PageInfo*)iterPage_;
49 //means tuple larger than PAGE_SIZE
50 char *record
= ((char*)iterPage_
) +sizeof(PageInfo
)+sizeof(int);
51 iterPage_
= (PageInfo
*) iterPage_
->nextPage_
;
55 //check whether there are any nodes in the current page
56 //int i = nodeOffset_;
58 data
= ((char*)iterPage_
) + sizeof(PageInfo
);
59 if ((*(int*)data
) == 1)
60 return data
+ sizeof(int);
62 data
= data
+ allocSize_
;
63 while(data
< iterPageEnd
)
65 if (*((int*)data
) == 0)
67 //not used, so skip it
68 data
= data
+ allocSize_
;
69 printDebug(DM_Iterator
,"ChunkID:%d Moving to next data node %x",
74 //used, return element pointer
76 printDebug(DM_Iterator
,"ChunkID:%d Returning %x nodeOffset:%d",
77 chunkID_
, data
+ sizeof(int), nodeOffset_
);
78 return data
+ sizeof(int);
81 //go to next page and check till it exhausts
82 while(iterPage_
->nextPage_
!= NULL
)
84 iterPage_
= (PageInfo
*)iterPage_
->nextPage_
;
85 data
= ((char*)iterPage_
) + sizeof(PageInfo
);
86 iterPageEnd
= ((char*)iterPage_
) + PAGE_SIZE
;
87 while(data
< iterPageEnd
)
89 if (*((int*)data
) == 0)
91 //not used, so skip it
92 data
= data
+ allocSize_
;
98 printDebug(DM_Iterator
,"ChunkID:%d Returning %x",
99 chunkID_
, data
+ sizeof(int));
100 return data
+sizeof(int);