chore: remove unused index comparison and decode helpers
IndexSearcher.compareEntryGroups / IndexComparisonSummary / IndexComparisonException / readEntryOrNull and AboutLibrariesData.decode have no call sites left in the app.
This commit is contained in:
@@ -45,12 +45,6 @@ class IndexSearcher(private val context: Context) {
|
|||||||
val dataStartOffset: Long
|
val dataStartOffset: Long
|
||||||
)
|
)
|
||||||
|
|
||||||
data class IndexComparisonSummary(
|
|
||||||
val expectedCount: Int,
|
|
||||||
val actualCount: Int,
|
|
||||||
val comparedCount: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class RangeCursor(
|
data class RangeCursor(
|
||||||
val rangeQuery: String,
|
val rangeQuery: String,
|
||||||
val absoluteIndex: Int,
|
val absoluteIndex: Int,
|
||||||
@@ -72,8 +66,6 @@ class IndexSearcher(private val context: Context) {
|
|||||||
val cursorAfter: RangeCursor?
|
val cursorAfter: RangeCursor?
|
||||||
)
|
)
|
||||||
|
|
||||||
class IndexComparisonException(message: String) : IllegalStateException(message)
|
|
||||||
|
|
||||||
suspend fun findFirstEntry(pathOrUri: String, query: String): IndexEntry? = withContext(Dispatchers.Default) {
|
suspend fun findFirstEntry(pathOrUri: String, query: String): IndexEntry? = withContext(Dispatchers.Default) {
|
||||||
val normalizedQuery = query.sanitizeQuery().lowercase().trim()
|
val normalizedQuery = query.sanitizeQuery().lowercase().trim()
|
||||||
try {
|
try {
|
||||||
@@ -244,99 +236,6 @@ class IndexSearcher(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun compareEntryGroups(
|
|
||||||
expectedIndexPath: String,
|
|
||||||
actualIndexPath: String,
|
|
||||||
onGroup: suspend (word: String, expected: List<IndexEntry>, actual: List<IndexEntry>) -> Unit
|
|
||||||
): IndexComparisonSummary = withContext(Dispatchers.IO) {
|
|
||||||
val expectedMetadata = loadMetadata(expectedIndexPath)
|
|
||||||
val actualMetadata = loadMetadata(actualIndexPath)
|
|
||||||
|
|
||||||
if (expectedMetadata.totalCount != actualMetadata.totalCount) {
|
|
||||||
throw IndexComparisonException(
|
|
||||||
"Index entry count differs: expected=${expectedMetadata.totalCount}, " +
|
|
||||||
"actual=${actualMetadata.totalCount}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
openSource(expectedIndexPath).use { expectedSource ->
|
|
||||||
openSource(actualIndexPath).use { actualSource ->
|
|
||||||
expectedSource.seek(expectedMetadata.dataStartOffset)
|
|
||||||
actualSource.seek(actualMetadata.dataStartOffset)
|
|
||||||
|
|
||||||
var expectedNext = readEntryOrNull(expectedSource, expectedMetadata, expectedMetadata.totalCount > 0)
|
|
||||||
var actualNext = readEntryOrNull(actualSource, actualMetadata, actualMetadata.totalCount > 0)
|
|
||||||
var comparedCount = 0
|
|
||||||
|
|
||||||
while (expectedNext != null && actualNext != null) {
|
|
||||||
if (expectedNext.word != actualNext.word) {
|
|
||||||
throw IndexComparisonException(
|
|
||||||
"Index words differ at entry $comparedCount: " +
|
|
||||||
"expected=${expectedNext.word}, actual=${actualNext.word}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val word = expectedNext.word
|
|
||||||
val expectedGroup = mutableListOf<IndexEntry>()
|
|
||||||
val actualGroup = mutableListOf<IndexEntry>()
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
val current = expectedNext ?: break
|
|
||||||
if (current.word != word) break
|
|
||||||
expectedGroup.add(current)
|
|
||||||
comparedCount++
|
|
||||||
expectedNext = readEntryOrNull(
|
|
||||||
expectedSource,
|
|
||||||
expectedMetadata,
|
|
||||||
comparedCount < expectedMetadata.totalCount
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
var actualReadCount = comparedCount - expectedGroup.size
|
|
||||||
while (true) {
|
|
||||||
val current = actualNext ?: break
|
|
||||||
if (current.word != word) break
|
|
||||||
actualGroup.add(current)
|
|
||||||
actualReadCount++
|
|
||||||
actualNext = readEntryOrNull(
|
|
||||||
actualSource,
|
|
||||||
actualMetadata,
|
|
||||||
actualReadCount < actualMetadata.totalCount
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expectedGroup.size != actualGroup.size) {
|
|
||||||
throw IndexComparisonException(
|
|
||||||
"Headword multiplicity differs for '$word': " +
|
|
||||||
"expected=${expectedGroup.size}, actual=${actualGroup.size}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onGroup(word, expectedGroup, actualGroup)
|
|
||||||
if (comparedCount % 10_000 == 0) yield()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expectedNext != null || actualNext != null) {
|
|
||||||
throw IndexComparisonException(
|
|
||||||
"One index ended before the other at entry $comparedCount"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
IndexComparisonSummary(
|
|
||||||
expectedCount = expectedMetadata.totalCount,
|
|
||||||
actualCount = actualMetadata.totalCount,
|
|
||||||
comparedCount = comparedCount
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun readEntryOrNull(
|
|
||||||
source: RandomAccessSource,
|
|
||||||
metadata: IndexMetadata,
|
|
||||||
shouldRead: Boolean
|
|
||||||
): IndexEntry? = if (shouldRead) readEntry(source, metadata) else null
|
|
||||||
|
|
||||||
fun trimMemory(level: Int) {
|
fun trimMemory(level: Int) {
|
||||||
metadataCache.trim(level)
|
metadataCache.trim(level)
|
||||||
resultsCache.trim(level)
|
resultsCache.trim(level)
|
||||||
|
|||||||
@@ -78,6 +78,4 @@ internal object AboutLibrariesParser {
|
|||||||
context.resources.openRawResource(resourceId)
|
context.resources.openRawResource(resourceId)
|
||||||
.bufferedReader()
|
.bufferedReader()
|
||||||
.use { reader -> json.decodeFromString(reader.readText()) }
|
.use { reader -> json.decodeFromString(reader.readText()) }
|
||||||
|
|
||||||
fun decode(source: String): AboutLibrariesData = json.decodeFromString(source)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user