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 if(NULL
== iterPage_
) return NULL
;
52 record
= ((char*)iterPage_
) +sizeof(PageInfo
);
53 while(*(int*)record
!= 1)
55 iterPage_
= (PageInfo
*) iterPage_
->nextPage_
;
56 if(NULL
== iterPage_
) return NULL
;
57 record
= ((char*)iterPage_
) +sizeof(PageInfo
);
59 iterPage_
= (PageInfo
*) iterPage_
->nextPage_
;
60 return (record
+ sizeof(int));
63 //check whether there are any nodes in the current page
64 //int i = nodeOffset_;
66 data
= ((char*)iterPage_
) + sizeof(PageInfo
);
67 if ((*(int*)data
) == 1)
68 return data
+ sizeof(int);
70 data
= data
+ allocSize_
;
71 while(data
< iterPageEnd
)
73 if (*((int*)data
) == 0)
75 //not used, so skip it
76 data
= data
+ allocSize_
;
77 printDebug(DM_Iterator
,"ChunkID:%d Moving to next data node %x",
82 //used, return element pointer
84 printDebug(DM_Iterator
,"ChunkID:%d Returning %x nodeOffset:%d",
85 chunkID_
, data
+ sizeof(int), nodeOffset_
);
86 return data
+ sizeof(int);
89 //go to next page and check till it exhausts
90 while(iterPage_
->nextPage_
!= NULL
)
92 iterPage_
= (PageInfo
*)iterPage_
->nextPage_
;
93 data
= ((char*)iterPage_
) + sizeof(PageInfo
);
94 iterPageEnd
= ((char*)iterPage_
) + PAGE_SIZE
;
95 while(data
< iterPageEnd
)
97 if (*((int*)data
) == 0)
99 //not used, so skip it
100 data
= data
+ allocSize_
;
106 printDebug(DM_Iterator
,"ChunkID:%d Returning %x",
107 chunkID_
, data
+ sizeof(int));
108 return data
+sizeof(int);