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_
= firstPage_
;
31 iter
.noOfNodes_
= os::floor((PAGE_SIZE
- sizeof(PageInfo
)) / allocSize_
);
35 void* ChunkIterator::nextElement()
39 printError(ErrNotExists
,"No iter page exists.");
42 PageInfo
* pageInfo
= (PageInfo
*)iterPage_
;
45 //means tuple larger than PAGE_SIZE
46 iterPage_
= pageInfo
->nextPage_
;
47 return (char*)pageInfo
+ sizeof(PageInfo
)+ sizeof(int);
50 char *data
= ((char*)iterPage_
) + sizeof(PageInfo
) + (nodeOffset_
* allocSize_
) ;
52 //check whether there are any nodes in the current page
54 while(nodeOffset_
< noOfNodes_
)
56 if (*((int*)data
) == 0)
58 //not used, so skip it
59 data
= data
+ allocSize_
;
61 if (data
>= (char*)iterPage_
+ PAGE_SIZE
) break;
65 //used, return element pointer
67 printDebug(DM_Iterator
,"ChunkID:%d Returning %x nodeOffset:%d",
68 chunkID_
, data
+ sizeof(int), nodeOffset_
);
69 return data
+ sizeof(int);
72 //go to next page and check till it exhausts
73 while(pageInfo
->nextPage_
!= NULL
)
75 iterPage_
= pageInfo
->nextPage_
;
76 pageInfo
= ((PageInfo
*)iterPage_
);
77 data
= (char*)iterPage_
+ sizeof(PageInfo
);
79 while(nodeOffset_
< noOfNodes_
)
81 if (*((int*)data
) == 0)
83 //not used, so skip it
84 data
= data
+ allocSize_
;
90 printDebug(DM_Iterator
,"ChunkID:%d Returning %x Page:%x nodeOffset:%d",
91 chunkID_
, data
+ sizeof(int), pageInfo
, nodeOffset_
);
92 return data
+sizeof(int);