function time_end($start) { $end = time_micro(); $end = round($end - $start, 3); $end = pad_zeros($end, 3); return $end; }
function Expand() { if (!$this->havefiles) { $this->Error("Files not provided"); } if ($this->debug_time) { $this->debug_t1 = time_micro(); } // // WORKING WITH INPUT // // From header : reading Huffman tree (with no weights, mind you) $this->ReconstructTree(); // From header : number of characters to read (ie. size of output file) $this->ofsize = bindec($this->BitRead(24)); // // WORKING WITH OUTPUT // // Reading bit-by-bit and generating output $this->Read2MakeOutput(); // Writing the output and closing resource handles fwrite($this->ofhand, $this->odata); fclose($this->ofhand); fclose($this->ifhand); if ($this->debug_time) { $this->debug_t2 = time_micro(); } // Calling Debug stuff in case any has been activated $this->ShowDebug(); }
function Compress() { if (!$this->havefiles) { $this->Error("Files not provided"); } if ($this->debug_time) { $this->debug_t1 = time_micro(); } // // WORKING WITH INPUT // // Counting letter occurrences in input file $this->CountOccurrences(); // Converting occurrences into basic nodes // The nodes array has been initialized, as it will be filled with dynamic incrementation $this->Occs2Nodes(); // Construction of the Huffman tree $this->MakeHuffmanTree(); // Constructing character codes $this->MakeCharCodes(); // // WORKING WITH OUTPUT // //!! No need for 8 bits of nb of chars in alphabet ?? still use $this -> nbchars ? NO //!! No need for 8+5+codelen bits of chars & codes ?? still use $this -> codelens array ? YES // Header : passing the Huffman tree with an automatically stopping algorithm $this->TransmitTree(); // End of header : number of chars actually encoded, over 3 bytes $this->BitWrite(DecBinDig($this->ifsize, 24), 24); // Contents : compressed data rewind($this->ifhand); while (($char = fgetc($this->ifhand)) !== FALSE) { $this->BitWrite($this->codes[$char], $this->codelens[$char]); } // Finalising output, closing file handles $this->BitWrite_End(); fclose($this->ofhand); fclose($this->ifhand); if ($this->debug_time) { $this->debug_t2 = time_micro(); } // Calling Debug stuff in case any has been activated $this->ShowDebug(); }