/// <summary> /// Insert the items in the input into the sorter in a mixed-up order. /// </summary> /// <param name="sorter"></param> /// <param name="input"></param> private void ShuffleInputs(BigDataSorter sorter, SortedDictionary <string, byte[]> input) { // Insert all the even items in oder. for (int i = 0; i < input.Count / 2; i++) { sorter.Add(input.ElementAt(i * 2).Key, input.ElementAt(i * 2).Value); } // And all the odd items in reverse order. for (int i = input.Count - 1; i > 0; i--) { if (i % 2 == 1) { sorter.Add(input.ElementAt(i).Key, input.ElementAt(i).Value); } } }
internal static void SortEntireFile(Dictionary <string, Dictionary <string, HashSet <string> > > sortableProperties, XmlWriter writer, string pathname) { var readerSettings = new XmlReaderSettings { IgnoreWhitespace = true }; // Step 2: Sort and rewrite file. using (var fastSplitter = new FastXmlElementSplitter(pathname)) { var sorter = new BigDataSorter(); bool foundOptionalFirstElement; foreach (var record in fastSplitter.GetSecondLevelElementStrings(OptionalFirstElementTag, StartTag, out foundOptionalFirstElement)) { if (foundOptionalFirstElement) { // Step 2A: Write out custom property declaration(s). WriteElement(writer, SortCustomPropertiesRecord(record)); foundOptionalFirstElement = false; } else { // Step 2B: Sort main CmObject record. var sortedMainObject = SortMainElement(sortableProperties, record); sorter.Add(sortedMainObject.Attribute("guid").Value, Utf8.GetBytes(sortedMainObject.ToString())); } } sorter.WriteResults(val => WriteElement(writer, readerSettings, val)); } }
public void OneItem() { var output = new List <byte[]>(); var sorter = new BigDataSorter(); sorter.Add("a", new byte[] { 1 }); sorter.WriteResults(val => output.Add(val)); Assert.That(output, Has.Count.EqualTo(1)); VerifyByteArray(output[0], new byte[] { 1 }); }