source: trunk/gsdl/src/mgpp/text/FragLevelConvert.cpp@ 2468

Last change on this file since 2468 was 2468, checked in by sjboddie, 23 years ago

Fiddled about with mgpp to get it compiling on Windows under VC++ 6.0. I
still can't get it to compile under VC++ 4.2 because of some weird
behaviour in STLport.

Also tidied up a little and removed some of the old log information
that was scattered about in some of the files.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/**************************************************************************
2 *
3 * FragLevelConvert.cpp -- converting between fragment and document numbers
4 * Copyright (C) 1999 Rodger McNab
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 **************************************************************************/
21
22#include "FragLevelConvert.h"
23#include "bitio_m_stdio.h"
24#include "bitio_gen.h"
25
26
27FragLevelConvert::FragLevelConvert () {
28 numFrags = 0;
29 numLevelDocs = 0;
30}
31
32bool FragLevelConvert::Read (FILE *invfFile,
33 unsigned long levelPtr,
34 unsigned long _numFrags,
35 unsigned long _numLevelDocs) {
36 levelStarts.erase (levelStarts.begin(), levelStarts.end());
37 numFrags = _numFrags;
38 numLevelDocs = _numLevelDocs;
39
40 // seek to the appropriate place in the inverted file
41 fseek (invfFile, levelPtr, SEEK_SET);
42
43 stdio_bitio_buffer buffer(invfFile);
44
45 unsigned long pTag = numLevelDocs*2;
46 unsigned long B = BIO_Bblock_Init (numFrags+pTag, pTag);
47 unsigned long fragNum = 0;
48 unsigned long i;
49 for (i=0; i<numLevelDocs; i++) {
50 unsigned long delta = buffer.bblock_decode (B, NULL)-1;
51 fragNum += delta;
52
53 levelStarts.push_back (fragNum);
54
55 // ignore end, assume every fragment is in a level
56 delta = buffer.bblock_decode (B, NULL)-1;
57 fragNum += delta;
58 }
59
60 // fragNum would be the starting fragment of the next document
61 // if there was one
62 levelStarts.push_back (fragNum);
63
64 buffer.done();
65
66 return true;
67}
68
69bool FragLevelConvert::FragToLevel (unsigned long fragNum,
70 unsigned long &levelDocNum) const {
71 // do binary search for something containing this fragment number
72 unsigned long low = 1, high = numLevelDocs;
73 unsigned long mid;
74
75 while ((mid = (low+high)/2) >= 1 && low <= high) {
76 if (fragNum > levelStarts[mid]) low = mid+1;
77 else if (fragNum <= levelStarts[mid-1]) high = mid-1;
78 else {
79 levelDocNum = mid;
80 return true;
81 }
82 }
83 return false;
84}
85
86
87bool FragLevelConvert::LevelToLevel (FragLevelConvert sectionLevelConvert,
88 unsigned long levelNum, unsigned long &DocNum) {
89
90 if (levelNum==1) {
91 DocNum=1;
92 return true;
93 }
94 unsigned long levelfragnum = sectionLevelConvert.levelStarts[levelNum-1]+1;
95
96 if (FragToLevel(levelfragnum, DocNum)) {
97 return true;
98 }
99 return false;
100
101
102}
Note: See TracBrowser for help on using the repository browser.