140a16a6dd076356dffd042fc9168f08ad521134
35 #define CURR_CDAT (*cdat_stackp)
36 #define CURR_SET set_list[CURR_CDAT->num_sets]
37 #define REF_IDX (num_refs % (refs_per_page * pages_per_chunk))
38 #define PREV_REF (ref_buf[num_ref_chunks] + (REF_IDX * (sizeof (struct ref)) + pagesize - (sizeof (struct ref))))
39 #define CURR_REF (ref_buf[num_ref_chunks] + (REF_IDX * (sizeof (struct ref)) + pagesize))
40 #define ODAT_IDX (num_odats % (odats_per_page * pages_per_chunk))
41 #define CURR_ODAT (odat_buf[num_odat_chunks] + (ODAT_IDX * (sizeof (struct odat)) + pagesize))
42 #define VDAT_IDX (num_vdats % (vdats_per_page * pages_per_chunk))
43 #define CURR_VDAT (vdat_buf[num_vdat_chunks] + (VDAT_IDX * (sizeof (struct vdat)) + pagesize))
44 #define CURR_MODEL (CURR_VDAT.model_list[CURR_VDAT.num_models])
45 #define CURR_LINK (link_buf[num_links])
46 #define CURR_POST (post_buf[num_posts])
47 #define CURR_QUAD (CURR_ODAT->quad_file)
51 int pages_per_chunk
= 10;
54 int curr_max_cdats
= PTRS_IN_PAGE
;
56 struct cdat
* cdat_buf
[PTRS_IN_PAGE
];
57 struct cdat
* cdat_stack
[PTRS_IN_PAGE
];
58 struct cdat
** cdat_stackp
;
61 int num_odat_chunks
= 0;
63 void* odat_buf
[MAX_CHUNKS
];
66 int num_vdat_chunks
= 0;
68 void* vdat_buf
[MAX_CHUNKS
];
71 int num_ref_chunks
= 0;
73 void* ref_buf
[MAX_CHUNKS
];
75 uint64_t ss_ref_id
= 0x00FFFFFF; /* system space for ref_ids */
78 int curr_max_posts
= PTRS_IN_PAGE
;
79 struct ref
* post_buf
[PTRS_IN_PAGE
];
83 int curr_max_links
= PTRS_IN_PAGE
;
84 struct link
* link_buf
[PTRS_IN_PAGE
];
87 /* The initalization function of the IR. */
92 /* Init root cdat and stack */
93 char root
[4] = "root";
95 if( (cdat_buf
[num_cdats
] = (struct cdat
*) malloc(sizeof(struct cdat
))) == NULL
)
97 perror("malloc root class failed\n");
100 cdat_buf
[num_cdats
]->idx
= num_cdats
;
101 memmove(cdat_buf
[num_cdats
]->name
, root
, 4);
103 cdat_stackp
= cdat_stack
;
104 *cdat_stackp
++ = cdat_buf
[num_cdats
++];
106 pagesize
= sysconf(_SC_PAGESIZE
);
107 odats_per_page
= (sizeof (struct odat
)/pagesize
);
108 vdats_per_page
= (sizeof (struct vdat
)/pagesize
);
109 refs_per_page
= (sizeof (struct ref
)/pagesize
);
120 for(i
= 0; i
<= num_odats
; i
++)
124 for(i
= 0; i
<= num_cdats
; i
++)
128 for(i
= 0; i
<= num_vdats
; i
++)
132 for(i
= 0; i
<= num_refs
; i
++)
136 for(i
= 0; i
<= num_links
; i
++)
148 if(curr_max_cdats
<= num_cdats
)
149 { if( (realloc((void*) cdat_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
150 perror("realloc cdat_buf failed");
151 curr_max_cdats
+= PTRS_IN_PAGE
;
152 if( (realloc( (void*) cdat_stack
, PTRS_IN_PAGE
* 4)) == NULL
) //increase cdat_stack also
153 perror("realloc cdat_stack failed");
155 if( (CURR_CDAT
= (struct cdat
*) malloc(sizeof (struct cdat
)) ) == NULL
)
156 perror("malloc cdat failed");
167 if(!(num_odats
% (odats_per_page
* pages_per_chunk
))) //chunk is full
170 if( ((odat_buf
[num_odat_chunks
] = malloc(odats_per_page
* pages_per_chunk
)) == NULL
) )
171 perror("malloc odat chunk failed");
183 if(!(num_vdats
% (vdats_per_page
* pages_per_chunk
))) //chunk is full
186 if( ((vdat_buf
[num_vdat_chunks
] = malloc(vdats_per_page
* pages_per_chunk
)) == NULL
) )
187 perror("malloc vdat chunk failed");
198 if(num_links
>= curr_max_links
)
199 { if( (realloc((void*) link_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
200 perror("realloc vdat_buf failed");
201 curr_max_links
+= PTRS_IN_PAGE
;
203 if((CURR_LINK
= (struct link
*) malloc(sizeof (struct link
))) == NULL
)
204 perror("malloc link failed");
215 if(num_refs
% 16 == 0)
216 { CURR_POST
= CURR_REF
;
219 if(!(num_refs
% (refs_per_page
* pages_per_chunk
))) //chunk is full
222 if( ((ref_buf
[num_ref_chunks
] = malloc(refs_per_page
* pages_per_chunk
)) == NULL
) )
223 perror("malloc ref chunk failed");
232 if(num_posts
>= curr_max_posts
)
233 { if( (realloc((void*) ref_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
234 perror("realoc post_buf failed");
235 curr_max_posts
+= PTRS_IN_PAGE
;
237 if ((CURR_POST
= (struct ref
*) malloc (sizeof (struct ref
))) == NULL
)
238 perror("malloc post failed");
265 return &CURR_CDAT
->CURR_SET
;