@@ -200,87 +200,4 @@ Public Class Estimator
200200
201201
202202
203-
204-
205- 'Public Function EstimateEntropy(path As String) As Double
206- ' Using fs As FileStream = File.OpenRead(path)
207- ' Return EntropyCompressionRatio(fs)
208- ' End Using
209- 'End Function
210-
211- 'Public Function EntropyCompressionRatio(input As Stream) As Double
212- ' Dim counts(255) As Long
213- ' Dim total As Long = 0
214- ' Dim bufferSize As Integer = 65536 ' 64 KB buffer for efficiency
215- ' Dim buffer(bufferSize - 1) As Byte
216-
217- ' input.Position = 0
218- ' Dim bytesRead As Integer
219-
220- ' Do
221- ' bytesRead = input.Read(buffer, 0, bufferSize)
222- ' If bytesRead = 0 Then Exit Do
223- ' For i As Integer = 0 To bytesRead - 1
224- ' counts(buffer(i)) += 1
225- ' Next
226- ' total += bytesRead
227- ' Loop While bytesRead > 0
228-
229- ' If total = 0 Then Return 1.0 ' empty stream, treat as incompressible
230-
231- ' Dim entropy As Double = 0.0
232- ' For i = 0 To 255
233- ' If counts(i) > 0 Then
234- ' Dim p = counts(i) / total
235- ' entropy -= p * Math.Log(p, 2)
236- ' End If
237- ' Next
238- ' ' Convert entropy (bits/byte) to compression ratio
239- ' Return Math.Min(entropy / 8.0, 1.0)
240- 'End Function
241-
242- 'Public Function EstimateZlibCompressionRatio(filePath As String, fileSize As Long) As Double
243-
244- ' Dim blocks As Single = fileSize \ BlockSize
245- ' Dim samples As Integer = Math.Ceiling((blocks * N0) / (N0 + blocks - 1))
246- ' Dim skipBlocks As Integer = 1
247- ' If samples > 0 Then
248- ' skipBlocks = Math.Max(1, blocks \ samples)
249- ' End If
250-
251-
252-
253- ' Dim totalOriginal As Long = 0
254- ' Dim totalCompressed As Long = 0
255-
256- ' Using inputStream As New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)
257- ' ' Create a memory stream to hold the compressed output
258- ' Using compressedOut As New MemoryStream()
259- ' Using zlibStream As New ZLibStream(compressedOut, CompressionLevel.Fastest, True)
260- ' Dim buffer(BlockSize - 1) As Byte
261- ' Dim bytesRead As Integer
262- ' Dim blockIndex As Integer = 0
263-
264- ' Do
265- ' bytesRead = inputStream.Read(buffer, 0, BlockSize)
266- ' If bytesRead <= 0 Then Exit Do
267-
268- ' If blockIndex Mod skipBlocks = 0 Then
269- ' zlibStream.Write(buffer, 0, bytesRead)
270- ' totalOriginal += bytesRead
271- ' End If
272-
273- ' blockIndex += 1
274- ' Loop
275-
276- ' zlibStream.Flush()
277- ' End Using
278- ' totalCompressed = compressedOut.Length
279- ' End Using
280- ' End Using
281-
282- ' If totalOriginal = 0 Then Return 1.0 ' Prevent division by zero
283- ' Return Math.Round(totalCompressed / totalOriginal, 3)
284- 'End Function
285-
286203End Class
0 commit comments