解壓zip VBA解壓縮ZIP檔案11 存在問題

2021-10-16 03:14:33 字數 3744 閱讀 4704

解壓功能實現了,但是還是存在問題的:

第2個問題是因為huffman樹的節點使用的是類模組,在記憶體釋放上有點問題,目前沒找到原因。

嘗試使用陣列去處理,測試記憶體釋放應該是正常了,另外速度也提公升了,12m檔案,用時38秒左右!

使用陣列記錄節點的huffman類模組:

private type node    weight as long    left as long    right as long    key as long    parent as longend typeprivate nodes() as nodeprivate pnode as long'樹的root節點private root as longprivate const null_value as long = &h80000000'建立樹結構public function create(weightvalues() as long, keys() as long) as long    dim inum as long    inum = ubound(keys)        insertsort weightvalues, keys, 0, inum    '節點的個數不會超過一顆最大層次的完整的2叉樹    redim nodes(2 ^ weightvalues(inum) * 2 - 1) as node        root = newnode(0, null_value, null_value, null_value)        dim parr as long    dim tmp as long        dim n as long    n = root        do until parr = inum + 1            do until nodes(n).key = weightvalues(parr)            if nodes(n).weight = 2 then                '新建左子樹                tmp = newnode(nodes(n).key + 1, null_value, null_value, n)                nodes(n).left = tmp                nodes(n).weight = nodes(n).weight - 1                n = tmp                            elseif nodes(n).weight = 1 then                '新建右子樹                tmp = newnode(nodes(n).key + 1, null_value, null_value, n)                nodes(n).right = tmp                nodes(n).weight = nodes(n).weight - 1                n = tmp                            else '= 0                n = nodes(n).parent            end if                    loop        nodes(n).key = keys(parr)        parr = parr + 1        n = nodes(n).parent    loop    end function'找到葉子節點的key'從bitindex位置,逐個讀取cpbyte中的bit,直到葉子節點function getleafkey(cpbyte() as byte, byref bitindex as long) as long    dim bvalue as long    dim n as long    n = root        'huffmantree裡把葉子節點的weight設定成了2    do until nodes(n).weight = 2        '逐個bit的去h中查詢,到達葉子節點為止        bvalue = getbit(cpbyte, bitindex)        bitindex = bitindex + 1        '1的時候右        if bvalue then            n = nodes(n).right        else            n = nodes(n).left        end if    loop        getleafkey = nodes(n).key    end functionprivate function insertsort(weightvalues() as long, keys() as long, low as long, high as long)    dim i as long, j as long    dim shaobing as long, shaobing_tmp as long        '先按arr_code_len排序    for i = low + 1 to high        if weightvalues(i) < weightvalues(i - 1) then            shaobing = weightvalues(i)             '設定哨兵            shaobing_tmp = keys(i)                        j = i - 1            do while weightvalues(j) > shaobing                weightvalues(j + 1) = weightvalues(j)                keys(j + 1) = keys(j)                j = j - 1                if j = low - 1 then exit do            loop                        weightvalues(j + 1) = shaobing            keys(j + 1) = shaobing_tmp        end if    next iend function'返回陣列的下標private function newnode(key as long, left as long, right as long, parent as long) as long    nodes(pnode).weight = 2    nodes(pnode).key = key        nodes(pnode).left = left    nodes(pnode).right = right    nodes(pnode).parent = parent        newnode = pnode    pnode = pnode + 1end functionpublic sub printout()    rprintout root, ""end subprivate function rprintout(n as long, str as string)    if nodes(n).weight = 2 then        debug.print str, nodes(n).key                exit function    else        rprintout nodes(n).left, str & "0"        rprintout nodes(n).right, str & "1"    end ifend functionprivate sub class_terminate()    erase nodesend sub
問題3和問題4因為一般應該也碰不到,真有那麼大的問題,也不至於用vba來解壓!暫時就不想著去解決了。

zip解壓縮方式

解壓縮類 在導包的時候,應新增ant.jar解壓縮包 直接貼 public class ziputil public static ziputil getinstance return instance 解壓縮zip包 param zipfilepath zip檔案路徑 param targetpa...

zip命令解壓縮

解壓aa.zip到指定資料夾 unzip aa.zip d opt module aa 語法 unzip cflptuvz agcjlmnoqsvx p 密 碼 zip文 件 檔案 d 目錄 x 檔案 或 unzip z 引數說明 c 將 解壓縮的結果顯示到螢幕上,並對字元做適當的轉換。f 更 新現...

zip壓縮與解壓縮示例

範例 zip命令可以用來將檔案壓縮成為常用的zip格式。unzip命令則用來解壓縮zip檔案。1.我想把乙個檔案abc.txt和乙個目錄dir1壓縮成為yasuo.zip zip r yasuo.zip abc.txt dir1 unzip yasuo.zip 3.我當前目錄下有abc1.zip,a...