mir war ein wenig langweilig und ich habe versucht die Huffman-Kodierung mit AutoIT nach zu bauen. An sich funktioniert das ganze auch so ich wollte euch einfach mal Fragen ob man diesen Code ein wenig verbessern kann.
MfG Croco
PHP Code:
#include <Array.au3>
$String = "Das ist ein kleiner Test String"
$Spektrum = "abcdefghijklmnopqrstuvwxyzäü "
local $Baum[StringLen($Spektrum)+1][3]
local $Index = 1
For $i=1 to StringLen($Spektrum)
$Teil = StringRight(StringLeft($Spektrum,$i),1)
If StringInStr($String,$Teil) Then
StringReplace($String,$Teil,$Teil)
$Baum[$Index][0] = $Teil
$Baum[$Index][1] = @extended
$Index = $Index+1
IniWrite("Tabelle.ini","Huffman",$Teil,"")
EndIf
Next
$Index = $Index-1
$Baum[0][0] = $Index
$Baum2 = SortByNumber($Baum)
$Work = Partner($Baum2)
Do
$Work = SortByNumber($Work)
$Work = Partner($Work)
Until $Work[0][0] = 1
Func SortByNumber($Array)
local $Baum[$Array[0][0]+1][3]
$Cur = 0
For $i=1 to $Array[0][0]
If $Array[$i][1] > $Cur Then $Cur = $Array[$i][1]
Next
$Index = 1
For $i=1 to $Cur
For $x=1 to $Array[0][0]
If $Array[$x][1] = $i Then
$Baum[$Index][0] = $Array[$x][0]
$Baum[$Index][1] = $Array[$x][1]
$Index = $Index+1
EndIf
Next
Next
$Baum[0][0] = $Array[0][0]
Return $Baum
EndFunc
Func Partner($Array)
local $Partner = int($Array[0][0]/2)
local $Allone = Mod($Array[0][0],2)
local $Baum[($Partner+$Allone)+1][3]
local $Index = 1
For $i=1 to $Partner*2 Step 2
$Baum[$Index][0] = $Array[$i][0]&$Array[$i+1][0]
$Baum[$Index][1] = $Array[$i][1]+$Array[$i+1][1]
$Baum[$Index][2] = ""
$Index = $Index+1
If StringLen($Array[$i][0]) = 1 Then
INIExpand($Array[$i][0],0)
Else
For $z=1 to StringLen($Array[$i][0])
$Buchstabe = StringRight(StringLeft($Array[$i][0],$z),1)
INIExpand($Buchstabe,0)
Next
EndIf
If StringLen($Array[$i+1][0]) = 1 Then
INIExpand($Array[$i+1][0],1)
Else
For $z=1 to StringLen($Array[$i+1][0])
$Buchstabe = StringRight(StringLeft($Array[$i+1][0],$z),1)
INIExpand($Buchstabe,1)
Next
EndIf
Next
If $Allone > 0 Then
$L = $Array[0][0]
$Baum[($Partner+$Allone)][0] = $Array[$L][0]
$Baum[($Partner+$Allone)][1] = $Array[$L][1]
$Baum[($Partner+$Allone)][2] = $Array[$L][2]
EndIf
$Baum[0][0] = ($Partner+$Allone)
Return $Baum
EndFunc
Func INIExpand($Key,$Value)
$Is = IniRead("Tabelle.ini","Huffman",$Key,"")
IniWrite("Tabelle.ini","Huffman",$Key,$Is&$Value)
EndFunc
Quote:
[Huffman]
a=0110
c=1110
d=00001
e=100
f=00101
g=10001
h=1111
i=000
k=01001
l=10101
n=0111
o=01101
r=11001
s=0010
t=1010
u=11101
=011






