- RSFD *rsfd;
- RSET *rset;
- int i, i_add = (to-from)/merge_chunk + 1;
- struct trunc_info *ti;
- int rscur = 0;
- int rsmax = (to-from)/i_add + 1;
-
- rset = xmalloc (sizeof(*rset) * rsmax);
- rsfd = xmalloc (sizeof(*rsfd) * rsmax);
-
- for (i = from; i < to; i += i_add)
- {
- if (i_add <= to - i)
- rset[rscur] = rset_trunc_r (isam, isam_p, i, i+i_add,
- merge_chunk);
- else
- rset[rscur] = rset_trunc_r (isam, isam_p, i, to,
- merge_chunk);
- rscur++;
- }
- ti = heap_init (rscur, sizeof(struct it_key), key_compare);
- for (i = rscur; --i >= 0; )
- {
- rsfd[i] = rset_open (rset[i], RSETF_READ|RSETF_SORT_SYSNO);
- if (rset_read (rset[i], rsfd[i], ti->tmpbuf))
- heap_insert (ti, ti->tmpbuf, i);
- else
- {
- rset_close (rset[i], rsfd[i]);
- rset_delete (rset[i]);
- }
- }
- while (ti->heapnum)