Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
l.cpp
Package: l.rar [view]
Upload User: fxdzsc
Upload Date: 2021-02-18
Package Size: 1k
Code Size: 2k
Category:
Compress-Decompress algrithms
Development Platform:
C/C++
- #include <codecogs/io/compression/lzw.h>
- #include <iostream>
- // the number of characters to generate in the sample array
- #define N 10000
- using namespace IO::Compression;
- int main()
- {
- // initialize random seed
- srand(time(0));
- // generate an array of N random letters
- std::vector<unsigned char> sample;
- for (int i = 0; i < N; ++i)
- sample.push_back('A' + rand() % ('Z' - 'A' + 1));
- // compress the sample array
- std::vector<unsigned char> compressed = LZW::compress(sample);
- // decompress the compressed array
- std::vector<unsigned char> uncompressed = LZW::decompress(compressed);
- // compare the sizes of the compressed and uncompressed arrays
- std::cout << " Size of the sample array: " << N << std::endl;
- std::cout << " Size of the compressed array: " << compressed.size() << std::endl;
- std::cout << "Size of the uncompressed array: " << uncompressed.size() << std::endl;
- std::cout << std::endl;
- // test if the sample and the uncompressed arrays are identical
- // this proves that the LZW compression algorithm does not affect the initial data
- bool identical = (N == uncompressed.size());
- for (size_t i = 0; identical && i < uncompressed.size(); ++i)
- if (sample[i] != uncompressed[i])
- identical = false;
- if (identical)
- std::cout << "The sample and uncompressed arrays are identical." << std::endl;
- else
- std::cout << "Error! The sample and uncompressed arrays are NOT identical." << std::endl;
- return 0;
- }