public void NumberListColumn_NullableCases() { // StringColumns are extremely common in object models, // so having very compact representations for common cases // is really important to file size for small databases. GenericNumberListColumn <int> column = new GenericNumberListColumn <int>(Nullability.DefaultToNull); TreeDiagnostics diagnostics; // Empty: { } diagnostics = TreeSerializer.Diagnostics(column, TreeFormat.Binary); Assert.True(diagnostics.Length <= 2); // All null: { IsNull: { Count: 100, Capacity: 100 } } for (int i = 0; i < 100; ++i) { column[i] = null; } CollectionReadVerifier.VerifySame(column, TreeSerializer.RoundTrip(column, TreeFormat.Binary, testDoubleDispose: false)); diagnostics = TreeSerializer.Diagnostics(column, TreeFormat.Binary); Assert.True(1 == diagnostics.Children.Count); Assert.True(diagnostics.Length <= 13); // All empty: Only nulls false written List <int> empty = new List <int>(); for (int i = 0; i < 100; ++i) { column[i] = empty; } CollectionReadVerifier.VerifySame(column, TreeSerializer.RoundTrip(column, TreeFormat.Binary, testDoubleDispose: false)); diagnostics = TreeSerializer.Diagnostics(column, TreeFormat.Binary); Assert.True(1 == diagnostics.Children.Count); Assert.True(diagnostics.Length <= 13); // No nulls, No Empty: 4b + 2.125b / value (613b) + 4 pages x 4b (16b) + overhead (~10b) List <int> single = new List <int>(); single.Add(1); for (int i = 0; i < 100; ++i) { column[i] = single; } CollectionReadVerifier.VerifySame(column, TreeSerializer.RoundTrip(column, TreeFormat.Binary, testDoubleDispose: false)); diagnostics = TreeSerializer.Diagnostics(column, TreeFormat.Binary); Assert.True(1 == diagnostics.Children.Count); Assert.True(diagnostics.Length <= 640); // Nulls and Non-Nulls; both parts must be written column[50] = null; CollectionReadVerifier.VerifySame(column, TreeSerializer.RoundTrip(column, TreeFormat.Binary, testDoubleDispose: false)); diagnostics = TreeSerializer.Diagnostics(column, TreeFormat.Binary); Assert.True(2 == diagnostics.Children.Count); Assert.True(diagnostics.Length <= 670); }
public void GenericNumberListColumn_Basics() { List <int> empty = new List <int>(); GenericNumberListColumn <int> column = new GenericNumberListColumn <int>(); column[0] = new int[] { 0, 1, 2 }; TreeDiagnostics diagnostics = TreeSerializer.Diagnostics(column, TreeFormat.Binary); int tinyColumnLength = (int)diagnostics.Length; Column.Basics(() => new GenericNumberListColumn <int>(), null, column[0], (index) => { IList <int> values = column[index]; if (values == null || values.Count == 0) { column[index] = new int[] { index, index + 1, index + 2 }; values = column[index]; } return(values); }); // ForEach column.Clear(); column[0] = new int[] { 0, 1, 2 }; int sum = 0; column.ForEach((slice) => { int[] array = slice.Array; int end = slice.Index + slice.Count; for (int i = slice.Index; i < end; ++i) { sum += array[i]; } }); Assert.Equal(3, sum); }