2
0

huffman.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * $XConsortium: huffman.h /main/3 1996/06/11 17:15:11 cde-hal $
  25. *
  26. * Copyright (c) 1993 HAL Computer Systems International, Ltd.
  27. * All rights reserved. Unpublished -- rights reserved under
  28. * the Copyright Laws of the United States. USE OF A COPYRIGHT
  29. * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
  30. * OR DISCLOSURE.
  31. *
  32. * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
  33. * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
  34. * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
  35. * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
  36. * INTERNATIONAL, LTD.
  37. *
  38. * RESTRICTED RIGHTS LEGEND
  39. * Use, duplication, or disclosure by the Government is subject
  40. * to the restrictions as set forth in subparagraph (c)(l)(ii)
  41. * of the Rights in Technical Data and Computer Software clause
  42. * at DFARS 252.227-7013.
  43. *
  44. * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
  45. * 1315 Dell Avenue
  46. * Campbell, CA 95008
  47. *
  48. */
  49. #ifndef _huff_h
  50. #define _huff_h 1
  51. #include "compression/abs_agent.h"
  52. #include "compression/trie.h"
  53. ////////////////////////////////////////
  54. //
  55. ////////////////////////////////////////
  56. class htr_node
  57. {
  58. public:
  59. htr_node* left;
  60. htr_node* right;
  61. encoding_unit* eu;
  62. unsigned long freq;
  63. htr_node* parent;
  64. public:
  65. htr_node(encoding_unit* eu, htr_node* lt = 0, htr_node* rt = 0);
  66. htr_node(unsigned long freq, htr_node* lt = 0, htr_node* rt = 0);
  67. ~htr_node();
  68. };
  69. ////////////////////////////////////////
  70. //
  71. ////////////////////////////////////////
  72. class huff : public compress_agent
  73. {
  74. protected:
  75. encoding_unit** e_units;
  76. unsigned int cts ;
  77. trie* tri;
  78. htr_node* htr_root;
  79. protected:
  80. void build_tree();
  81. void calculate_code();
  82. encoding_unit* get_e_unit(unsigned char*& data, int len);
  83. public:
  84. huff();
  85. virtual ~huff() ;
  86. virtual void compress(const buffer& uncompressed, buffer& compressed) ;
  87. virtual void decompress(buffer& compressed, buffer& uncompressed) ;
  88. ostream& print_alphabet(ostream& out);
  89. MMDB_SIGNATURES(huff);
  90. // compacted disk representation In and Out functions
  91. virtual int cdr_sizeof();
  92. virtual io_status cdrOut(buffer&);
  93. virtual io_status cdrIn(buffer&);
  94. // get data to compute the alphabet
  95. virtual io_status build_dict(lex_func_t f_lex, getchar_func_t f_getchar);
  96. };
  97. extern huff g_huff_agent;
  98. #endif