fix: duplicated entries in epwing dictionary

This commit is contained in:
Xiao YiFang 2022-05-23 00:13:24 +08:00 committed by Abs62
parent f07ba75a5c
commit efb4a84da2
3 changed files with 35 additions and 11 deletions

View file

@ -44,7 +44,7 @@ namespace {
enum
{
Signature = 0x58575045, // EPWX on little-endian, XWPE on big-endian
CurrentFormatVersion = 5 + BtreeIndexing::FormatVersion + Folding::Version
CurrentFormatVersion = 6 + BtreeIndexing::FormatVersion + Folding::Version
};
struct IdxHeader

View file

@ -846,7 +846,7 @@ void EpwingBook::getFirstHeadword( EpwingHeadword & head )
fixHeadword( head.headword );
EWPos epos( pos.page, pos.offset );
allHeadwordPositions[ head.headword ] = epos;
allHeadwordPositions[ head.headword ] << epos;
}
bool EpwingBook::getNextHeadword( EpwingHeadword & head )
@ -877,13 +877,25 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head )
if( allHeadwordPositions.contains( head.headword ) )
{
EWPos epos = allHeadwordPositions[ head.headword ];
if( pos.page != epos.first || abs( pos.offset - epos.second ) > 4 )
// existed position
bool existed = false;
foreach( EWPos epos, allHeadwordPositions[ head.headword ] )
{
if( pos.page == epos.first && abs( pos.offset - epos.second ) <= 4 )
{
existed = true;
break;
}
}
if( !existed )
{
allHeadwordPositions[ head.headword ] << EWPos( pos.page, pos.offset );
return true;
}
}
else
{
allHeadwordPositions[ head.headword ] = EWPos( pos.page, pos.offset );
allHeadwordPositions[ head.headword ] << EWPos( pos.page, pos.offset );
return true;
}
}
@ -939,14 +951,26 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head )
if( allHeadwordPositions.contains( head.headword ) )
{
EWPos epos = allHeadwordPositions[ head.headword ];
if( pos.page != epos.first || abs( pos.offset - epos.second ) > 4 )
// existed position
bool existed = false;
foreach( EWPos epos, allHeadwordPositions[ head.headword ] )
{
if( pos.page == epos.first && abs( pos.offset - epos.second ) <= 4 )
{
existed = true;
break;
}
}
if( !existed )
{
allHeadwordPositions[ head.headword ] << EWPos( pos.page, pos.offset );
return true;
}
}
else
{
allHeadwordPositions[ head.headword ] = EWPos( pos.page, pos.offset );
break;
allHeadwordPositions[ head.headword ] << EWPos( pos.page, pos.offset );
return true;
}
}

View file

@ -74,7 +74,7 @@ class EpwingBook
QStringList imageCacheList, soundsCacheList, moviesCacheList, fontsCacheList;
QMap< QString, QString > baseFontsMap, customFontsMap;
QVector< int > refPages, refOffsets;
QMap< QString, EWPos > allHeadwordPositions;
QMap< QString, QList< EWPos > > allHeadwordPositions;
QVector< EWPos > LinksQueue;
int refOpenCount, refCloseCount;
static Mutex libMutex;