MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / getMerge

Method getMerge

src/jrd/sort.cpp:1178–1348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1176
1177
1178sort_record* Sort::getMerge(merge_control* merge)
1179{
1180/**************************************
1181 *
1182 * Get next record from a merge tree and/or run_control.
1183 *
1184 **************************************/
1185 SORTP *p; // no more than 1 SORTP* to a line
1186 SORTP *q; // no more than 1 SORTP* to a line
1187 ULONG l;
1188 ULONG n;
1189
1190 sort_record* record = NULL;
1191 bool eof = false;
1192
1193 while (merge)
1194 {
1195 // If node is a run_control, get the next record (or not) and back to parent
1196
1197 if (merge->mrg_header.rmh_type == RMH_TYPE_RUN)
1198 {
1199 run_control* run = (run_control*) merge;
1200 merge = run->run_header.rmh_parent;
1201
1202 // check for end-of-file condition in either direction
1203
1204 if (run->run_records == 0)
1205 {
1206 record = (sort_record*) - 1;
1207 eof = true;
1208 continue;
1209 }
1210
1211 eof = false;
1212
1213 // Find the appropriate record in the buffer to return
1214
1215 if ((record = (sort_record*) run->run_record) < (sort_record*) run->run_end_buffer)
1216 {
1217 run->run_record = reinterpret_cast<sort_record*>(NEXT_RUN_RECORD(run->run_record));
1218 --run->run_records;
1219 continue;
1220 }
1221
1222 // There are records remaining, but the buffer is full.
1223 // Read a buffer full.
1224
1225 l = (ULONG) (run->run_end_buffer - run->run_buffer);
1226 n = run->run_records * m_longs * sizeof(ULONG);
1227 l = MIN(l, n);
1228 run->run_seek = readBlock(m_space, run->run_seek, run->run_buffer, l);
1229
1230 record = reinterpret_cast<sort_record*>(run->run_buffer);
1231 run->run_record =
1232 reinterpret_cast<sort_record*>(NEXT_RUN_RECORD(record));
1233 --run->run_records;
1234
1235 continue;

Callers

nothing calls this directly

Calls 2

diddleKeyMethod · 0.80
getRecordMethod · 0.45

Tested by

no test coverage detected