private void Test2(int n, int p) { var pipe = new Pipe(); var t = new GolombEncoder(pipe.Writer, p); var list_1 = new List <uint>(); { var random = new Random(); for (int i = 0; i < n; i++) { list_1.Add((uint)(random.Next() % (n * p))); } list_1.Sort(); uint previous = 0; for (int i = 0; i < n; i++) { t.Encoding(list_1[i] - previous); previous = list_1[i]; } } t.Flush(); pipe.Writer.Complete(); pipe.Reader.TryRead(out var readResult); Debug.WriteLine(readResult.Buffer.Length); var d = new GolombDecoder(readResult.Buffer, p); var list_2 = new List <uint>(); { uint current = 0; for (; ;) { if (!d.TryDecode(out var result)) { break; } current += result; list_2.Add(current); } } Debug.Assert(Enumerable.SequenceEqual(list_1, list_2)); }
private void Test(int n, int p) { var pipe = new Pipe(); var t = new GolombEncoder(pipe.Writer, p); { var list = new List <uint>(); var random = new Random(); for (int i = 0; i < n; i++) { list.Add((uint)(random.Next() % (n * p))); } list.Sort(); for (int i = 1; i < n; i++) { t.Encoding(list[i] - list[i - 1]); } } t.Flush(); pipe.Writer.Complete(); var s = pipe.Reader.ReadAsync().Result.Buffer.ToArray(); var sb = new StringBuilder(); foreach (var b in s) { sb.Append(Convert.ToString(b, 2)); } Debug.WriteLine(s.Length); }