-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libzstd 1.4.5 with dict training fix
ZDICT_optimizeTrainFromBuffer_[fast]Cover fails to select dictionary on some inputs: facebook/zstd#2371
- Loading branch information
Showing
4 changed files
with
39 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using size_t = System.UIntPtr; | ||
|
||
namespace ZstdNet | ||
{ | ||
public static class DictBuilder | ||
{ | ||
public static byte[] TrainFromBuffer(IEnumerable<byte[]> samples, int dictCapacity = DefaultDictCapacity) | ||
{ | ||
var ms = new MemoryStream(); | ||
var samplesSizes = samples.Select(sample => | ||
{ | ||
ms.Write(sample, 0, sample.Length); | ||
return (size_t)sample.Length; | ||
}).ToArray(); | ||
|
||
var dictBuffer = new byte[dictCapacity]; | ||
var dictSize = (int)ExternMethods | ||
.ZDICT_trainFromBuffer(dictBuffer, (size_t)dictCapacity, ms.ToArray(), samplesSizes, (uint)samplesSizes.Length) | ||
using System.Linq; | ||
using size_t = System.UIntPtr; | ||
|
||
namespace ZstdNet | ||
{ | ||
public static class DictBuilder | ||
{ | ||
public static byte[] TrainFromBuffer(IEnumerable<byte[]> samples, int dictCapacity = DefaultDictCapacity) | ||
{ | ||
var ms = new MemoryStream(); | ||
var samplesSizes = samples.Select(sample => | ||
{ | ||
ms.Write(sample, 0, sample.Length); | ||
return (size_t)sample.Length; | ||
}).ToArray(); | ||
|
||
var dictBuffer = new byte[dictCapacity]; | ||
var dictSize = (int)ExternMethods | ||
.ZDICT_trainFromBuffer(dictBuffer, (size_t)dictCapacity, ms.GetBuffer(), samplesSizes, (uint)samplesSizes.Length) | ||
.EnsureZdictSuccess(); | ||
|
||
if (dictCapacity != dictSize) | ||
if(dictCapacity != dictSize) | ||
Array.Resize(ref dictBuffer, dictSize); | ||
|
||
return dictBuffer; | ||
} | ||
|
||
public const int DefaultDictCapacity = 112640; // Used by zstd utility by default | ||
} | ||
} | ||
|
||
return dictBuffer; | ||
} | ||
|
||
public const int DefaultDictCapacity = 112640; // Used by zstd utility by default | ||
} | ||
} |
Binary file not shown.
Binary file not shown.