45.
BA.AddBitsData.Length, 32 BA.AddBitsSymbolCodes.Count \ 2, 8
StoreTreeNode, BA
C6 n
C6n 46.
For I = 0
To Data.Length - 1
C3 n
C3n 47.
For I2 = 0
To SYMDataI.Length - 1
C3 n
C3n 48.
BA.AddBitSYMDataI.SubstringI2, 1 Next
Next
C6 n
C6n
49.
BA.FlushBuffer Return
BA.GetBitsArray End Function
C6 n
C6n
b. Dekompresi
50.
Public Function DecompressByteArray
ByVal Data
As Byte As Byte
C1 1
C1 51.
Dim BA
As New bitsarray
C2 n
C2n 52.
BA.SetArrayData
C6 n
C6n 53.
Dim Length
As Long = BA.ReadBits32
C2 n
C2n 54.
Dim NoOfSymbols = BA.ReadBits8
C2 n
C2n 55.
Dim Node
As New BinaryTreeNode
C2 n
C2n 56.
Node.Symbol = -1
C5 n
C5n 57.
LoadTreeNode, BA
C6 n
C6n 58.
Dim SymbolCodes
As Collection
= GetSymbolCodesNode,
C2 n
C2n 59.
Dim SYM0
To 255
As String
C2 n
C2n 60.
Dim I2
As Integer
C2 n
C2n 61.
For I = 0
To 255
C3 n
C3n 62.
For I2 = 1
To SymbolCodes.Count
Step 2
C3 n
C3n 63.
If SymbolCodesI2 = I
Then
C4 n
C4n 64.
SYMI = SymbolCodesI2 + 1 End If
Next Next
C5 n
C5n 65.
Dim Result0
To Length - 1
As Byte
C2 n
C2n 66.
Dim Bt
As String =
C2 n
C2n 67.
Dim RC
As Long = 0
C2 n
C2n 68.
Dim FLG
As Boolean
C2 n
C2n 69.
Do While RC Length
FLG = False
C6 n
C6n 70.
For i = 0
To 255
C3 n
C3n
Universitas Sumatera Utara
71.
If SYMi = Bt
And bt
Then ResultRC = i
RC = RC + 1 Bt =
FLG = True
Exit For End If
Next
C4 n
C4n
72.
If Not FLG
Then Bt = Bt BA.ReadBit
End If Loop
Return Result
End Function End Module
C4 n
C4n
T|n| = C
1
n + 24C
2
+12C
3
+ 7C
4
+ 21C
5
+7C
6
n
1
= θ n Log n
Sesuai dengan penghitungan ang menjadi kompleksitas algoritma Huffman adalah T|n| =
θ n Log n. Misalnya nilai n=1.000.000 maka nilai kompleksitas T|n| = θ n Log n adalah T|n| = 1.000.0000 Log 1.000.000 = 6.000.000.
4.3.2. Perhitungan Kompleksitas Waktu Algoritma Run Length Encoding Berikut adalah tabel perhitungan kompleksitas waktu untuk algoritma Huffman dapat
dilihat pada tabel 4.5. berikut.
Tabel 4.4. Perhitungan Kompleksitas Waktu Algoritma RLE a. Kompresi
No Code
C C
1.
Function RLEEncode
ByVal Bytes
As Byte As
Byte
C1 1
C1 2.
Dim PreviousByte
As Byte = Bytes0
C2 1
C2 3.
Dim ByteCount
As Byte = 0
C2 1
C2 4.
Dim OutputBytes
As New System.Collections.Generic.
Queue Of Byte
C2 1
C2 5.
For CurrentByte
As Integer = 1
To Bytes.Length – 1
C3 n
C3n 6.
If BytesCurrentByte = PreviousByte
And ByteCount 255
Then
C4 n
C4n 7.
ByteCount = CByte
ByteCount + 1
C5 n
C5n
Universitas Sumatera Utara
8.
Else
C6 n
C6n 9.
OutputBytes.EnqueueByteCount
n C6n
10.
OutputBytes.EnqueuePreviousByte
C6 n
C6n 11.
PreviousByte = BytesCurrentByte
C6 n
C6n 12.
ByteCount = 0 End If
Next
C6 n
C6n 13.
14. 15.
OutputBytes.EnqueueByteCount
C6 n
C6n 16.
OutputBytes.EnqueuePreviousByte
C6 n
C6n 17.
Return OutputBytes.ToArray
End Function
C7 n
C7n
b. Dekompresi