|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
3 | 3 | using System.IO;
|
4 |
| -using System.Linq; |
5 |
| -using size_t = System.UIntPtr; |
6 |
| - |
7 |
| -namespace ZstdNet |
8 |
| -{ |
9 |
| - public static class DictBuilder |
10 |
| - { |
11 |
| - public static byte[] TrainFromBuffer(IEnumerable<byte[]> samples, int dictCapacity = DefaultDictCapacity) |
12 |
| - { |
13 |
| - var ms = new MemoryStream(); |
14 |
| - var samplesSizes = samples.Select(sample => |
15 |
| - { |
16 |
| - ms.Write(sample, 0, sample.Length); |
17 |
| - return (size_t)sample.Length; |
18 |
| - }).ToArray(); |
19 |
| - |
20 |
| - var dictBuffer = new byte[dictCapacity]; |
21 |
| - var dictSize = (int)ExternMethods |
22 |
| - .ZDICT_trainFromBuffer(dictBuffer, (size_t)dictCapacity, ms.ToArray(), samplesSizes, (uint)samplesSizes.Length) |
| 4 | +using System.Linq; |
| 5 | +using size_t = System.UIntPtr; |
| 6 | + |
| 7 | +namespace ZstdNet |
| 8 | +{ |
| 9 | + public static class DictBuilder |
| 10 | + { |
| 11 | + public static byte[] TrainFromBuffer(IEnumerable<byte[]> samples, int dictCapacity = DefaultDictCapacity) |
| 12 | + { |
| 13 | + var ms = new MemoryStream(); |
| 14 | + var samplesSizes = samples.Select(sample => |
| 15 | + { |
| 16 | + ms.Write(sample, 0, sample.Length); |
| 17 | + return (size_t)sample.Length; |
| 18 | + }).ToArray(); |
| 19 | + |
| 20 | + var dictBuffer = new byte[dictCapacity]; |
| 21 | + var dictSize = (int)ExternMethods |
| 22 | + .ZDICT_trainFromBuffer(dictBuffer, (size_t)dictCapacity, ms.GetBuffer(), samplesSizes, (uint)samplesSizes.Length) |
23 | 23 | .EnsureZdictSuccess();
|
24 | 24 |
|
25 |
| - if (dictCapacity != dictSize) |
| 25 | + if(dictCapacity != dictSize) |
26 | 26 | Array.Resize(ref dictBuffer, dictSize);
|
27 |
| - |
28 |
| - return dictBuffer; |
29 |
| - } |
30 |
| - |
31 |
| - public const int DefaultDictCapacity = 112640; // Used by zstd utility by default |
32 |
| - } |
33 |
| -} |
| 27 | + |
| 28 | + return dictBuffer; |
| 29 | + } |
| 30 | + |
| 31 | + public const int DefaultDictCapacity = 112640; // Used by zstd utility by default |
| 32 | + } |
| 33 | +} |
0 commit comments