<commit_before>﻿//
// Program: BtreeExample03.cs
// Purpose: Demonstrate LINQ usage and range query.
//

using System;
using System.Linq;
using Kaos.Collections;

namespace ExampleApp
{
    class BtreeExample03
    {
        static void Main()
        {
            var towns = new BtreeDictionary<string, int>();

            // Load sample data.
            towns.Add ("Albany", 43600);
            towns.Add ("Bandon", 2960);
            towns.Add ("Corvallis", 54462);
            towns.Add ("Damascus", 10539);
            towns.Add ("Elkton", 195);
            towns.Add ("Florence", 8466);
            towns.Add ("Glide", 1795);
            towns.Add ("Jacksonville", 2235);
            towns.Add ("Lebanon", 13140);
            towns.Add ("Lookingglass", 855);
            towns.Add ("Medford", 75180);
            towns.Add ("Powers", 689);
            towns.Add ("Riddle", 1020);
            towns.Add ("Roseburg", 20480);
            towns.Add ("Scio", 710);
            towns.Add ("Talent", 6066);
            towns.Add ("Umatilla", 6906);
            towns.Add ("Winston", 5379);
            towns.Add ("Yamhill", 820);

            // Here's a typical LINQ-To-Objects operation.
            double avg = towns.Average (x => x.Value);
            Console.WriteLine ("Average population of all towns = {0:f0}", avg);


            // Lambda expression
            var r1 =  towns.Where (t => t.Key.CompareTo ("E") < 0);

            Console.WriteLine ("\nTowns A-D:");
            foreach (var e in r1)
                Console.WriteLine (e.Key);

            // LINQ range: O(n)
            var r2 =  towns.SkipWhile (t => t.Key.CompareTo ("E") < 0).TakeWhile (t => t.Key.CompareTo ("J") < 0);

            Console.WriteLine ("\nTowns E-G:");
            foreach (var e in r2)
                Console.WriteLine (e.Key);

            //
            // Use the BetweenKeys iterator to query range.
            // Unlike LINQ SkipWhile and TakeWhile, this will perform an optimized (partial scan) lookup.
            //

            // BtreeDictionary range operator: O(log n)
            var r3 = towns.BetweenKeys ("K", "M");

            Console.WriteLine ("\nTowns K-L:");
            foreach (var town in r3)
                Console.WriteLine (town.Key);

            // BtreeDictionary range operator without upper limit: O(log n)
            var r4 = towns.SkipUntilKey ("M");

            Console.WriteLine ("\nTowns M-R:");
            foreach (var town in r4)
                // This avoids the issue in the last example where a town named "M" would be included.
                if (town.Key.CompareTo ("S") >= 0)
                    break;
                else
                    Console.WriteLine (town.Key);

            // BtreeDictionary range operator without upper limit: O(log n)
            var r5 = towns.SkipUntilKey ("T");

            Console.WriteLine ("\nTowns T-Z:");
            foreach (var town in r5)
                Console.WriteLine (town.Key);
        }
    }
}<commit_msg>add output, explicit types<commit_after>﻿//
// Program: BtreeExample03.cs
// Purpose: Demonstrate LINQ usage and range query.
//

using System;
using System.Linq;
using System.Collections.Generic;
using Kaos.Collections;

namespace ExampleApp
{
    class BtreeExample03
    {
        static void Main()
        {
            var towns = new BtreeDictionary<string,int>();

            // Load sample data.
            towns.Add ("Albany", 43600);
            towns.Add ("Bandon", 2960);
            towns.Add ("Corvallis", 54462);
            towns.Add ("Damascus", 10539);
            towns.Add ("Elkton", 195);
            towns.Add ("Florence", 8466);
            towns.Add ("Glide", 1795);
            towns.Add ("Jacksonville", 2235);
            towns.Add ("Lebanon", 13140);
            towns.Add ("Lookingglass", 855);
            towns.Add ("Medford", 75180);
            towns.Add ("Powers", 689);
            towns.Add ("Riddle", 1020);
            towns.Add ("Roseburg", 20480);
            towns.Add ("Scio", 710);
            towns.Add ("Talent", 6066);
            towns.Add ("Umatilla", 6906);
            towns.Add ("Winston", 5379);
            towns.Add ("Yamhill", 820);

            // Here's a typical LINQ-To-Objects operation.
            double avg = towns.Average (x => x.Value);
            Console.WriteLine ("Average population of all towns = {0:f0}", avg);

            // Lambda expression
            IEnumerable<KeyValuePair<string,int>> r1 = towns.Where (t => t.Key.CompareTo ("E") < 0);

            Console.WriteLine ("\nTowns A-D:");
            foreach (KeyValuePair<string,int> e in r1)
                Console.WriteLine (e.Key);

            // LINQ range: O(n)
            IEnumerable<KeyValuePair<string,int>> r2 = towns.SkipWhile (t => t.Key.CompareTo ("E") < 0).TakeWhile (t => t.Key.CompareTo ("J") < 0);

            Console.WriteLine ("\nTowns E-G:");
            foreach (KeyValuePair<string,int> e in r2)
                Console.WriteLine (e.Key);

            //
            // Use the BetweenKeys iterator to query range.
            // Unlike LINQ SkipWhile and TakeWhile, this will perform an optimized (partial scan) lookup.
            //

            // BtreeDictionary range operator: O(log n)
            IEnumerable<KeyValuePair<string,int>> r3 = towns.BetweenKeys ("K", "M");

            Console.WriteLine ("\nTowns K-L:");
            foreach (KeyValuePair<string,int> town in r3)
                Console.WriteLine (town.Key);

            // BtreeDictionary range operator without upper limit: O(log n)
            IEnumerable<KeyValuePair<string,int>> r4 = towns.SkipUntilKey ("M");

            Console.WriteLine ("\nTowns M-R:");
            foreach (KeyValuePair<string,int> town in r4)
                // This avoids the issue in the last example where a town named "M" would be included.
                if (town.Key.CompareTo ("S") >= 0)
                    break;
                else
                    Console.WriteLine (town.Key);

            // BtreeDictionary range operator without upper limit: O(log n)
            IEnumerable<KeyValuePair<string,int>> r5 = towns.SkipUntilKey ("T");

            Console.WriteLine ("\nTowns T-Z:");
            foreach (KeyValuePair<string,int> town in r5)
                Console.WriteLine (town.Key);
        }

        /* Output:

        Average population of all towns = 13447

        Towns A-D:
        Albany
        Bandon
        Corvallis
        Damascus

        Towns E-G:
        Elkton
        Florence
        Glide

        Towns K-L:
        Lebanon
        Lookingglass

        Towns M-R:
        Medford
        Powers
        Riddle
        Roseburg

        Towns T-Z:
        Talent
        Umatilla
        Winston
        Yamhill

         */
    }
}
{'fraction_non_alphanumeric': 0.12399001028353165, 'fraction_numerical': 0.0292346114294109, 'mean_word_length': 1.6074301034086558, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2259977', 'n_tokens_mistral': 2130, 'n_tokens_neox': 1928, 'n_words': 548}