Skip to content
Browse files

set svn:eol-style to "native"

  • Loading branch information...
1 parent d8e2d83 commit 705e02197163b41b0f88ad0326592b6ad06bc52b @fancycode committed Oct 14, 2005
Showing with 9,583 additions and 9,583 deletions.
  1. +76 −76 7zip/7zip/Common/InBuffer.h
  2. +70 −70 7zip/7zip/Common/OutBuffer.cpp
  3. +71 −71 7zip/7zip/Common/OutBuffer.h
  4. +8 −8 7zip/7zip/Common/StdAfx.h
  5. +55 −55 7zip/7zip/Compress/LZ/BinTree/BinTree.h
  6. +12 −12 7zip/7zip/Compress/LZ/BinTree/BinTree2.h
  7. +16 −16 7zip/7zip/Compress/LZ/BinTree/BinTree3.h
  8. +16 −16 7zip/7zip/Compress/LZ/BinTree/BinTree3Z.h
  9. +18 −18 7zip/7zip/Compress/LZ/BinTree/BinTree4.h
  10. +20 −20 7zip/7zip/Compress/LZ/BinTree/BinTree4b.h
  11. +444 −444 7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h
  12. +63 −63 7zip/7zip/Compress/LZ/IMatchFinder.h
  13. +99 −99 7zip/7zip/Compress/LZ/LZInWindow.cpp
  14. +84 −84 7zip/7zip/Compress/LZ/LZInWindow.h
  15. +312 −312 7zip/7zip/Compress/LZ/MT/MT.cpp
  16. +83 −83 7zip/7zip/Compress/LZ/MT/MT.h
  17. +8 −8 7zip/7zip/Compress/LZ/MT/StdAfx.h
  18. +6 −6 7zip/7zip/Compress/LZ/StdAfx.h
  19. +82 −82 7zip/7zip/Compress/LZMA/LZMA.h
  20. +356 −356 7zip/7zip/Compress/LZMA/LZMADecoder.cpp
  21. +239 −239 7zip/7zip/Compress/LZMA/LZMADecoder.h
  22. +1,484 −1,484 7zip/7zip/Compress/LZMA/LZMAEncoder.cpp
  23. +416 −416 7zip/7zip/Compress/LZMA/LZMAEncoder.h
  24. +8 −8 7zip/7zip/Compress/LZMA/StdAfx.h
  25. +240 −240 7zip/7zip/Compress/RangeCoder/RangeCoder.h
  26. +80 −80 7zip/7zip/Compress/RangeCoder/RangeCoderBit.cpp
  27. +120 −120 7zip/7zip/Compress/RangeCoder/RangeCoderBit.h
  28. +161 −161 7zip/7zip/Compress/RangeCoder/RangeCoderBitTree.h
  29. +31 −31 7zip/7zip/Compress/RangeCoder/RangeCoderOpt.h
  30. +6 −6 7zip/7zip/Compress/RangeCoder/StdAfx.h
  31. +200 −200 7zip/7zip/ICoder.h
  32. +79 −79 7zip/7zip/IStream.h
  33. +79 −79 7zip/Common/Alloc.cpp
  34. +14 −14 7zip/Common/Alloc.h
  35. +75 −75 7zip/Common/Buffer.h
  36. +61 −61 7zip/Common/CRC.cpp
  37. +35 −35 7zip/Common/CRC.h
  38. +12 −12 7zip/Common/ComTry.h
  39. +20 −20 7zip/Common/Defs.h
  40. +201 −201 7zip/Common/MyCom.h
  41. +24 −24 7zip/Common/MyUnknown.h
  42. +184 −184 7zip/Common/MyWindows.h
  43. +8 −8 7zip/Common/StdAfx.h
  44. +19 −19 7zip/Common/Types.h
  45. +37 −37 7zip/OS/Handle.h
  46. +8 −8 7zip/OS/StdAfx.h
  47. +17 −17 7zip/OS/Synchronization.cpp
  48. +114 −114 7zip/OS/Synchronization.h
  49. +52 −52 7zip/OS/Thread.h
  50. +181 −181 7zip/readme.txt
  51. +504 −504 LICENSE.txt
  52. +588 −588 py7zlib.py
  53. +63 −63 pylzma.c
  54. +43 −43 pylzma.h
  55. +165 −165 pylzma_compress.cpp
  56. +34 −34 pylzma_compress.h
  57. +241 −241 pylzma_compressfile.cpp
  58. +36 −36 pylzma_compressfile.h
  59. +242 −242 pylzma_compressobj.cpp
  60. +36 −36 pylzma_compressobj.h
  61. +156 −156 pylzma_decompress.c
  62. +36 −36 pylzma_decompress.h
  63. +345 −345 pylzma_decompressobj.c
  64. +48 −48 pylzma_decompressobj.h
  65. +226 −226 pylzma_encoder.cpp
  66. +51 −51 pylzma_encoder.h
  67. +103 −103 pylzma_filestreams.h
  68. +263 −263 pylzma_streams.h
  69. +24 −24 readme.txt
  70. +105 −105 setup.py
  71. +170 −170 tests/test_pylzma.py
View
152 7zip/7zip/Common/InBuffer.h
@@ -1,76 +1,76 @@
-// InBuffer.h
-
-#ifndef __INBUFFER_H
-#define __INBUFFER_H
-
-#include "../IStream.h"
-#include "../../Common/MyCom.h"
-
-#ifndef _NO_EXCEPTIONS
-class CInBufferException
-{
-public:
- HRESULT ErrorCode;
- CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
-};
-#endif
-
-class CInBuffer
-{
- UInt64 _processedSize;
- Byte *_bufferBase;
- UInt32 _bufferSize;
- Byte *_buffer;
- Byte *_bufferLimit;
- CMyComPtr<ISequentialInStream> _stream;
- bool _wasFinished;
-
- bool ReadBlock();
-
-public:
- #ifdef _NO_EXCEPTIONS
- HRESULT ErrorCode;
- #endif
-
- CInBuffer();
- ~CInBuffer() { Free(); }
-
- bool Create(UInt32 bufferSize);
- void Free();
-
- void SetStream(ISequentialInStream *stream);
- void Init();
- void ReleaseStream() { _stream.Release(); }
-
- bool ReadByte(Byte &b)
- {
- if(_buffer >= _bufferLimit)
- if(!ReadBlock())
- return false;
- b = *_buffer++;
- return true;
- }
- Byte ReadByte()
- {
- if(_buffer >= _bufferLimit)
- if(!ReadBlock())
- return 0xFF;
- return *_buffer++;
- }
- void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
- {
- for(processedSize = 0; processedSize < size; processedSize++)
- if (!ReadByte(((Byte *)data)[processedSize]))
- return;
- }
- bool ReadBytes(void *data, UInt32 size)
- {
- UInt32 processedSize;
- ReadBytes(data, size, processedSize);
- return (processedSize == size);
- }
- UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
- bool WasFinished() const { return _wasFinished; }
-};
-
-#endif
+// InBuffer.h
+
+#ifndef __INBUFFER_H
+#define __INBUFFER_H
+
+#include "../IStream.h"
+#include "../../Common/MyCom.h"
+
+#ifndef _NO_EXCEPTIONS
+class CInBufferException
+{
+public:
+ HRESULT ErrorCode;
+ CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
+};
+#endif
+
+class CInBuffer
+{
+ UInt64 _processedSize;
+ Byte *_bufferBase;
+ UInt32 _bufferSize;
+ Byte *_buffer;
+ Byte *_bufferLimit;
+ CMyComPtr<ISequentialInStream> _stream;
+ bool _wasFinished;
+
+ bool ReadBlock();
+
+public:
+ #ifdef _NO_EXCEPTIONS
+ HRESULT ErrorCode;
+ #endif
+
+ CInBuffer();
+ ~CInBuffer() { Free(); }
+
+ bool Create(UInt32 bufferSize);
+ void Free();
+
+ void SetStream(ISequentialInStream *stream);
+ void Init();
+ void ReleaseStream() { _stream.Release(); }
+
+ bool ReadByte(Byte &b)
+ {
+ if(_buffer >= _bufferLimit)
+ if(!ReadBlock())
+ return false;
+ b = *_buffer++;
+ return true;
+ }
+ Byte ReadByte()
+ {
+ if(_buffer >= _bufferLimit)
+ if(!ReadBlock())
+ return 0xFF;
+ return *_buffer++;
+ }
+ void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
+ {
+ for(processedSize = 0; processedSize < size; processedSize++)
+ if (!ReadByte(((Byte *)data)[processedSize]))
+ return;
+ }
+ bool ReadBytes(void *data, UInt32 size)
+ {
+ UInt32 processedSize;
+ ReadBytes(data, size, processedSize);
+ return (processedSize == size);
+ }
+ UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
+ bool WasFinished() const { return _wasFinished; }
+};
+
+#endif
View
140 7zip/7zip/Common/OutBuffer.cpp
@@ -1,70 +1,70 @@
-// OutByte.cpp
-
-#include "StdAfx.h"
-
-#include "OutBuffer.h"
-
-#include "../../Common/Alloc.h"
-
-bool COutBuffer::Create(UInt32 bufferSize)
-{
- const UInt32 kMinBlockSize = 1;
- if (bufferSize < kMinBlockSize)
- bufferSize = kMinBlockSize;
- if (_buffer != 0 && _bufferSize == bufferSize)
- return true;
- Free();
- _bufferSize = bufferSize;
- _buffer = (Byte *)::BigAlloc(bufferSize);
- return (_buffer != 0);
-}
-
-void COutBuffer::Free()
-{
- BigFree(_buffer);
- _buffer = 0;
-}
-
-void COutBuffer::SetStream(ISequentialOutStream *stream)
-{
- _stream = stream;
-}
-
-void COutBuffer::Init()
-{
- _processedSize = 0;
- _pos = 0;
- #ifdef _NO_EXCEPTIONS
- ErrorCode = S_OK;
- #endif
-}
-
-HRESULT COutBuffer::Flush()
-{
- if (_pos == 0)
- return S_OK;
- UInt32 processedSize;
- HRESULT result = _stream->Write(_buffer, _pos, &processedSize);
- if (result != S_OK)
- return result;
- if (_pos != processedSize)
- return E_FAIL;
- _processedSize += processedSize;
- _pos = 0;
- return S_OK;
-}
-
-void COutBuffer::WriteBlock()
-{
- #ifdef _NO_EXCEPTIONS
- if (ErrorCode != S_OK)
- return;
- #endif
- HRESULT result = Flush();
- #ifdef _NO_EXCEPTIONS
- ErrorCode = result;
- #else
- if (result != S_OK)
- throw COutBufferException(result);
- #endif
-}
+// OutByte.cpp
+
+#include "StdAfx.h"
+
+#include "OutBuffer.h"
+
+#include "../../Common/Alloc.h"
+
+bool COutBuffer::Create(UInt32 bufferSize)
+{
+ const UInt32 kMinBlockSize = 1;
+ if (bufferSize < kMinBlockSize)
+ bufferSize = kMinBlockSize;
+ if (_buffer != 0 && _bufferSize == bufferSize)
+ return true;
+ Free();
+ _bufferSize = bufferSize;
+ _buffer = (Byte *)::BigAlloc(bufferSize);
+ return (_buffer != 0);
+}
+
+void COutBuffer::Free()
+{
+ BigFree(_buffer);
+ _buffer = 0;
+}
+
+void COutBuffer::SetStream(ISequentialOutStream *stream)
+{
+ _stream = stream;
+}
+
+void COutBuffer::Init()
+{
+ _processedSize = 0;
+ _pos = 0;
+ #ifdef _NO_EXCEPTIONS
+ ErrorCode = S_OK;
+ #endif
+}
+
+HRESULT COutBuffer::Flush()
+{
+ if (_pos == 0)
+ return S_OK;
+ UInt32 processedSize;
+ HRESULT result = _stream->Write(_buffer, _pos, &processedSize);
+ if (result != S_OK)
+ return result;
+ if (_pos != processedSize)
+ return E_FAIL;
+ _processedSize += processedSize;
+ _pos = 0;
+ return S_OK;
+}
+
+void COutBuffer::WriteBlock()
+{
+ #ifdef _NO_EXCEPTIONS
+ if (ErrorCode != S_OK)
+ return;
+ #endif
+ HRESULT result = Flush();
+ #ifdef _NO_EXCEPTIONS
+ ErrorCode = result;
+ #else
+ if (result != S_OK)
+ throw COutBufferException(result);
+ #endif
+}
View
142 7zip/7zip/Common/OutBuffer.h
@@ -1,71 +1,71 @@
-// OutBuffer.h
-
-#ifndef __OUTBUFFER_H
-#define __OUTBUFFER_H
-
-#include "../IStream.h"
-#include "../../Common/MyCom.h"
-
-#ifndef _NO_EXCEPTIONS
-struct COutBufferException
-{
- HRESULT ErrorCode;
- COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
-};
-#endif
-
-class COutBuffer
-{
- Byte *_buffer;
- UInt32 _pos;
- UInt32 _bufferSize;
- CMyComPtr<ISequentialOutStream> _stream;
- UInt64 _processedSize;
-
- void WriteBlock();
-public:
- #ifdef _NO_EXCEPTIONS
- HRESULT ErrorCode;
- #endif
-
- COutBuffer(): _buffer(0), _pos(0), _stream(0) {}
- ~COutBuffer() { Free(); }
-
- bool Create(UInt32 bufferSize);
- void Free();
-
- void SetStream(ISequentialOutStream *stream);
- void Init();
- HRESULT Flush();
- void ReleaseStream() { _stream.Release(); }
-
- /*
- void *GetBuffer(UInt32 &sizeAvail)
- {
- sizeAvail = _bufferSize - _pos;
- return _buffer + _pos;
- }
- void MovePos(UInt32 num)
- {
- _pos += num;
- if(_pos >= _bufferSize)
- WriteBlock();
- }
- */
-
- void WriteByte(Byte b)
- {
- _buffer[_pos++] = b;
- if(_pos >= _bufferSize)
- WriteBlock();
- }
- void WriteBytes(const void *data, UInt32 size)
- {
- for (UInt32 i = 0; i < size; i++)
- WriteByte(((const Byte *)data)[i]);
- }
-
- UInt64 GetProcessedSize() const { return _processedSize + _pos; }
-};
-
-#endif
+// OutBuffer.h
+
+#ifndef __OUTBUFFER_H
+#define __OUTBUFFER_H
+
+#include "../IStream.h"
+#include "../../Common/MyCom.h"
+
+#ifndef _NO_EXCEPTIONS
+struct COutBufferException
+{
+ HRESULT ErrorCode;
+ COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
+};
+#endif
+
+class COutBuffer
+{
+ Byte *_buffer;
+ UInt32 _pos;
+ UInt32 _bufferSize;
+ CMyComPtr<ISequentialOutStream> _stream;
+ UInt64 _processedSize;
+
+ void WriteBlock();
+public:
+ #ifdef _NO_EXCEPTIONS
+ HRESULT ErrorCode;
+ #endif
+
+ COutBuffer(): _buffer(0), _pos(0), _stream(0) {}
+ ~COutBuffer() { Free(); }
+
+ bool Create(UInt32 bufferSize);
+ void Free();
+
+ void SetStream(ISequentialOutStream *stream);
+ void Init();
+ HRESULT Flush();
+ void ReleaseStream() { _stream.Release(); }
+
+ /*
+ void *GetBuffer(UInt32 &sizeAvail)
+ {
+ sizeAvail = _bufferSize - _pos;
+ return _buffer + _pos;
+ }
+ void MovePos(UInt32 num)
+ {
+ _pos += num;
+ if(_pos >= _bufferSize)
+ WriteBlock();
+ }
+ */
+
+ void WriteByte(Byte b)
+ {
+ _buffer[_pos++] = b;
+ if(_pos >= _bufferSize)
+ WriteBlock();
+ }
+ void WriteBytes(const void *data, UInt32 size)
+ {
+ for (UInt32 i = 0; i < size; i++)
+ WriteByte(((const Byte *)data)[i]);
+ }
+
+ UInt64 GetProcessedSize() const { return _processedSize + _pos; }
+};
+
+#endif
View
16 7zip/7zip/Common/StdAfx.h
@@ -1,8 +1,8 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../Common/MyWindows.h"
-
-#endif
+// StdAfx.h
+
+#ifndef __STDAFX_H
+#define __STDAFX_H
+
+#include "../../Common/MyWindows.h"
+
+#endif
View
110 7zip/7zip/Compress/LZ/BinTree/BinTree.h
@@ -1,55 +1,55 @@
-// BinTree.h
-
-#include "../LZInWindow.h"
-#include "../IMatchFinder.h"
-
-namespace BT_NAMESPACE {
-
-typedef UInt32 CIndex;
-const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
-
-class CMatchFinderBinTree:
- public IMatchFinder,
- public IMatchFinderSetCallback,
- public CLZInWindow,
- public CMyUnknownImp
-{
- UInt32 _cyclicBufferPos;
- UInt32 _cyclicBufferSize; // it must be historySize + 1
- UInt32 _matchMaxLen;
- CIndex *_hash;
- UInt32 _cutValue;
-
- CMyComPtr<IMatchFinderCallback> m_Callback;
-
- void Normalize();
- void FreeThisClassMemory();
- void FreeMemory();
-
- MY_UNKNOWN_IMP1(IMatchFinderSetCallback)
-
- STDMETHOD(Init)(ISequentialInStream *inStream);
- STDMETHOD_(void, ReleaseStream)();
- STDMETHOD(MovePos)();
- STDMETHOD_(Byte, GetIndexByte)(Int32 index);
- STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
- STDMETHOD_(UInt32, GetNumAvailableBytes)();
- STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
- STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
- STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);
- STDMETHOD_(void, DummyLongestMatch)();
-
- // IMatchFinderSetCallback
- STDMETHOD(SetCallback)(IMatchFinderCallback *callback);
-
- virtual void BeforeMoveBlock();
- virtual void AfterMoveBlock();
-
-public:
- CMatchFinderBinTree();
- virtual ~CMatchFinderBinTree();
- void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }
-};
-
-}
+// BinTree.h
+
+#include "../LZInWindow.h"
+#include "../IMatchFinder.h"
+
+namespace BT_NAMESPACE {
+
+typedef UInt32 CIndex;
+const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
+
+class CMatchFinderBinTree:
+ public IMatchFinder,
+ public IMatchFinderSetCallback,
+ public CLZInWindow,
+ public CMyUnknownImp
+{
+ UInt32 _cyclicBufferPos;
+ UInt32 _cyclicBufferSize; // it must be historySize + 1
+ UInt32 _matchMaxLen;
+ CIndex *_hash;
+ UInt32 _cutValue;
+
+ CMyComPtr<IMatchFinderCallback> m_Callback;
+
+ void Normalize();
+ void FreeThisClassMemory();
+ void FreeMemory();
+
+ MY_UNKNOWN_IMP1(IMatchFinderSetCallback)
+
+ STDMETHOD(Init)(ISequentialInStream *inStream);
+ STDMETHOD_(void, ReleaseStream)();
+ STDMETHOD(MovePos)();
+ STDMETHOD_(Byte, GetIndexByte)(Int32 index);
+ STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
+ STDMETHOD_(UInt32, GetNumAvailableBytes)();
+ STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
+ STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
+ UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
+ STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);
+ STDMETHOD_(void, DummyLongestMatch)();
+
+ // IMatchFinderSetCallback
+ STDMETHOD(SetCallback)(IMatchFinderCallback *callback);
+
+ virtual void BeforeMoveBlock();
+ virtual void AfterMoveBlock();
+
+public:
+ CMatchFinderBinTree();
+ virtual ~CMatchFinderBinTree();
+ void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }
+};
+
+}
View
24 7zip/7zip/Compress/LZ/BinTree/BinTree2.h
@@ -1,12 +1,12 @@
-// BinTree2.h
-
-#ifndef __BINTREE2_H
-#define __BINTREE2_H
-
-#undef BT_NAMESPACE
-#define BT_NAMESPACE NBT2
-
-#include "BinTree.h"
-#include "BinTreeMain.h"
-
-#endif
+// BinTree2.h
+
+#ifndef __BINTREE2_H
+#define __BINTREE2_H
+
+#undef BT_NAMESPACE
+#define BT_NAMESPACE NBT2
+
+#include "BinTree.h"
+#include "BinTreeMain.h"
+
+#endif
View
32 7zip/7zip/Compress/LZ/BinTree/BinTree3.h
@@ -1,16 +1,16 @@
-// BinTree3.h
-
-#ifndef __BINTREE3_H
-#define __BINTREE3_H
-
-#undef BT_NAMESPACE
-#define BT_NAMESPACE NBT3
-
-#define HASH_ARRAY_2
-
-#include "BinTree.h"
-#include "BinTreeMain.h"
-
-#undef HASH_ARRAY_2
-
-#endif
+// BinTree3.h
+
+#ifndef __BINTREE3_H
+#define __BINTREE3_H
+
+#undef BT_NAMESPACE
+#define BT_NAMESPACE NBT3
+
+#define HASH_ARRAY_2
+
+#include "BinTree.h"
+#include "BinTreeMain.h"
+
+#undef HASH_ARRAY_2
+
+#endif
View
32 7zip/7zip/Compress/LZ/BinTree/BinTree3Z.h
@@ -1,16 +1,16 @@
-// BinTree3Z.h
-
-#ifndef __BINTREE3Z_H
-#define __BINTREE3Z_H
-
-#undef BT_NAMESPACE
-#define BT_NAMESPACE NBT3Z
-
-#define HASH_ZIP
-
-#include "BinTree.h"
-#include "BinTreeMain.h"
-
-#undef HASH_ZIP
-
-#endif
+// BinTree3Z.h
+
+#ifndef __BINTREE3Z_H
+#define __BINTREE3Z_H
+
+#undef BT_NAMESPACE
+#define BT_NAMESPACE NBT3Z
+
+#define HASH_ZIP
+
+#include "BinTree.h"
+#include "BinTreeMain.h"
+
+#undef HASH_ZIP
+
+#endif
View
36 7zip/7zip/Compress/LZ/BinTree/BinTree4.h
@@ -1,18 +1,18 @@
-// BinTree4.h
-
-#ifndef __BINTREE4_H
-#define __BINTREE4_H
-
-#undef BT_NAMESPACE
-#define BT_NAMESPACE NBT4
-
-#define HASH_ARRAY_2
-#define HASH_ARRAY_3
-
-#include "BinTree.h"
-#include "BinTreeMain.h"
-
-#undef HASH_ARRAY_2
-#undef HASH_ARRAY_3
-
-#endif
+// BinTree4.h
+
+#ifndef __BINTREE4_H
+#define __BINTREE4_H
+
+#undef BT_NAMESPACE
+#define BT_NAMESPACE NBT4
+
+#define HASH_ARRAY_2
+#define HASH_ARRAY_3
+
+#include "BinTree.h"
+#include "BinTreeMain.h"
+
+#undef HASH_ARRAY_2
+#undef HASH_ARRAY_3
+
+#endif
View
40 7zip/7zip/Compress/LZ/BinTree/BinTree4b.h
@@ -1,20 +1,20 @@
-// BinTree4b.h
-
-#ifndef __BINTREE4B_H
-#define __BINTREE4B_H
-
-#undef BT_NAMESPACE
-#define BT_NAMESPACE NBT4B
-
-#define HASH_ARRAY_2
-#define HASH_ARRAY_3
-#define HASH_BIG
-
-#include "BinTree.h"
-#include "BinTreeMain.h"
-
-#undef HASH_ARRAY_2
-#undef HASH_ARRAY_3
-#undef HASH_BIG
-
-#endif
+// BinTree4b.h
+
+#ifndef __BINTREE4B_H
+#define __BINTREE4B_H
+
+#undef BT_NAMESPACE
+#define BT_NAMESPACE NBT4B
+
+#define HASH_ARRAY_2
+#define HASH_ARRAY_3
+#define HASH_BIG
+
+#include "BinTree.h"
+#include "BinTreeMain.h"
+
+#undef HASH_ARRAY_2
+#undef HASH_ARRAY_3
+#undef HASH_BIG
+
+#endif
View
888 7zip/7zip/Compress/LZ/BinTree/BinTreeMain.h
@@ -1,444 +1,444 @@
-// BinTreeMain.h
-
-#include "../../../../Common/Defs.h"
-#include "../../../../Common/CRC.h"
-#include "../../../../Common/Alloc.h"
-
-namespace BT_NAMESPACE {
-
-#ifdef HASH_ARRAY_2
- static const UInt32 kHash2Size = 1 << 10;
- #ifdef HASH_ARRAY_3
- static const UInt32 kNumHashDirectBytes = 0;
- static const UInt32 kNumHashBytes = 4;
- static const UInt32 kHash3Size = 1 << 18;
- #ifdef HASH_BIG
- static const UInt32 kHashSize = 1 << 23;
- #else
- static const UInt32 kHashSize = 1 << 20;
- #endif
- #else
- static const UInt32 kNumHashDirectBytes = 3;
- static const UInt32 kNumHashBytes = 3;
- static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
- #endif
-#else
- #ifdef HASH_ZIP
- static const UInt32 kNumHashDirectBytes = 0;
- static const UInt32 kNumHashBytes = 3;
- static const UInt32 kHashSize = 1 << 16;
- #else
- #define THERE_ARE_DIRECT_HASH_BYTES
- static const UInt32 kNumHashDirectBytes = 2;
- static const UInt32 kNumHashBytes = 2;
- static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
- #endif
-#endif
-
-static const UInt32 kHashSizeSum = kHashSize
- #ifdef HASH_ARRAY_2
- + kHash2Size
- #ifdef HASH_ARRAY_3
- + kHash3Size
- #endif
- #endif
- ;
-
-#ifdef HASH_ARRAY_2
-static const UInt32 kHash2Offset = kHashSize;
-#ifdef HASH_ARRAY_3
-static const UInt32 kHash3Offset = kHashSize + kHash2Size;
-#endif
-#endif
-
-CMatchFinderBinTree::CMatchFinderBinTree():
- _hash(0),
- _cutValue(0xFF)
-{
-}
-
-void CMatchFinderBinTree::FreeThisClassMemory()
-{
- BigFree(_hash);
- _hash = 0;
-}
-
-void CMatchFinderBinTree::FreeMemory()
-{
- FreeThisClassMemory();
- CLZInWindow::Free();
-}
-
-CMatchFinderBinTree::~CMatchFinderBinTree()
-{
- FreeMemory();
-}
-
-STDMETHODIMP CMatchFinderBinTree::Create(UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
-{
- UInt32 sizeReserv = (historySize + keepAddBufferBefore +
- matchMaxLen + keepAddBufferAfter) / 2 + 256;
- if (CLZInWindow::Create(historySize + keepAddBufferBefore,
- matchMaxLen + keepAddBufferAfter, sizeReserv))
- {
- if (historySize + 256 > kMaxValForNormalize)
- {
- FreeMemory();
- return E_INVALIDARG;
- }
- _matchMaxLen = matchMaxLen;
- UInt32 newCyclicBufferSize = historySize + 1;
- if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)
- return S_OK;
- FreeThisClassMemory();
- _cyclicBufferSize = newCyclicBufferSize; // don't change it
- _hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize * 2) * sizeof(CIndex));
- if (_hash != 0)
- return S_OK;
- }
- FreeMemory();
- return E_OUTOFMEMORY;
-}
-
-static const UInt32 kEmptyHashValue = 0;
-
-STDMETHODIMP CMatchFinderBinTree::Init(ISequentialInStream *stream)
-{
- RINOK(CLZInWindow::Init(stream));
- for(UInt32 i = 0; i < kHashSizeSum; i++)
- _hash[i] = kEmptyHashValue;
- _cyclicBufferPos = 0;
- ReduceOffsets(-1);
- return S_OK;
-}
-
-STDMETHODIMP_(void) CMatchFinderBinTree::ReleaseStream()
-{
- // ReleaseStream();
-}
-
-#ifdef HASH_ARRAY_2
-#ifdef HASH_ARRAY_3
-inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)
-{
- UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
- hash2Value = temp & (kHash2Size - 1);
- hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);
- return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) &
- (kHashSize - 1);
-}
-#else // no HASH_ARRAY_3
-inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)
-{
- hash2Value = (CCRC::Table[pointer[0]] ^ pointer[1]) & (kHash2Size - 1);
- return ((UInt32(pointer[0]) << 16)) | ((UInt32(pointer[1]) << 8)) | pointer[2];
-}
-#endif // HASH_ARRAY_3
-#else // no HASH_ARRAY_2
-#ifdef HASH_ZIP
-inline UInt32 Hash(const Byte *pointer)
-{
- return ((UInt32(pointer[0]) << 8) ^
- CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);
-}
-#else // no HASH_ZIP
-inline UInt32 Hash(const Byte *pointer)
-{
- return pointer[0] ^ (UInt32(pointer[1]) << 8);
-}
-#endif // HASH_ZIP
-#endif // HASH_ARRAY_2
-
-STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetLongestMatch(UInt32 *distances)
-{
- UInt32 lenLimit;
- if (_pos + _matchMaxLen <= _streamPos)
- lenLimit = _matchMaxLen;
- else
- {
- lenLimit = _streamPos - _pos;
- if(lenLimit < kNumHashBytes)
- return 0;
- }
-
- UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
- Byte *cur = _buffer + _pos;
-
- UInt32 maxLen = 0;
-
- #ifdef HASH_ARRAY_2
- UInt32 hash2Value;
- #ifdef HASH_ARRAY_3
- UInt32 hash3Value;
- UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
- #else
- UInt32 hashValue = Hash(cur, hash2Value);
- #endif
- #else
- UInt32 hashValue = Hash(cur);
- #endif
-
- UInt32 curMatch = _hash[hashValue];
- #ifdef HASH_ARRAY_2
- UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];
- #ifdef HASH_ARRAY_3
- UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
- #endif
- _hash[kHash2Offset + hash2Value] = _pos;
- distances[2] = 0xFFFFFFFF;
- if(curMatch2 > matchMinPos)
- if (_buffer[curMatch2] == cur[0])
- {
- distances[2] = _pos - curMatch2 - 1;
- maxLen = 2;
- }
-
- #ifdef HASH_ARRAY_3
- _hash[kHash3Offset + hash3Value] = _pos;
- distances[3] = 0xFFFFFFFF;
- if(curMatch3 > matchMinPos)
- if (_buffer[curMatch3] == cur[0])
- {
- distances[3] = _pos - curMatch3 - 1;
- maxLen = 3;
- }
- #endif
- #endif
-
- _hash[hashValue] = _pos;
-
- CIndex *son = _hash + kHashSizeSum;
- CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CIndex *ptr1 = son + (_cyclicBufferPos << 1);
-
- distances[kNumHashBytes] = 0xFFFFFFFF;
-
- #ifdef THERE_ARE_DIRECT_HASH_BYTES
- if (lenLimit == kNumHashDirectBytes)
- {
- if(curMatch > matchMinPos)
- while (maxLen < kNumHashDirectBytes)
- distances[++maxLen] = _pos - curMatch - 1;
- // We don't need tree in this case
- }
- else
- #endif
- {
- UInt32 len0, len1;
- len0 = len1 = kNumHashDirectBytes;
- UInt32 count = _cutValue;
- while(true)
- {
- if(curMatch <= matchMinPos || count-- == 0)
- {
- *ptr0 = kEmptyHashValue;
- *ptr1 = kEmptyHashValue;
- break;
- }
- Byte *pb = _buffer + curMatch;
- UInt32 len = MyMin(len0, len1);
- do
- {
- if (pb[len] != cur[len])
- break;
- }
- while(++len != lenLimit);
-
- UInt32 delta = _pos - curMatch;
- while (maxLen < len)
- distances[++maxLen] = delta - 1;
-
- UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
- (_cyclicBufferPos - delta):
- (_cyclicBufferPos - delta + _cyclicBufferSize);
- CIndex *pair = son + (cyclicPos << 1);
-
- if (len != lenLimit)
- {
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- else
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- break;
- }
- }
- }
- #ifdef HASH_ARRAY_2
- #ifdef HASH_ARRAY_3
- if (distances[4] < distances[3])
- distances[3] = distances[4];
- #endif
- if (distances[3] < distances[2])
- distances[2] = distances[3];
- #endif
- return maxLen;
-}
-
-STDMETHODIMP_(void) CMatchFinderBinTree::DummyLongestMatch()
-{
- UInt32 lenLimit;
- if (_pos + _matchMaxLen <= _streamPos)
- lenLimit = _matchMaxLen;
- else
- {
- lenLimit = _streamPos - _pos;
- if(lenLimit < kNumHashBytes)
- return;
- }
- UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
- Byte *cur = _buffer + _pos;
-
- #ifdef HASH_ARRAY_2
- UInt32 hash2Value;
- #ifdef HASH_ARRAY_3
- UInt32 hash3Value;
- UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
- _hash[kHash3Offset + hash3Value] = _pos;
- #else
- UInt32 hashValue = Hash(cur, hash2Value);
- #endif
- _hash[kHash2Offset + hash2Value] = _pos;
- #else
- UInt32 hashValue = Hash(cur);
- #endif
-
- UInt32 curMatch = _hash[hashValue];
- _hash[hashValue] = _pos;
-
- CIndex *son = _hash + kHashSizeSum;
- CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CIndex *ptr1 = son + (_cyclicBufferPos << 1);
-
- #ifdef THERE_ARE_DIRECT_HASH_BYTES
- if (lenLimit != kNumHashDirectBytes)
- #endif
- {
- UInt32 len0, len1;
- len0 = len1 = kNumHashDirectBytes;
- UInt32 count = _cutValue;
- while(true)
- {
- if(curMatch <= matchMinPos || count-- == 0)
- break;
- Byte *pb = _buffer + curMatch;
- UInt32 len = MyMin(len0, len1);
- do
- {
- if (pb[len] != cur[len])
- break;
- }
- while(++len != lenLimit);
-
- UInt32 delta = _pos - curMatch;
- UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
- (_cyclicBufferPos - delta):
- (_cyclicBufferPos - delta + _cyclicBufferSize);
- CIndex *pair = son + (cyclicPos << 1);
-
- if (len != lenLimit)
- {
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- else
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- return;
- }
- }
- }
- *ptr0 = kEmptyHashValue;
- *ptr1 = kEmptyHashValue;
-}
-
-void CMatchFinderBinTree::Normalize()
-{
- UInt32 subValue = _pos - _cyclicBufferSize;
- CIndex *items = _hash;
- UInt32 numItems = (kHashSizeSum + _cyclicBufferSize * 2);
- for (UInt32 i = 0; i < numItems; i++)
- {
- UInt32 value = items[i];
- if (value <= subValue)
- value = kEmptyHashValue;
- else
- value -= subValue;
- items[i] = value;
- }
- ReduceOffsets(subValue);
-}
-
-STDMETHODIMP CMatchFinderBinTree::MovePos()
-{
- if (++_cyclicBufferPos == _cyclicBufferSize)
- _cyclicBufferPos = 0;
- RINOK(CLZInWindow::MovePos());
- if (_pos == kMaxValForNormalize)
- Normalize();
- return S_OK;
-}
-
-STDMETHODIMP_(Byte) CMatchFinderBinTree::GetIndexByte(Int32 index)
- { return CLZInWindow::GetIndexByte(index); }
-
-STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetMatchLen(Int32 index,
- UInt32 back, UInt32 limit)
- { return CLZInWindow::GetMatchLen(index, back, limit); }
-
-STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetNumAvailableBytes()
- { return CLZInWindow::GetNumAvailableBytes(); }
-
-STDMETHODIMP_(const Byte *) CMatchFinderBinTree::GetPointerToCurrentPos()
- { return CLZInWindow::GetPointerToCurrentPos(); }
-
-// IMatchFinderSetCallback
-STDMETHODIMP CMatchFinderBinTree::SetCallback(IMatchFinderCallback *callback)
-{
- m_Callback = callback;
- return S_OK;
-}
-
-void CMatchFinderBinTree::BeforeMoveBlock()
-{
- if (m_Callback)
- m_Callback->BeforeChangingBufferPos();
- CLZInWindow::BeforeMoveBlock();
-}
-
-void CMatchFinderBinTree::AfterMoveBlock()
-{
- if (m_Callback)
- m_Callback->AfterChangingBufferPos();
- CLZInWindow::AfterMoveBlock();
-}
-
-}
+// BinTreeMain.h
+
+#include "../../../../Common/Defs.h"
+#include "../../../../Common/CRC.h"
+#include "../../../../Common/Alloc.h"
+
+namespace BT_NAMESPACE {
+
+#ifdef HASH_ARRAY_2
+ static const UInt32 kHash2Size = 1 << 10;
+ #ifdef HASH_ARRAY_3
+ static const UInt32 kNumHashDirectBytes = 0;
+ static const UInt32 kNumHashBytes = 4;
+ static const UInt32 kHash3Size = 1 << 18;
+ #ifdef HASH_BIG
+ static const UInt32 kHashSize = 1 << 23;
+ #else
+ static const UInt32 kHashSize = 1 << 20;
+ #endif
+ #else
+ static const UInt32 kNumHashDirectBytes = 3;
+ static const UInt32 kNumHashBytes = 3;
+ static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
+ #endif
+#else
+ #ifdef HASH_ZIP
+ static const UInt32 kNumHashDirectBytes = 0;
+ static const UInt32 kNumHashBytes = 3;
+ static const UInt32 kHashSize = 1 << 16;
+ #else
+ #define THERE_ARE_DIRECT_HASH_BYTES
+ static const UInt32 kNumHashDirectBytes = 2;
+ static const UInt32 kNumHashBytes = 2;
+ static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
+ #endif
+#endif
+
+static const UInt32 kHashSizeSum = kHashSize
+ #ifdef HASH_ARRAY_2
+ + kHash2Size
+ #ifdef HASH_ARRAY_3
+ + kHash3Size
+ #endif
+ #endif
+ ;
+
+#ifdef HASH_ARRAY_2
+static const UInt32 kHash2Offset = kHashSize;
+#ifdef HASH_ARRAY_3
+static const UInt32 kHash3Offset = kHashSize + kHash2Size;
+#endif
+#endif
+
+CMatchFinderBinTree::CMatchFinderBinTree():
+ _hash(0),
+ _cutValue(0xFF)
+{
+}
+
+void CMatchFinderBinTree::FreeThisClassMemory()
+{
+ BigFree(_hash);
+ _hash = 0;
+}
+
+void CMatchFinderBinTree::FreeMemory()
+{
+ FreeThisClassMemory();
+ CLZInWindow::Free();
+}
+
+CMatchFinderBinTree::~CMatchFinderBinTree()
+{
+ FreeMemory();
+}
+
+STDMETHODIMP CMatchFinderBinTree::Create(UInt32 historySize, UInt32 keepAddBufferBefore,
+ UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
+{
+ UInt32 sizeReserv = (historySize + keepAddBufferBefore +
+ matchMaxLen + keepAddBufferAfter) / 2 + 256;
+ if (CLZInWindow::Create(historySize + keepAddBufferBefore,
+ matchMaxLen + keepAddBufferAfter, sizeReserv))
+ {
+ if (historySize + 256 > kMaxValForNormalize)
+ {
+ FreeMemory();
+ return E_INVALIDARG;
+ }
+ _matchMaxLen = matchMaxLen;
+ UInt32 newCyclicBufferSize = historySize + 1;
+ if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)
+ return S_OK;
+ FreeThisClassMemory();
+ _cyclicBufferSize = newCyclicBufferSize; // don't change it
+ _hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize * 2) * sizeof(CIndex));
+ if (_hash != 0)
+ return S_OK;
+ }
+ FreeMemory();
+ return E_OUTOFMEMORY;
+}
+
+static const UInt32 kEmptyHashValue = 0;
+
+STDMETHODIMP CMatchFinderBinTree::Init(ISequentialInStream *stream)
+{
+ RINOK(CLZInWindow::Init(stream));
+ for(UInt32 i = 0; i < kHashSizeSum; i++)
+ _hash[i] = kEmptyHashValue;
+ _cyclicBufferPos = 0;
+ ReduceOffsets(-1);
+ return S_OK;
+}
+
+STDMETHODIMP_(void) CMatchFinderBinTree::ReleaseStream()
+{
+ // ReleaseStream();
+}
+
+#ifdef HASH_ARRAY_2
+#ifdef HASH_ARRAY_3
+inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)
+{
+ UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
+ hash2Value = temp & (kHash2Size - 1);
+ hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);
+ return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) &
+ (kHashSize - 1);
+}
+#else // no HASH_ARRAY_3
+inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)
+{
+ hash2Value = (CCRC::Table[pointer[0]] ^ pointer[1]) & (kHash2Size - 1);
+ return ((UInt32(pointer[0]) << 16)) | ((UInt32(pointer[1]) << 8)) | pointer[2];
+}
+#endif // HASH_ARRAY_3
+#else // no HASH_ARRAY_2
+#ifdef HASH_ZIP
+inline UInt32 Hash(const Byte *pointer)
+{
+ return ((UInt32(pointer[0]) << 8) ^
+ CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);
+}
+#else // no HASH_ZIP
+inline UInt32 Hash(const Byte *pointer)
+{
+ return pointer[0] ^ (UInt32(pointer[1]) << 8);
+}
+#endif // HASH_ZIP
+#endif // HASH_ARRAY_2
+
+STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetLongestMatch(UInt32 *distances)
+{
+ UInt32 lenLimit;
+ if (_pos + _matchMaxLen <= _streamPos)
+ lenLimit = _matchMaxLen;
+ else
+ {
+ lenLimit = _streamPos - _pos;
+ if(lenLimit < kNumHashBytes)
+ return 0;
+ }
+
+ UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
+ Byte *cur = _buffer + _pos;
+
+ UInt32 maxLen = 0;
+
+ #ifdef HASH_ARRAY_2
+ UInt32 hash2Value;
+ #ifdef HASH_ARRAY_3
+ UInt32 hash3Value;
+ UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
+ #else
+ UInt32 hashValue = Hash(cur, hash2Value);
+ #endif
+ #else
+ UInt32 hashValue = Hash(cur);
+ #endif
+
+ UInt32 curMatch = _hash[hashValue];
+ #ifdef HASH_ARRAY_2
+ UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];
+ #ifdef HASH_ARRAY_3
+ UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
+ #endif
+ _hash[kHash2Offset + hash2Value] = _pos;
+ distances[2] = 0xFFFFFFFF;
+ if(curMatch2 > matchMinPos)
+ if (_buffer[curMatch2] == cur[0])
+ {
+ distances[2] = _pos - curMatch2 - 1;
+ maxLen = 2;
+ }
+
+ #ifdef HASH_ARRAY_3
+ _hash[kHash3Offset + hash3Value] = _pos;
+ distances[3] = 0xFFFFFFFF;
+ if(curMatch3 > matchMinPos)
+ if (_buffer[curMatch3] == cur[0])
+ {
+ distances[3] = _pos - curMatch3 - 1;
+ maxLen = 3;
+ }
+ #endif
+ #endif
+
+ _hash[hashValue] = _pos;
+
+ CIndex *son = _hash + kHashSizeSum;
+ CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+ CIndex *ptr1 = son + (_cyclicBufferPos << 1);
+
+ distances[kNumHashBytes] = 0xFFFFFFFF;
+
+ #ifdef THERE_ARE_DIRECT_HASH_BYTES
+ if (lenLimit == kNumHashDirectBytes)
+ {
+ if(curMatch > matchMinPos)
+ while (maxLen < kNumHashDirectBytes)
+ distances[++maxLen] = _pos - curMatch - 1;
+ // We don't need tree in this case
+ }
+ else
+ #endif
+ {
+ UInt32 len0, len1;
+ len0 = len1 = kNumHashDirectBytes;
+ UInt32 count = _cutValue;
+ while(true)
+ {
+ if(curMatch <= matchMinPos || count-- == 0)
+ {
+ *ptr0 = kEmptyHashValue;
+ *ptr1 = kEmptyHashValue;
+ break;
+ }
+ Byte *pb = _buffer + curMatch;
+ UInt32 len = MyMin(len0, len1);
+ do
+ {
+ if (pb[len] != cur[len])
+ break;
+ }
+ while(++len != lenLimit);
+
+ UInt32 delta = _pos - curMatch;
+ while (maxLen < len)
+ distances[++maxLen] = delta - 1;
+
+ UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
+ (_cyclicBufferPos - delta):
+ (_cyclicBufferPos - delta + _cyclicBufferSize);
+ CIndex *pair = son + (cyclicPos << 1);
+
+ if (len != lenLimit)
+ {
+ if (pb[len] < cur[len])
+ {
+ *ptr1 = curMatch;
+ ptr1 = pair + 1;
+ curMatch = *ptr1;
+ len1 = len;
+ }
+ else
+ {
+ *ptr0 = curMatch;
+ ptr0 = pair;
+ curMatch = *ptr0;
+ len0 = len;
+ }
+ }
+ else
+ {
+ *ptr1 = pair[0];
+ *ptr0 = pair[1];
+ break;
+ }
+ }
+ }
+ #ifdef HASH_ARRAY_2
+ #ifdef HASH_ARRAY_3
+ if (distances[4] < distances[3])
+ distances[3] = distances[4];
+ #endif
+ if (distances[3] < distances[2])
+ distances[2] = distances[3];
+ #endif
+ return maxLen;
+}
+
+STDMETHODIMP_(void) CMatchFinderBinTree::DummyLongestMatch()
+{
+ UInt32 lenLimit;
+ if (_pos + _matchMaxLen <= _streamPos)
+ lenLimit = _matchMaxLen;
+ else
+ {
+ lenLimit = _streamPos - _pos;
+ if(lenLimit < kNumHashBytes)
+ return;
+ }
+ UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
+ Byte *cur = _buffer + _pos;
+
+ #ifdef HASH_ARRAY_2
+ UInt32 hash2Value;
+ #ifdef HASH_ARRAY_3
+ UInt32 hash3Value;
+ UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
+ _hash[kHash3Offset + hash3Value] = _pos;
+ #else
+ UInt32 hashValue = Hash(cur, hash2Value);
+ #endif
+ _hash[kHash2Offset + hash2Value] = _pos;
+ #else
+ UInt32 hashValue = Hash(cur);
+ #endif
+
+ UInt32 curMatch = _hash[hashValue];
+ _hash[hashValue] = _pos;
+
+ CIndex *son = _hash + kHashSizeSum;
+ CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+ CIndex *ptr1 = son + (_cyclicBufferPos << 1);
+
+ #ifdef THERE_ARE_DIRECT_HASH_BYTES
+ if (lenLimit != kNumHashDirectBytes)
+ #endif
+ {
+ UInt32 len0, len1;
+ len0 = len1 = kNumHashDirectBytes;
+ UInt32 count = _cutValue;
+ while(true)
+ {
+ if(curMatch <= matchMinPos || count-- == 0)
+ break;
+ Byte *pb = _buffer + curMatch;
+ UInt32 len = MyMin(len0, len1);
+ do
+ {
+ if (pb[len] != cur[len])
+ break;
+ }
+ while(++len != lenLimit);
+
+ UInt32 delta = _pos - curMatch;
+ UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
+ (_cyclicBufferPos - delta):
+ (_cyclicBufferPos - delta + _cyclicBufferSize);
+ CIndex *pair = son + (cyclicPos << 1);
+
+ if (len != lenLimit)
+ {
+ if (pb[len] < cur[len])
+ {
+ *ptr1 = curMatch;
+ ptr1 = pair + 1;
+ curMatch = *ptr1;
+ len1 = len;
+ }
+ else
+ {
+ *ptr0 = curMatch;
+ ptr0 = pair;
+ curMatch = *ptr0;
+ len0 = len;
+ }
+ }
+ else
+ {
+ *ptr1 = pair[0];
+ *ptr0 = pair[1];
+ return;
+ }
+ }
+ }
+ *ptr0 = kEmptyHashValue;
+ *ptr1 = kEmptyHashValue;
+}
+
+void CMatchFinderBinTree::Normalize()
+{
+ UInt32 subValue = _pos - _cyclicBufferSize;
+ CIndex *items = _hash;
+ UInt32 numItems = (kHashSizeSum + _cyclicBufferSize * 2);
+ for (UInt32 i = 0; i < numItems; i++)
+ {
+ UInt32 value = items[i];
+ if (value <= subValue)
+ value = kEmptyHashValue;
+ else
+ value -= subValue;
+ items[i] = value;
+ }
+ ReduceOffsets(subValue);
+}
+
+STDMETHODIMP CMatchFinderBinTree::MovePos()
+{
+ if (++_cyclicBufferPos == _cyclicBufferSize)
+ _cyclicBufferPos = 0;
+ RINOK(CLZInWindow::MovePos());
+ if (_pos == kMaxValForNormalize)
+ Normalize();
+ return S_OK;
+}
+
+STDMETHODIMP_(Byte) CMatchFinderBinTree::GetIndexByte(Int32 index)
+ { return CLZInWindow::GetIndexByte(index); }
+
+STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetMatchLen(Int32 index,
+ UInt32 back, UInt32 limit)
+ { return CLZInWindow::GetMatchLen(index, back, limit); }
+
+STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetNumAvailableBytes()
+ { return CLZInWindow::GetNumAvailableBytes(); }
+
+STDMETHODIMP_(const Byte *) CMatchFinderBinTree::GetPointerToCurrentPos()
+ { return CLZInWindow::GetPointerToCurrentPos(); }
+
+// IMatchFinderSetCallback
+STDMETHODIMP CMatchFinderBinTree::SetCallback(IMatchFinderCallback *callback)
+{
+ m_Callback = callback;
+ return S_OK;
+}
+
+void CMatchFinderBinTree::BeforeMoveBlock()
+{
+ if (m_Callback)
+ m_Callback->BeforeChangingBufferPos();
+ CLZInWindow::BeforeMoveBlock();
+}
+
+void CMatchFinderBinTree::AfterMoveBlock()
+{
+ if (m_Callback)
+ m_Callback->AfterChangingBufferPos();
+ CLZInWindow::AfterMoveBlock();
+}
+
+}
View
126 7zip/7zip/Compress/LZ/IMatchFinder.h
@@ -1,63 +1,63 @@
-// MatchFinders/IMatchFinder.h
-
-#ifndef __IMATCHFINDER_H
-#define __IMATCHFINDER_H
-
-// {23170F69-40C1-278A-0000-000200010000}
-DEFINE_GUID(IID_IInWindowStream,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200010000")
-IInWindowStream: public IUnknown
-{
- STDMETHOD(Init)(ISequentialInStream *inStream) PURE;
- STDMETHOD_(void, ReleaseStream)() PURE;
- STDMETHOD(MovePos)() PURE;
- STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;
- STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;
- STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;
- STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;
-};
-
-// {23170F69-40C1-278A-0000-000200020000}
-DEFINE_GUID(IID_IMatchFinder,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020000")
-IMatchFinder: public IInWindowStream
-{
- STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;
- STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances) PURE;
- STDMETHOD_(void, DummyLongestMatch)() PURE;
-};
-
-// {23170F69-40C1-278A-0000-000200020100}
-DEFINE_GUID(IID_IMatchFinderCallback,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020100")
-IMatchFinderCallback: public IUnknown
-{
- STDMETHOD(BeforeChangingBufferPos)() PURE;
- STDMETHOD(AfterChangingBufferPos)() PURE;
-};
-
-// {23170F69-40C1-278A-0000-000200020200}
-DEFINE_GUID(IID_IMatchFinderSetCallback,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020200")
-IMatchFinderSetCallback: public IUnknown
-{
- STDMETHOD(SetCallback)(IMatchFinderCallback *callback) PURE;
-};
-
-/*
-// {23170F69-40C1-278A-0000-000200030000}
-DEFINE_GUID(IID_IInitMatchFinder,
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00);
-MIDL_INTERFACE("23170F69-40C1-278A-0000-000200030000")
-IMatchFinderInit: public IUnknown
-{
- STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder) PURE;
-};
-*/
-
-#endif
+// MatchFinders/IMatchFinder.h
+
+#ifndef __IMATCHFINDER_H
+#define __IMATCHFINDER_H
+
+// {23170F69-40C1-278A-0000-000200010000}
+DEFINE_GUID(IID_IInWindowStream,
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00);
+MIDL_INTERFACE("23170F69-40C1-278A-0000-000200010000")
+IInWindowStream: public IUnknown
+{
+ STDMETHOD(Init)(ISequentialInStream *inStream) PURE;
+ STDMETHOD_(void, ReleaseStream)() PURE;
+ STDMETHOD(MovePos)() PURE;
+ STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;
+ STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;
+ STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;
+ STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;
+};
+
+// {23170F69-40C1-278A-0000-000200020000}
+DEFINE_GUID(IID_IMatchFinder,
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00);
+MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020000")
+IMatchFinder: public IInWindowStream
+{
+ STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
+ UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;
+ STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances) PURE;
+ STDMETHOD_(void, DummyLongestMatch)() PURE;
+};
+
+// {23170F69-40C1-278A-0000-000200020100}
+DEFINE_GUID(IID_IMatchFinderCallback,
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01, 0x00);
+MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020100")
+IMatchFinderCallback: public IUnknown
+{
+ STDMETHOD(BeforeChangingBufferPos)() PURE;
+ STDMETHOD(AfterChangingBufferPos)() PURE;
+};
+
+// {23170F69-40C1-278A-0000-000200020200}
+DEFINE_GUID(IID_IMatchFinderSetCallback,
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00);
+MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020200")
+IMatchFinderSetCallback: public IUnknown
+{
+ STDMETHOD(SetCallback)(IMatchFinderCallback *callback) PURE;
+};
+
+/*
+// {23170F69-40C1-278A-0000-000200030000}
+DEFINE_GUID(IID_IInitMatchFinder,
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00);
+MIDL_INTERFACE("23170F69-40C1-278A-0000-000200030000")
+IMatchFinderInit: public IUnknown
+{
+ STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder) PURE;
+};
+*/
+
+#endif
View
198 7zip/7zip/Compress/LZ/LZInWindow.cpp
@@ -1,99 +1,99 @@
-// LZInWindow.cpp
-
-#include "StdAfx.h"
-
-#include "LZInWindow.h"
-#include "../../../Common/MyCom.h"
-#include "../../../Common/Alloc.h"
-
-void CLZInWindow::Free()
-{
- ::BigFree(_bufferBase);
- _bufferBase = 0;
-}
-
-bool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)
-{
- _keepSizeBefore = keepSizeBefore;
- _keepSizeAfter = keepSizeAfter;
- _keepSizeReserv = keepSizeReserv;
- UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
- if (_bufferBase == 0 || _blockSize != blockSize)
- {
- Free();
- _blockSize = blockSize;
- _bufferBase = (Byte *)::BigAlloc(_blockSize);
- }
- _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;
- return (_bufferBase != 0);
-}
-
-
-HRESULT CLZInWindow::Init(ISequentialInStream *stream)
-{
- _stream = stream;
- _buffer = _bufferBase;
- _pos = 0;
- _streamPos = 0;
- _streamEndWasReached = false;
- return ReadBlock();
-}
-
-/*
-void CLZInWindow::ReleaseStream()
-{
- _stream.Release();
-}
-*/
-
-///////////////////////////////////////////
-// ReadBlock
-
-// In State:
-// (_buffer + _streamPos) <= (_bufferBase + _blockSize)
-// Out State:
-// _posLimit <= _blockSize - _keepSizeAfter;
-// if(_streamEndWasReached == false):
-// _streamPos >= _pos + _keepSizeAfter
-// _posLimit = _streamPos - _keepSizeAfter;
-// else
-//
-
-HRESULT CLZInWindow::ReadBlock()
-{
- if(_streamEndWasReached)
- return S_OK;
- while(true)
- {
- UInt32 size = UInt32(_bufferBase - _buffer) + _blockSize - _streamPos;
- if(size == 0)
- return S_OK;
- UInt32 numReadBytes;
- RINOK(_stream->ReadPart(_buffer + _streamPos, size, &numReadBytes));
- if(numReadBytes == 0)
- {
- _posLimit = _streamPos;
- const Byte *pointerToPostion = _buffer + _posLimit;
- if(pointerToPostion > _pointerToLastSafePosition)
- _posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);
- _streamEndWasReached = true;
- return S_OK;
- }
- _streamPos += numReadBytes;
- if(_streamPos >= _pos + _keepSizeAfter)
- {
- _posLimit = _streamPos - _keepSizeAfter;
- return S_OK;
- }
- }
-}
-
-void CLZInWindow::MoveBlock()
-{
- BeforeMoveBlock();
- UInt32 offset = UInt32(_buffer - _bufferBase) + _pos - _keepSizeBefore;
- UInt32 numBytes = UInt32(_buffer - _bufferBase) + _streamPos - offset;
- memmove(_bufferBase, _bufferBase + offset, numBytes);
- _buffer -= offset;
- AfterMoveBlock();
-}
+// LZInWindow.cpp
+
+#include "StdAfx.h"
+
+#include "LZInWindow.h"
+#include "../../../Common/MyCom.h"
+#include "../../../Common/Alloc.h"
+
+void CLZInWindow::Free()
+{
+ ::BigFree(_bufferBase);
+ _bufferBase = 0;
+}
+
+bool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)
+{
+ _keepSizeBefore = keepSizeBefore;
+ _keepSizeAfter = keepSizeAfter;
+ _keepSizeReserv = keepSizeReserv;
+ UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
+ if (_bufferBase == 0 || _blockSize != blockSize)
+ {
+ Free();
+ _blockSize = blockSize;
+ _bufferBase = (Byte *)::BigAlloc(_blockSize);
+ }
+ _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;
+ return (_bufferBase != 0);
+}
+
+
+HRESULT CLZInWindow::Init(ISequentialInStream *stream)
+{
+ _stream = stream;
+ _buffer = _bufferBase;
+ _pos = 0;
+ _streamPos = 0;
+ _streamEndWasReached = false;
+ return ReadBlock();
+}
+
+/*
+void CLZInWindow::ReleaseStream()
+{
+ _stream.Release();
+}
+*/
+
+///////////////////////////////////////////
+// ReadBlock
+
+// In State:
+// (_buffer + _streamPos) <= (_bufferBase + _blockSize)
+// Out State:
+// _posLimit <= _blockSize - _keepSizeAfter;
+// if(_streamEndWasReached == false):
+// _streamPos >= _pos + _keepSizeAfter
+// _posLimit = _streamPos - _keepSizeAfter;
+// else
+//
+
+HRESULT CLZInWindow::ReadBlock()
+{
+ if(_streamEndWasReached)
+ return S_OK;
+ while(true)
+ {
+ UInt32 size = UInt32(_bufferBase - _buffer) + _blockSize - _streamPos;
+ if(size == 0)
+ return S_OK;
+ UInt32 numReadBytes;
+ RINOK(_stream->ReadPart(_buffer + _streamPos, size, &numReadBytes));
+ if(numReadBytes == 0)
+ {
+ _posLimit = _streamPos;
+ const Byte *pointerToPostion = _buffer + _posLimit;
+ if(pointerToPostion > _pointerToLastSafePosition)
+ _posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);
+ _streamEndWasReached = true;
+ return S_OK;
+ }
+ _streamPos += numReadBytes;
+ if(_streamPos >= _pos + _keepSizeAfter)
+ {
+ _posLimit = _streamPos - _keepSizeAfter;
+ return S_OK;
+ }
+ }
+}
+
+void CLZInWindow::MoveBlock()
+{
+ BeforeMoveBlock();
+ UInt32 offset = UInt32(_buffer - _bufferBase) + _pos - _keepSizeBefore;
+ UInt32 numBytes = UInt32(_buffer - _bufferBase) + _streamPos - offset;
+ memmove(_bufferBase, _bufferBase + offset, numBytes);
+ _buffer -= offset;
+ AfterMoveBlock();
+}
View
168 7zip/7zip/Compress/LZ/LZInWindow.h
@@ -1,84 +1,84 @@
-// LZInWindow.h
-
-#ifndef __LZ_IN_WINDOW_H
-#define __LZ_IN_WINDOW_H
-
-#include "../../IStream.h"
-
-class CLZInWindow
-{
- Byte *_bufferBase; // pointer to buffer with data
- ISequentialInStream *_stream;
- UInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done
- bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
- const Byte *_pointerToLastSafePosition;
-protected:
- Byte *_buffer; // Pointer to virtual Buffer begin
- UInt32 _blockSize; // Size of Allocated memory block
- UInt32 _pos; // offset (from _buffer) of curent byte
- UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
- UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
- UInt32 _keepSizeReserv; // how many BYTEs must be kept as reserv
- UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream
-
- virtual void BeforeMoveBlock() {};
- virtual void AfterMoveBlock() {};
- void MoveBlock();
- virtual HRESULT ReadBlock();
- void Free();
-public:
- CLZInWindow(): _bufferBase(0) {}
- virtual ~CLZInWindow() { Free(); }
-
- bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter,
- UInt32 keepSizeReserv = (1<<17));
-
- HRESULT Init(ISequentialInStream *stream);
- // void ReleaseStream();
-
- Byte *GetBuffer() const { return _buffer; }
-
- const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }
-
- HRESULT MovePos()
- {
- _pos++;
- if (_pos > _posLimit)
- {
- const Byte *pointerToPostion = _buffer + _pos;
- if(pointerToPostion > _pointerToLastSafePosition)
- MoveBlock();
- return ReadBlock();
- }
- else
- return S_OK;
- }
- Byte GetIndexByte(Int32 index)const
- { return _buffer[(size_t)_pos + index]; }
-
- // index + limit have not to exceed _keepSizeAfter;
- UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
- {
- if(_streamEndWasReached)
- if ((_pos + index) + limit > _streamPos)
- limit = _streamPos - (_pos + index);
- distance++;
- Byte *pby = _buffer + (size_t)_pos + index;
- UInt32 i;
- for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
- return i;
- }
-
- UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }
-
- void ReduceOffsets(Int32 subValue)
- {
- _buffer += subValue;
- _posLimit -= subValue;
- _pos -= subValue;
- _streamPos -= subValue;
- }
-
-};
-
-#endif
+// LZInWindow.h
+
+#ifndef __LZ_IN_WINDOW_H
+#define __LZ_IN_WINDOW_H
+
+#include "../../IStream.h"
+
+class CLZInWindow
+{
+ Byte *_bufferBase; // pointer to buffer with data
+ ISequentialInStream *_stream;
+ UInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done
+ bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
+ const Byte *_pointerToLastSafePosition;
+protected:
+ Byte *_buffer; // Pointer to virtual Buffer begin
+ UInt32 _blockSize; // Size of Allocated memory block
+ UInt32 _pos; // offset (from _buffer) of curent byte
+ UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
+ UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
+ UInt32 _keepSizeReserv; // how many BYTEs must be kept as reserv
+ UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream
+
+ virtual void BeforeMoveBlock() {};
+ virtual void AfterMoveBlock() {};
+ void MoveBlock();
+ virtual HRESULT ReadBlock();
+ void Free();
+public:
+ CLZInWindow(): _bufferBase(0) {}
+ virtual ~CLZInWindow() { Free(); }
+
+ bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter,
+ UInt32 keepSizeReserv = (1<<17));
+
+ HRESULT Init(ISequentialInStream *stream);
+ // void ReleaseStream();
+
+ Byte *GetBuffer() const { return _buffer; }
+
+ const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }
+
+ HRESULT MovePos()
+ {
+ _pos++;
+ if (_pos > _posLimit)
+ {
+ const Byte *pointerToPostion = _buffer + _pos;
+ if(pointerToPostion > _pointerToLastSafePosition)
+ MoveBlock();
+ return ReadBlock();
+ }
+ else
+ return S_OK;
+ }
+ Byte GetIndexByte(Int32 index)const
+ { return _buffer[(size_t)_pos + index]; }
+
+ // index + limit have not to exceed _keepSizeAfter;
+ UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
+ {
+ if(_streamEndWasReached)
+ if ((_pos + index) + limit > _streamPos)
+ limit = _streamPos - (_pos + index);
+ distance++;
+ Byte *pby = _buffer + (size_t)_pos + index;
+ UInt32 i;
+ for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
+ return i;
+ }
+
+ UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }
+
+ void ReduceOffsets(Int32 subValue)
+ {
+ _buffer += subValue;
+ _posLimit -= subValue;
+ _pos -= subValue;
+ _streamPos -= subValue;
+ }
+
+};
+
+#endif
View
624 7zip/7zip/Compress/LZ/MT/MT.cpp
@@ -1,312 +1,312 @@
-// MT.cpp
-
-#include "StdAfx.h"
-
-#include "../../../../Common/Alloc.h"
-
-#include "MT.h"
-
-class CMatchFinderCallback:
- public IMatchFinderCallback,
- public CMyUnknownImp
-{
- MY_UNKNOWN_IMP
-
- STDMETHOD(BeforeChangingBufferPos)();
- STDMETHOD(AfterChangingBufferPos)();
-public:
- CMatchFinderMT *m_MatchFinderMT;
- const Byte *m_BufferPosBefore;
-};
-
-STDMETHODIMP CMatchFinderCallback::BeforeChangingBufferPos()
-{
- m_MatchFinderMT->m_AskChangeBufferPos.Set();
- m_MatchFinderMT->m_CanChangeBufferPos.Lock();
- m_BufferPosBefore = m_MatchFinderMT->m_MatchFinder->GetPointerToCurrentPos();
- return S_OK;
-}
-
-STDMETHODIMP CMatchFinderCallback::AfterChangingBufferPos()
-{
- m_MatchFinderMT->m_DataCurrentPos +=
- m_MatchFinderMT->m_MatchFinder->GetPointerToCurrentPos() - m_BufferPosBefore;
- m_MatchFinderMT->m_BufferPosWasChanged.Set();
- return S_OK;
-}
-
-HRESULT CMatchFinderMT::SetMatchFinder(IMatchFinder *matchFinder,
- UInt32 multiThreadMult)
-{
- _multiThreadMult = multiThreadMult;
- m_MatchFinder = matchFinder;
- CMyComPtr<IMatchFinderSetCallback> matchFinderSetCallback;
- if (m_MatchFinder.QueryInterface(IID_IMatchFinderSetCallback,
- &matchFinderSetCallback) == S_OK)
- {
- CMatchFinderCallback *matchFinderCallbackSpec =
- new CMatchFinderCallback;
- CMyComPtr<IMatchFinderCallback> matchFinderCallback = matchFinderCallbackSpec;
- matchFinderCallbackSpec->m_MatchFinderMT = this;
- matchFinderSetCallback->SetCallback(matchFinderCallback);
- return S_OK;
- }
- else
- return E_FAIL;
-}
-
-
-STDMETHODIMP CMatchFinderMT::Init(ISequentialInStream *s)
-{
- m_AskChangeBufferPos.Reset();
- m_CanChangeBufferPos.Reset();
- m_BufferPosWasChanged.Reset();
- m_StopWriting.Reset();
- m_WritingWasStopped.Reset();
- m_NeedStart = true;
- m_CurrentPos = 0;
- m_CurrentLimitPos = 0;
-
- HRESULT result = m_MatchFinder->Init(s);
- if (result == S_OK)
- m_DataCurrentPos = m_MatchFinder->GetPointerToCurrentPos();
- return result;
-}
-
-STDMETHODIMP_(void) CMatchFinderMT::ReleaseStream()
-{
- m_StopWriting.Set();
- m_WritingWasStopped.Lock();
- m_MatchFinder->ReleaseStream();
-}
-
-STDMETHODIMP CMatchFinderMT::MovePos()
-{
- if (m_Result != S_OK)
- return m_Result;
- m_NumAvailableBytesCurrent--;
- m_DataCurrentPos++;
- return S_OK;
-}
-
-STDMETHODIMP_(Byte) CMatchFinderMT::GetIndexByte(Int32 index)
-{
- return m_DataCurrentPos[index];
-}
-
-STDMETHODIMP_(UInt32) CMatchFinderMT::GetMatchLen(Int32 index,
- UInt32 distance, UInt32 limit)
-{
- if (int(index + limit) > m_NumAvailableBytesCurrent)
- limit = m_NumAvailableBytesCurrent - (index);
- distance++;
- const Byte *pby = m_DataCurrentPos + index;
- UInt32 i;
- for(i = 0; i < limit && pby[i] == pby[i - distance]; i++);
- return i;
-}
-
-STDMETHODIMP_(const Byte *) CMatchFinderMT::GetPointerToCurrentPos()
-{
- return m_DataCurrentPos;
-}
-
-
-STDMETHODIMP_(UInt32) CMatchFinderMT::GetNumAvailableBytes()
-{
- if (m_NeedStart)
- return m_MatchFinder->GetNumAvailableBytes();
- else
- return m_NumAvailableBytesCurrent;
-}
-
-void CMatchFinderMT::FreeMem()
-{
- MyFree(m_Buffer);
- MyFree(m_DummyBuffer);
-}
-
-STDMETHODIMP CMatchFinderMT::Create(UInt32 sizeHistory,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen,
- UInt32 keepAddBufferAfter)
-{
- FreeMem();
- m_MatchMaxLen = matchMaxLen;
-
- m_BlockSize = (matchMaxLen + 1) * _multiThreadMult;
- UInt32 bufferSize = m_BlockSize * kNumMTBlocks;
- m_DummyBuffer = (UInt32 *)MyAlloc((matchMaxLen + 1) * sizeof(UInt32));
- if (m_DummyBuffer == 0)
- return E_OUTOFMEMORY;
- m_Buffer = (UInt32 *)MyAlloc(bufferSize * sizeof(UInt32));
- if (m_Buffer == 0)
- return E_OUTOFMEMORY;
- for (int i = 0; i < kNumMTBlocks; i++)
- m_Buffers[i] = &m_Buffer[i * m_BlockSize];
-
- m_NeedStart = true;
- m_CurrentPos = 0;
- m_CurrentLimitPos = 0;
-
- keepAddBufferBefore += bufferSize;
-
- return m_MatchFinder->Create(sizeHistory, keepAddBufferBefore, matchMaxLen,
- keepAddBufferAfter);
-}
-
-static DWORD WINAPI MFThread(void *threadCoderInfo)
-{
- CMatchFinderMT &mt = *(CMatchFinderMT *)threadCoderInfo;
- return mt.ThreadFunc();
-}
-
-DWORD CMatchFinderMT::ThreadFunc()
-{
- bool errorMode = false;
- while (true)
- {
- HANDLE events[3] = { m_ExitEvent, m_StopWriting, m_CanWriteEvents[m_WriteBufferIndex] } ;
- DWORD waitResult = ::WaitForMultipleObjects((errorMode ? 2: 3), events, FALSE, INFINITE);
- if (waitResult == WAIT_OBJECT_0 + 0)
- return 0;
- if (waitResult == WAIT_OBJECT_0 + 1)
- {
- m_WriteBufferIndex = 0;
- for (int i = 0; i < kNumMTBlocks; i++)
- m_CanWriteEvents[i].Reset();
- m_WritingWasStopped.Set();
- errorMode = false;
- continue;
- }
- if (errorMode)
- {
- // this case means bug_in_program. So just exit;
- return 1;
- }
-
- m_Results[m_WriteBufferIndex] = S_OK;
- UInt32 *buffer = m_Buffers[m_WriteBufferIndex];
- UInt32 curPos = 0;
- UInt32 numBytes = 0;
- UInt32 limit = m_BlockSize - m_MatchMaxLen;
- IMatchFinder *mf = m_MatchFinder;
- do
- {
- if (mf->GetNumAvailableBytes() == 0)
- break;
- UInt32 len = mf->GetLongestMatch(buffer + curPos);
- /*
- if (len == 1)
- len = 0;
- */
- buffer[curPos] = len;
- curPos += len + 1;
- numBytes++;
- HRESULT result = mf->MovePos();
- if (result != S_OK)
- {
- m_Results[m_WriteBufferIndex] = result;
- errorMode = true;
- break;
- }
- }
- while (curPos < limit);
- m_LimitPos[m_WriteBufferIndex] = curPos;
- if (errorMode)
- m_NumAvailableBytes[m_WriteBufferIndex] = numBytes;
- else
- m_NumAvailableBytes[m_WriteBufferIndex] = numBytes +
- mf->GetNumAvailableBytes();
- m_CanReadEvents[m_WriteBufferIndex].Set();
- if (++m_WriteBufferIndex == kNumMTBlocks)
- m_WriteBufferIndex = 0;
- }
-}
-
-CMatchFinderMT::CMatchFinderMT():
- m_Buffer(0),
- m_DummyBuffer(0),
- _multiThreadMult(100)
-{
- for (int i = 0; i < kNumMTBlocks; i++)
- {
- m_CanReadEvents[i].Reset();
- m_CanWriteEvents[i].Reset();
- }
- m_ReadBufferIndex = 0;
- m_WriteBufferIndex = 0;
-
- m_ExitEvent.Reset();
- if (!m_Thread.Create(MFThread, this))
- throw 271826;
-}
-
-CMatchFinderMT::~CMatchFinderMT()
-{
- m_ExitEvent.Set();
- m_Thread.Wait();
- FreeMem();
-}
-
-void CMatchFinderMT::Start()
-{
- m_AskChangeBufferPos.Reset();
- m_CanChangeBufferPos.Reset();
- m_BufferPosWasChanged.Reset();
-
- m_WriteBufferIndex = 0;
- m_ReadBufferIndex = 0;
- m_NeedStart = false;
- m_CurrentPos = 0;
- m_CurrentLimitPos = 0;
- m_Result = S_OK;
- int i;
- for (i = 0; i < kNumMTBlocks; i++)
- m_CanReadEvents[i].Reset();
- for (i = kNumMTBlocks - 1; i >= 0; i--)
- m_CanWriteEvents[i].Set();
-}
-
-STDMETHODIMP_(UInt32) CMatchFinderMT::GetLongestMatch(UInt32 *distances)
-{
- if (m_CurrentPos == m_CurrentLimitPos)
- {
- if (m_NeedStart)
- Start();
- while (true)
- {
- HANDLE events[2] = { m_AskChangeBufferPos, m_CanReadEvents[m_ReadBufferIndex] } ;
- DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);
- if (waitResult == WAIT_OBJECT_0 + 1)
- break;
- m_BufferPosWasChanged.Reset();
- m_CanChangeBufferPos.Set();
- m_BufferPosWasChanged.Lock();
- }
-
- m_CurrentLimitPos = m_LimitPos[m_ReadBufferIndex];
- m_NumAvailableBytesCurrent = m_NumAvailableBytes[m_ReadBufferIndex];
- m_CurrentPos = 0;
- m_Result = m_Results[m_ReadBufferIndex];
- }
- /*
- if (m_CurrentPos >= m_CurrentLimitPos)
- throw 1123324;
- */
- const UInt32 *buffer = m_Buffers[m_ReadBufferIndex];
- UInt32 len = buffer[m_CurrentPos++];
- for (UInt32 i = 1; i <= len; i++)
- distances[i] = buffer[m_CurrentPos++];
- if (m_CurrentPos == m_CurrentLimitPos)
- {
- m_CanWriteEvents[m_ReadBufferIndex].Set();
- if (++m_ReadBufferIndex == kNumMTBlocks)
- m_ReadBufferIndex = 0;
- }
- return len;
-}
-
-STDMETHODIMP_(void) CMatchFinderMT::DummyLongestMatch()
-{
- GetLongestMatch(m_DummyBuffer);
-}
+// MT.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../Common/Alloc.h"
+
+#include "MT.h"
+
+class CMatchFinderCallback:
+ public IMatchFinderCallback,
+ public CMyUnknownImp
+{
+ MY_UNKNOWN_IMP
+
+ STDMETHOD(BeforeChangingBufferPos)();
+ STDMETHOD(AfterChangingBufferPos)();
+public:
+ CMatchFinderMT *m_MatchFinderMT;
+ const Byte *m_BufferPosBefore;
+};
+
+STDMETHODIMP CMatchFinderCallback::BeforeChangingBufferPos()
+{
+ m_MatchFinderMT->m_AskChangeBufferPos.Set();
+ m_MatchFinderMT->m_CanChangeBufferPos.Lock();
+ m_BufferPosBefore = m_MatchFinderMT->m_MatchFinder->GetPointerToCurrentPos();
+ return S_OK;
+}
+
+STDMETHODIMP CMatchFinderCallback::AfterChangingBufferPos()