public static string Truncate <TValue>(this IntPrefixTree <TValue> .Node root, PrefixKey ip) where TValue : class { return(ip.ToBinary().Substring(0, root.Range)); }
/// <summary> /// Writes a signed 32-bit integer to the StreamEx. /// </summary> /// <param name="b">32-bit signed integer.</param> /// <param name="seq">Byte sequence a.k.a endianness.</param> public void WriteInt32(Int32 b, BitOrder seq = BitOrder.LittleEndian) { Write(b.ToBinary(seq), 0, 4); }
public void TestMultidimensionalArray() { Int32[,,] array3d = new Int32[2, 2, 3] { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } }; Byte [] binary = array3d.ToBinary <Int32[,,]> (); Int32[,,] result = binary.FromBinary <Int32[,,]> (); for (Int32 i = 0; i < 2; ++i) { for (Int32 j = 0; j < 2; ++j) { for (Int32 k = 0; k < 3; ++k) { Assert.That (array3d [i,j,k] == result [i,j,k]); } } } }
public void TestNormalValueArray() { Int32[] array = new Int32 [6] { 0, 1, 2, 3, 4, 5}; Byte [] binary = array.ToBinary <Int32[]> (); Int32[] result = binary.FromBinary <Int32[]> (); for (Int32 i = 0; i < array.Length; ++i) { Assert.That (array [i] == result [i]); } }
public void TestJaggedArray() { Int32[][] jaggedArray = new Int32 [5][]; jaggedArray [0] = new Int32[2] { 0, 1 }; jaggedArray [1] = new Int32[4] { 1, 2, 3, 4}; jaggedArray [2] = new Int32[6] { 2, 3, 4, 5, 6, 7}; jaggedArray [3] = new Int32[8] { 3, 4, 5, 6, 7, 8, 9, 10}; jaggedArray [4] = new Int32[10] { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; Byte [] binary = jaggedArray.ToBinary <Int32[][]> (); Int32[][] result = binary.FromBinary <Int32[][]> (); for (Int32 i = 0; i < jaggedArray.Length; ++i) { for (Int32 j = 0; j < jaggedArray [i].Length; ++j) { Assert.That (jaggedArray [i][j] == result [i][j]); } } }