Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BinCompressor.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. **
  3. ** Copyright (C) 1995-2011 Opera Software ASA. All rights reserved.
  4. **
  5. ** This file is part of the Opera web browser.
  6. ** It may not be distributed under any circumstances.
  7. */
  8. #ifndef BINCOMPRESSOR_H
  9. #define BINCOMPRESSOR_H
  10. #include "modules/search_engine/TypeDescriptor.h" // For the CHECK_RESULT macro
  11. /**
  12. * @brief Very fast algorithm to compress and decompress arbitrary data. UniCompressor is more efective for Unicode text.
  13. * @author Pavel Studeny <pavels@opera.com>
  14. */
  15. class BinCompressor : public NonCopyable
  16. {
  17. public:
  18. BinCompressor(void) {m_dict = NULL;}
  19. ~BinCompressor(void) {FreeCompDict();}
  20. /**
  21. * init internal ditionary, only needed for compression
  22. */
  23. CHECK_RESULT(OP_STATUS InitCompDict(void));
  24. /**
  25. * free internal dictionary
  26. */
  27. void FreeCompDict(void) {if (m_dict != NULL) OP_DELETEA(m_dict); m_dict = NULL;}
  28. /**
  29. * compress a block of unicode text
  30. * @param dst 69 * len / 68 + 8 B must be available
  31. * @param src data to compress
  32. * @param len length of src in bytes
  33. * @return length of output data stored in dst
  34. */
  35. unsigned Compress(unsigned char *dst, const void *src, unsigned len);
  36. /**
  37. * length of original data should be kept to allocate a sufficient buffer for decompression
  38. * @param dst buffer for decompressed data
  39. * @param src compressed data
  40. * @param len length of src in bytes
  41. * @return length of uncompressed data
  42. */
  43. unsigned Decompress(void *dst, const unsigned char *src, unsigned len);
  44. /**
  45. * @return the original length of the compressed data
  46. */
  47. unsigned Length(const unsigned char *src);
  48. protected:
  49. inline unsigned char *OutputLiteral(unsigned char *op, const unsigned char *sp, const unsigned char *cp);
  50. inline unsigned char *OutputMatch(unsigned char *op, unsigned length, unsigned short offset);
  51. UINT32 *m_dict;
  52. };
  53. #endif // BINCOMPRESSOR_H