ruby-lzma 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/README.markdown +15 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/ext/Alloc.cpp +118 -0
- data/ext/Alloc.h +29 -0
- data/ext/BinTree.h +55 -0
- data/ext/BinTree2.h +12 -0
- data/ext/BinTree3.h +16 -0
- data/ext/BinTree3Z.h +16 -0
- data/ext/BinTree4.h +18 -0
- data/ext/BinTree4b.h +20 -0
- data/ext/BinTreeMain.h +444 -0
- data/ext/BranchX86.c +101 -0
- data/ext/BranchX86.h +19 -0
- data/ext/CRC.cpp +61 -0
- data/ext/CRC.h +36 -0
- data/ext/C_FileIO.h +45 -0
- data/ext/CommandLineParser.h +82 -0
- data/ext/Defs.h +20 -0
- data/ext/FileStreams.h +98 -0
- data/ext/HC.h +55 -0
- data/ext/HC2.h +13 -0
- data/ext/HC3.h +17 -0
- data/ext/HC4.h +19 -0
- data/ext/HC4b.h +21 -0
- data/ext/HCMain.h +350 -0
- data/ext/ICoder.h +156 -0
- data/ext/IMatchFinder.h +63 -0
- data/ext/IStream.h +62 -0
- data/ext/InBuffer.cpp +80 -0
- data/ext/InBuffer.h +76 -0
- data/ext/LZInWindow.cpp +102 -0
- data/ext/LZInWindow.h +84 -0
- data/ext/LZMA.h +82 -0
- data/ext/LZMADecoder.h +248 -0
- data/ext/LZMAEncoder.cpp +1504 -0
- data/ext/LZMAEncoder.h +416 -0
- data/ext/LZOutWindow.cpp +17 -0
- data/ext/LZOutWindow.h +66 -0
- data/ext/LzmaBench.h +11 -0
- data/ext/LzmaDecode.c +588 -0
- data/ext/LzmaDecode.h +131 -0
- data/ext/LzmaRam.cpp +228 -0
- data/ext/LzmaRam.h +46 -0
- data/ext/LzmaRamDecode.c +79 -0
- data/ext/LzmaRamDecode.h +55 -0
- data/ext/MyCom.h +203 -0
- data/ext/MyGuidDef.h +54 -0
- data/ext/MyInitGuid.h +13 -0
- data/ext/MyString.h +631 -0
- data/ext/MyUnknown.h +24 -0
- data/ext/MyWindows.h +183 -0
- data/ext/OutBuffer.cpp +117 -0
- data/ext/OutBuffer.h +64 -0
- data/ext/Pat.h +318 -0
- data/ext/Pat2.h +22 -0
- data/ext/Pat2H.h +24 -0
- data/ext/Pat2R.h +20 -0
- data/ext/Pat3H.h +24 -0
- data/ext/Pat4H.h +24 -0
- data/ext/PatMain.h +989 -0
- data/ext/RangeCoder.h +205 -0
- data/ext/RangeCoderBit.cpp +80 -0
- data/ext/RangeCoderBit.h +120 -0
- data/ext/RangeCoderBitTree.h +161 -0
- data/ext/RangeCoderOpt.h +31 -0
- data/ext/StdAfx.h +8 -0
- data/ext/StreamUtils.cpp +44 -0
- data/ext/StreamUtils.h +11 -0
- data/ext/StringConvert.h +71 -0
- data/ext/StringToInt.h +17 -0
- data/ext/Types.h +19 -0
- data/ext/Vector.h +211 -0
- data/ext/extconf.rb +7 -0
- data/ext/lzma_ruby.cpp +51 -0
- data/ext/lzmalib.h +64 -0
- data/ext/mylib.cpp +81 -0
- data/java/SevenZip/CRC.java +52 -0
- data/java/SevenZip/Compression/LZ/BinTree.java +382 -0
- data/java/SevenZip/Compression/LZ/InWindow.java +131 -0
- data/java/SevenZip/Compression/LZ/OutWindow.java +85 -0
- data/java/SevenZip/Compression/LZMA/Base.java +88 -0
- data/java/SevenZip/Compression/LZMA/Decoder.java +329 -0
- data/java/SevenZip/Compression/LZMA/Encoder.java +1415 -0
- data/java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java +55 -0
- data/java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java +99 -0
- data/java/SevenZip/Compression/RangeCoder/Decoder.java +88 -0
- data/java/SevenZip/Compression/RangeCoder/Encoder.java +151 -0
- data/java/SevenZip/ICodeProgress.java +6 -0
- data/java/SevenZip/LzmaAlone.java +253 -0
- data/java/SevenZip/LzmaBench.java +391 -0
- data/java/com/ephemeronindustries/lzma/LZMA.java +104 -0
- data/lib/lzma.rb +32 -0
- data/ruby-lzma.gemspec +136 -0
- data/test/test_lzma.rb +42 -0
- metadata +157 -0
data/ext/RangeCoderOpt.h
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
// Compress/RangeCoder/RangeCoderOpt.h
|
2
|
+
|
3
|
+
#ifndef __COMPRESS_RANGECODER_OPT_H
|
4
|
+
#define __COMPRESS_RANGECODER_OPT_H
|
5
|
+
|
6
|
+
#define RC_INIT_VAR \
|
7
|
+
UInt32 range = rangeDecoder->Range; \
|
8
|
+
UInt32 code = rangeDecoder->Code;
|
9
|
+
|
10
|
+
#define RC_FLUSH_VAR \
|
11
|
+
rangeDecoder->Range = range; \
|
12
|
+
rangeDecoder->Code = code;
|
13
|
+
|
14
|
+
#define RC_NORMALIZE \
|
15
|
+
if (range < NCompress::NRangeCoder::kTopValue) \
|
16
|
+
{ code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }
|
17
|
+
|
18
|
+
#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \
|
19
|
+
{ UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \
|
20
|
+
if (code < bound) \
|
21
|
+
{ A0; range = bound; \
|
22
|
+
prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \
|
23
|
+
mi <<= 1; } \
|
24
|
+
else \
|
25
|
+
{ A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \
|
26
|
+
mi = (mi + mi) + 1; }} \
|
27
|
+
RC_NORMALIZE
|
28
|
+
|
29
|
+
#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)
|
30
|
+
|
31
|
+
#endif
|
data/ext/StdAfx.h
ADDED
data/ext/StreamUtils.cpp
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
// StreamUtils.cpp
|
2
|
+
|
3
|
+
#include "StdAfx.h"
|
4
|
+
|
5
|
+
#include "MyCom.h"
|
6
|
+
#include "StreamUtils.h"
|
7
|
+
|
8
|
+
HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)
|
9
|
+
{
|
10
|
+
if (processedSize != 0)
|
11
|
+
*processedSize = 0;
|
12
|
+
while(size != 0)
|
13
|
+
{
|
14
|
+
UInt32 processedSizeLoc;
|
15
|
+
HRESULT res = stream->Read(data, size, &processedSizeLoc);
|
16
|
+
if (processedSize != 0)
|
17
|
+
*processedSize += processedSizeLoc;
|
18
|
+
data = (Byte *)((Byte *)data + processedSizeLoc);
|
19
|
+
size -= processedSizeLoc;
|
20
|
+
RINOK(res);
|
21
|
+
if (processedSizeLoc == 0)
|
22
|
+
return S_OK;
|
23
|
+
}
|
24
|
+
return S_OK;
|
25
|
+
}
|
26
|
+
|
27
|
+
HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)
|
28
|
+
{
|
29
|
+
if (processedSize != 0)
|
30
|
+
*processedSize = 0;
|
31
|
+
while(size != 0)
|
32
|
+
{
|
33
|
+
UInt32 processedSizeLoc;
|
34
|
+
HRESULT res = stream->Write(data, size, &processedSizeLoc);
|
35
|
+
if (processedSize != 0)
|
36
|
+
*processedSize += processedSizeLoc;
|
37
|
+
data = (const void *)((const Byte *)data + processedSizeLoc);
|
38
|
+
size -= processedSizeLoc;
|
39
|
+
RINOK(res);
|
40
|
+
if (processedSizeLoc == 0)
|
41
|
+
break;
|
42
|
+
}
|
43
|
+
return S_OK;
|
44
|
+
}
|
data/ext/StreamUtils.h
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
// StreamUtils.h
|
2
|
+
|
3
|
+
#ifndef __STREAMUTILS_H
|
4
|
+
#define __STREAMUTILS_H
|
5
|
+
|
6
|
+
#include "IStream.h"
|
7
|
+
|
8
|
+
HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);
|
9
|
+
HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);
|
10
|
+
|
11
|
+
#endif
|
data/ext/StringConvert.h
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
// Common/StringConvert.h
|
2
|
+
|
3
|
+
#ifndef __COMMON_STRINGCONVERT_H
|
4
|
+
#define __COMMON_STRINGCONVERT_H
|
5
|
+
|
6
|
+
#include "MyWindows.h"
|
7
|
+
#include "MyString.h"
|
8
|
+
#include "Types.h"
|
9
|
+
|
10
|
+
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);
|
11
|
+
AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);
|
12
|
+
|
13
|
+
inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)
|
14
|
+
{ return unicodeString; }
|
15
|
+
inline const UString& GetUnicodeString(const UString &unicodeString)
|
16
|
+
{ return unicodeString; }
|
17
|
+
inline UString GetUnicodeString(const AString &ansiString)
|
18
|
+
{ return MultiByteToUnicodeString(ansiString); }
|
19
|
+
inline UString GetUnicodeString(const AString &multiByteString, UINT codePage)
|
20
|
+
{ return MultiByteToUnicodeString(multiByteString, codePage); }
|
21
|
+
inline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)
|
22
|
+
{ return unicodeString; }
|
23
|
+
inline const UString& GetUnicodeString(const UString &unicodeString, UINT)
|
24
|
+
{ return unicodeString; }
|
25
|
+
|
26
|
+
inline const char* GetAnsiString(const char* ansiString)
|
27
|
+
{ return ansiString; }
|
28
|
+
inline const AString& GetAnsiString(const AString &ansiString)
|
29
|
+
{ return ansiString; }
|
30
|
+
inline AString GetAnsiString(const UString &unicodeString)
|
31
|
+
{ return UnicodeStringToMultiByte(unicodeString); }
|
32
|
+
|
33
|
+
inline const char* GetOemString(const char* oemString)
|
34
|
+
{ return oemString; }
|
35
|
+
inline const AString& GetOemString(const AString &oemString)
|
36
|
+
{ return oemString; }
|
37
|
+
inline AString GetOemString(const UString &unicodeString)
|
38
|
+
{ return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }
|
39
|
+
|
40
|
+
|
41
|
+
#ifdef _UNICODE
|
42
|
+
inline const wchar_t* GetSystemString(const wchar_t* unicodeString)
|
43
|
+
{ return unicodeString;}
|
44
|
+
inline const UString& GetSystemString(const UString &unicodeString)
|
45
|
+
{ return unicodeString;}
|
46
|
+
inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT codePage)
|
47
|
+
{ return unicodeString;}
|
48
|
+
inline const UString& GetSystemString(const UString &unicodeString, UINT codePage)
|
49
|
+
{ return unicodeString;}
|
50
|
+
inline UString GetSystemString(const AString &multiByteString, UINT codePage)
|
51
|
+
{ return MultiByteToUnicodeString(multiByteString, codePage);}
|
52
|
+
inline UString GetSystemString(const AString &multiByteString)
|
53
|
+
{ return MultiByteToUnicodeString(multiByteString);}
|
54
|
+
#else
|
55
|
+
inline const char* GetSystemString(const char *ansiString)
|
56
|
+
{ return ansiString; }
|
57
|
+
inline const AString& GetSystemString(const AString &multiByteString, UINT)
|
58
|
+
{ return multiByteString; }
|
59
|
+
inline const char * GetSystemString(const char *multiByteString, UINT)
|
60
|
+
{ return multiByteString; }
|
61
|
+
inline AString GetSystemString(const UString &unicodeString)
|
62
|
+
{ return UnicodeStringToMultiByte(unicodeString); }
|
63
|
+
inline AString GetSystemString(const UString &unicodeString, UINT codePage)
|
64
|
+
{ return UnicodeStringToMultiByte(unicodeString, codePage); }
|
65
|
+
#endif
|
66
|
+
|
67
|
+
#ifndef _WIN32_WCE
|
68
|
+
AString SystemStringToOemString(const CSysString &srcString);
|
69
|
+
#endif
|
70
|
+
|
71
|
+
#endif
|
data/ext/StringToInt.h
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
// Common/StringToInt.h
|
2
|
+
|
3
|
+
#ifndef __COMMON_STRINGTOINT_H
|
4
|
+
#define __COMMON_STRINGTOINT_H
|
5
|
+
|
6
|
+
#include <string.h>
|
7
|
+
#include "Types.h"
|
8
|
+
|
9
|
+
UInt64 ConvertStringToUInt64(const char *s, const char **end);
|
10
|
+
UInt64 ConvertOctStringToUInt64(const char *s, const char **end);
|
11
|
+
UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);
|
12
|
+
|
13
|
+
Int64 ConvertStringToInt64(const char *s, const char **end);
|
14
|
+
|
15
|
+
#endif
|
16
|
+
|
17
|
+
|
data/ext/Types.h
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
// Common/Types.h
|
2
|
+
|
3
|
+
#ifndef __COMMON_TYPES_H
|
4
|
+
#define __COMMON_TYPES_H
|
5
|
+
|
6
|
+
typedef unsigned char Byte;
|
7
|
+
typedef short Int16;
|
8
|
+
typedef unsigned short UInt16;
|
9
|
+
typedef int Int32;
|
10
|
+
typedef unsigned int UInt32;
|
11
|
+
#ifdef _MSC_VER
|
12
|
+
typedef __int64 Int64;
|
13
|
+
typedef unsigned __int64 UInt64;
|
14
|
+
#else
|
15
|
+
typedef long long int Int64;
|
16
|
+
typedef unsigned long long int UInt64;
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#endif
|
data/ext/Vector.h
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
// Common/Vector.h
|
2
|
+
|
3
|
+
#ifndef __COMMON_VECTOR_H
|
4
|
+
#define __COMMON_VECTOR_H
|
5
|
+
|
6
|
+
#include "Defs.h"
|
7
|
+
|
8
|
+
class CBaseRecordVector
|
9
|
+
{
|
10
|
+
void MoveItems(int destIndex, int srcIndex);
|
11
|
+
protected:
|
12
|
+
int _capacity;
|
13
|
+
int _size;
|
14
|
+
void *_items;
|
15
|
+
size_t _itemSize;
|
16
|
+
|
17
|
+
void ReserveOnePosition();
|
18
|
+
void InsertOneItem(int index);
|
19
|
+
void TestIndexAndCorrectNum(int index, int &num) const
|
20
|
+
{ if (index + num > _size) num = _size - index; }
|
21
|
+
public:
|
22
|
+
CBaseRecordVector(size_t itemSize):
|
23
|
+
_capacity(0), _size(0), _items(0), _itemSize(itemSize) {}
|
24
|
+
virtual ~CBaseRecordVector();
|
25
|
+
int Size() const { return _size; }
|
26
|
+
bool IsEmpty() const { return (_size == 0); }
|
27
|
+
void Reserve(int newCapacity);
|
28
|
+
virtual void Delete(int index, int num = 1);
|
29
|
+
void Clear();
|
30
|
+
void DeleteFrom(int index);
|
31
|
+
void DeleteBack();
|
32
|
+
};
|
33
|
+
|
34
|
+
template <class T>
|
35
|
+
class CRecordVector: public CBaseRecordVector
|
36
|
+
{
|
37
|
+
public:
|
38
|
+
CRecordVector():CBaseRecordVector(sizeof(T)){};
|
39
|
+
CRecordVector(const CRecordVector &v):
|
40
|
+
CBaseRecordVector(sizeof(T)) { *this = v;}
|
41
|
+
CRecordVector& operator=(const CRecordVector &v)
|
42
|
+
{
|
43
|
+
Clear();
|
44
|
+
return (*this += v);
|
45
|
+
}
|
46
|
+
CRecordVector& operator+=(const CRecordVector &v)
|
47
|
+
{
|
48
|
+
int size = v.Size();
|
49
|
+
Reserve(Size() + size);
|
50
|
+
for(int i = 0; i < size; i++)
|
51
|
+
Add(v[i]);
|
52
|
+
return *this;
|
53
|
+
}
|
54
|
+
int Add(T item)
|
55
|
+
{
|
56
|
+
ReserveOnePosition();
|
57
|
+
((T *)_items)[_size] = item;
|
58
|
+
return _size++;
|
59
|
+
}
|
60
|
+
void Insert(int index, T item)
|
61
|
+
{
|
62
|
+
InsertOneItem(index);
|
63
|
+
((T *)_items)[index] = item;
|
64
|
+
}
|
65
|
+
// T* GetPointer() const { return (T*)_items; }
|
66
|
+
// operator const T *() const { return _items; };
|
67
|
+
const T& operator[](int index) const { return ((T *)_items)[index]; }
|
68
|
+
T& operator[](int index) { return ((T *)_items)[index]; }
|
69
|
+
const T& Front() const { return operator[](0); }
|
70
|
+
T& Front() { return operator[](0); }
|
71
|
+
const T& Back() const { return operator[](_size - 1); }
|
72
|
+
T& Back() { return operator[](_size - 1); }
|
73
|
+
|
74
|
+
void Swap(int i, int j)
|
75
|
+
{
|
76
|
+
T temp = operator[](i);
|
77
|
+
operator[](i) = operator[](j);
|
78
|
+
operator[](j) = temp;
|
79
|
+
}
|
80
|
+
|
81
|
+
void Sort(int left, int right)
|
82
|
+
{
|
83
|
+
if (right - left < 2)
|
84
|
+
return;
|
85
|
+
Swap(left, (left + right) / 2);
|
86
|
+
int last = left;
|
87
|
+
for (int i = left; i < right; i++)
|
88
|
+
if (operator[](i) < operator[](left))
|
89
|
+
Swap(++last, i);
|
90
|
+
Swap(left, last);
|
91
|
+
Sort(left, last);
|
92
|
+
Sort(last + 1, right);
|
93
|
+
}
|
94
|
+
void Sort() { Sort(0, Size()); }
|
95
|
+
void Sort(int left, int right, int (*compare)(const T*, const T*, void *), void *param)
|
96
|
+
{
|
97
|
+
if (right - left < 2)
|
98
|
+
return;
|
99
|
+
Swap(left, (left + right) / 2);
|
100
|
+
int last = left;
|
101
|
+
for (int i = left; i < right; i++)
|
102
|
+
if (compare(&operator[](i), &operator[](left), param) < 0)
|
103
|
+
Swap(++last, i);
|
104
|
+
Swap(left, last);
|
105
|
+
Sort(left, last, compare, param);
|
106
|
+
Sort(last + 1, right, compare, param);
|
107
|
+
}
|
108
|
+
|
109
|
+
void Sort(int (*compare)(const T*, const T*, void *), void *param)
|
110
|
+
{
|
111
|
+
Sort(0, Size(), compare, param);
|
112
|
+
}
|
113
|
+
};
|
114
|
+
|
115
|
+
typedef CRecordVector<int> CIntVector;
|
116
|
+
typedef CRecordVector<unsigned int> CUIntVector;
|
117
|
+
typedef CRecordVector<bool> CBoolVector;
|
118
|
+
typedef CRecordVector<unsigned char> CByteVector;
|
119
|
+
typedef CRecordVector<void *> CPointerVector;
|
120
|
+
|
121
|
+
template <class T>
|
122
|
+
class CObjectVector: public CPointerVector
|
123
|
+
{
|
124
|
+
public:
|
125
|
+
CObjectVector(){};
|
126
|
+
~CObjectVector() { Clear(); }
|
127
|
+
CObjectVector(const CObjectVector &objectVector)
|
128
|
+
{ *this = objectVector; }
|
129
|
+
CObjectVector& operator=(const CObjectVector &objectVector)
|
130
|
+
{
|
131
|
+
Clear();
|
132
|
+
return (*this += objectVector);
|
133
|
+
}
|
134
|
+
CObjectVector& operator+=(const CObjectVector &objectVector)
|
135
|
+
{
|
136
|
+
int size = objectVector.Size();
|
137
|
+
Reserve(Size() + size);
|
138
|
+
for(int i = 0; i < size; i++)
|
139
|
+
Add(objectVector[i]);
|
140
|
+
return *this;
|
141
|
+
}
|
142
|
+
const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }
|
143
|
+
T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }
|
144
|
+
T& Front() { return operator[](0); }
|
145
|
+
const T& Front() const { return operator[](0); }
|
146
|
+
T& Back() { return operator[](_size - 1); }
|
147
|
+
const T& Back() const { return operator[](_size - 1); }
|
148
|
+
int Add(const T& item)
|
149
|
+
{ return CPointerVector::Add(new T(item)); }
|
150
|
+
void Insert(int index, const T& item)
|
151
|
+
{ CPointerVector::Insert(index, new T(item)); }
|
152
|
+
virtual void Delete(int index, int num = 1)
|
153
|
+
{
|
154
|
+
TestIndexAndCorrectNum(index, num);
|
155
|
+
for(int i = 0; i < num; i++)
|
156
|
+
delete (T *)(((void **)_items)[index + i]);
|
157
|
+
CPointerVector::Delete(index, num);
|
158
|
+
}
|
159
|
+
int Find(const T& item) const
|
160
|
+
{
|
161
|
+
for(int i = 0; i < Size(); i++)
|
162
|
+
if (item == (*this)[i])
|
163
|
+
return i;
|
164
|
+
return -1;
|
165
|
+
}
|
166
|
+
int FindInSorted(const T& item) const
|
167
|
+
{
|
168
|
+
int left = 0, right = Size();
|
169
|
+
while (left != right)
|
170
|
+
{
|
171
|
+
int mid = (left + right) / 2;
|
172
|
+
const T& midValue = (*this)[mid];
|
173
|
+
if (item == midValue)
|
174
|
+
return mid;
|
175
|
+
if (item < midValue)
|
176
|
+
right = mid;
|
177
|
+
else
|
178
|
+
left = mid + 1;
|
179
|
+
}
|
180
|
+
return -1;
|
181
|
+
}
|
182
|
+
int AddToSorted(const T& item)
|
183
|
+
{
|
184
|
+
int left = 0, right = Size();
|
185
|
+
while (left != right)
|
186
|
+
{
|
187
|
+
int mid = (left + right) / 2;
|
188
|
+
const T& midValue = (*this)[mid];
|
189
|
+
if (item == midValue)
|
190
|
+
{
|
191
|
+
right = mid + 1;
|
192
|
+
break;
|
193
|
+
}
|
194
|
+
if (item < midValue)
|
195
|
+
right = mid;
|
196
|
+
else
|
197
|
+
left = mid + 1;
|
198
|
+
}
|
199
|
+
Insert(right, item);
|
200
|
+
return right;
|
201
|
+
}
|
202
|
+
|
203
|
+
void Sort(int (*compare)(void *const *, void *const *, void *), void *param)
|
204
|
+
{ CPointerVector::Sort(compare, param); }
|
205
|
+
|
206
|
+
static int CompareObjectItems(void *const *a1, void *const *a2, void *param)
|
207
|
+
{ return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }
|
208
|
+
void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }
|
209
|
+
};
|
210
|
+
|
211
|
+
#endif
|
data/ext/extconf.rb
ADDED
data/ext/lzma_ruby.cpp
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "lzmalib.h"
|
3
|
+
#include "stdlib.h"
|
4
|
+
|
5
|
+
VALUE cLZMA;
|
6
|
+
|
7
|
+
static VALUE lz_compress(VALUE self, VALUE data) {
|
8
|
+
VALUE result = Qnil;
|
9
|
+
|
10
|
+
if(data != Qnil) {
|
11
|
+
void *data_ptr = RSTRING_PTR(data);
|
12
|
+
int data_len = RSTRING_LEN(data);
|
13
|
+
|
14
|
+
int out_size;
|
15
|
+
void *out_buffer = lzma_compress(data_ptr, data_len, &out_size);
|
16
|
+
|
17
|
+
if(out_buffer) {
|
18
|
+
result = rb_str_new((char*)out_buffer, out_size);
|
19
|
+
lzma_free(out_buffer);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE lz_decompress(VALUE self, VALUE data) {
|
27
|
+
VALUE result = Qnil;
|
28
|
+
|
29
|
+
if(data != Qnil) {
|
30
|
+
void *data_ptr = RSTRING_PTR(data);
|
31
|
+
int len = RSTRING_LEN(data);
|
32
|
+
|
33
|
+
int out_size;
|
34
|
+
void *out_buffer = lzma_decompress(data_ptr, len, &out_size);
|
35
|
+
|
36
|
+
if(out_buffer) {
|
37
|
+
result = rb_str_new((char*)out_buffer, out_size);
|
38
|
+
lzma_free(out_buffer);
|
39
|
+
} else {
|
40
|
+
rb_raise(rb_eRuntimeError, "Couldn't decompress with LZMA");
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
return result;
|
45
|
+
}
|
46
|
+
|
47
|
+
extern "C" void Init_lzma_ruby() {
|
48
|
+
cLZMA = rb_define_class("LZMA", rb_cObject);
|
49
|
+
rb_define_method(cLZMA, "compress", (VALUE(*)(...))lz_compress, 1);
|
50
|
+
rb_define_method(cLZMA, "decompress", (VALUE(*)(...))lz_decompress, 1);
|
51
|
+
}
|