如何提高二进制文件的查找速度?

时间:2017-02-24 05:21:02

标签: vb.net

我正在搜索存储在二进制文件中的UInt64编号列表中的所有多个入口,如下所示:

Dim i, j, n, cnt As Integer
Dim a, b As UInt64
Dim reader As New BinaryReader(File.Open("c:\file.bin", FileMode.Open, FileAccess.Read, FileShare.Read))

n = 1000    
For i = 2 To n
    a = reader.ReadUInt64()
    reader.BaseStream.Seek(0, SeekOrigin.Begin)
    cnt = 0
    For j = 1 To i - 1
        b = reader.ReadUInt64()
        If b = a Then
            cnt += 1
        End If
    Next
Next

显然,顺序读取流非常快,但每次返回原点都非常耗时。我该如何优化效率?

0 个答案:

没有答案