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_
;
32 iter
.noOfNodes_
= os::floor((PAGE_SIZE
- sizeof(PageInfo
)) / allocSize_
);
34 iter
.iterPageEnd
= ((char*)firstPage_
) +PAGE_SIZE
;
35 printDebug(DM_Iterator
,"ChunkID:%d FirstPage is %x",
36 chunkID_
, iter
.iterPage_
);
40 void* ChunkIterator::nextElement()
44 //means tuple larger than PAGE_SIZE
45 if(NULL
== iterPage_
) return NULL
;
47 record
= ((char*)iterPage_
) +sizeof(PageInfo
);
48 while(*(InUse
*)record
!= 1)
50 iterPage_
= (PageInfo
*) iterPage_
->nextPage_
;
51 if(NULL
== iterPage_
) return NULL
;
52 record
= ((char*)iterPage_
) +sizeof(PageInfo
);
54 iterPage_
= (PageInfo
*) iterPage_
->nextPage_
;
55 return (record
+ sizeof(InUse
));
58 //check whether there are any nodes in the current page
59 //int i = nodeOffset_;
61 data
= ((char*)iterPage_
) + sizeof(PageInfo
);
62 if ((*(InUse
*)data
) == 1)
63 return data
+ sizeof(InUse
);
66 while(data
< iterPageEnd
)
68 if (*((InUse
*)data
) == 0)
70 //not used, so skip it
71 data
= data
+ allocSize_
;
72 printDebug(DM_Iterator
,"ChunkID:%d Moving to next data node %x",
77 //used, return element pointer
79 printDebug(DM_Iterator
,"ChunkID:%d Returning %x nodeOffset:%d",
80 chunkID_
, data
+ sizeof(InUse
), nodeOffset_
);
81 return data
+ sizeof(InUse
);
84 //go to next page and check till it exhausts
85 while(iterPage_
->nextPage_
!= NULL
)
87 iterPage_
= (PageInfo
*)iterPage_
->nextPage_
;
88 data
= ((char*)iterPage_
) + sizeof(PageInfo
);
89 iterPageEnd
= ((char*)iterPage_
) + PAGE_SIZE
;
90 while(data
< iterPageEnd
)
92 if (*((InUse
*)data
) == 0)
94 //not used, so skip it
95 data
= data
+ allocSize_
;
99 printDebug(DM_Iterator
,"ChunkID:%d Returning %x",
100 chunkID_
, data
+ sizeof(InUse
));
101 return data
+sizeof(InUse
);
107 void* ChunkIterator::nextElementIntMatch(int value
, int offset
)
109 //check whether there are any nodes in the current page
111 data
= ((char*)iterPage_
) + sizeof(PageInfo
);
112 if ((*(InUse
*)data
) == 1 && *(int*)(data
+sizeof(InUse
)+offset
) == value
)
113 return data
+ sizeof(InUse
);
116 while(data
< iterPageEnd
)
118 if (*(int*)(data
+sizeof(InUse
)+offset
) == value
&& *((InUse
*)data
))
120 printDebug(DM_Iterator
,"ChunkID:%d Returning %x nodeOffset:%d",
121 chunkID_
, data
+ sizeof(InUse
), nodeOffset_
);
122 return data
+ sizeof(InUse
);
124 data
= data
+ allocSize_
;
125 printDebug(DM_Iterator
,"ChunkID:%d Moving to next data node %x",
128 //go to next page and check till it exhausts
129 while(iterPage_
->nextPage_
!= NULL
)
131 iterPage_
= (PageInfo
*)iterPage_
->nextPage_
;
132 data
= ((char*)iterPage_
) + sizeof(PageInfo
);
133 iterPageEnd
= ((char*)iterPage_
) + PAGE_SIZE
;
134 while(data
< iterPageEnd
)
136 if (*(int*)(data
+sizeof(InUse
)+offset
) == value
&& *((InUse
*)data
))
138 printDebug(DM_Iterator
,"ChunkID:%d Returning %x",
139 chunkID_
, data
+ sizeof(InUse
));
140 return data
+sizeof(InUse
);
142 data
= data
+ allocSize_
;