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 enum
{ {
Signature = 0x58575045, // EPWX on little-endian, XWPE on big-endian Signature = 0x58575045, // EPWX on little-endian, XWPE on big-endian
CurrentFormatVersion = 5 + BtreeIndexing::FormatVersion + Folding::Version CurrentFormatVersion = 6 + BtreeIndexing::FormatVersion + Folding::Version
}; };
struct IdxHeader struct IdxHeader

View file

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

View file

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