public void BasicTest()
        {
            DualKeyDictionary<int, string, string> dictionary = new DualKeyDictionary<int, string, string>();

            // Adding "Zero" to dictionary with primary int key of 0
            dictionary.Add(0, "Zero");
            Assert.AreEqual(1, dictionary.Count);

            // Associating binary sub-key of "0000" with primary int key of 0
            dictionary.Associate("0000", 0);

            // Adding "Three" to dictionary with primary int key of 3 and a binary sub-key of "0011"
            dictionary.Add(3, "0011", "Three");
            Assert.AreEqual(2, dictionary.Count);

            // Getting value for binary sub-key "0000"
            string value = dictionary["0000"]; // value will be "Zero"
            Assert.AreEqual("Zero", value);

            // Getting value for binary sub-key "0011"
            value = dictionary["0011"]; // value will be "Three"
            Assert.AreEqual("Three", value);

            // Getting value for int primary key 3
            value = dictionary[3]; // value will be "Three"
            Assert.AreEqual("Three", value);
        }
        public void BasicTest()
        {
            DualKeyDictionary <int, string, string> dictionary = new DualKeyDictionary <int, string, string>();

            // Adding "Zero" to dictionary with primary int key of 0
            dictionary.Add(0, "Zero");
            Assert.AreEqual(1, dictionary.Count);

            // Associating binary sub-key of "0000" with primary int key of 0
            dictionary.Associate("0000", 0);

            // Adding "Three" to dictionary with primary int key of 3 and a binary sub-key of "0011"
            dictionary.Add(3, "0011", "Three");
            Assert.AreEqual(2, dictionary.Count);

            // Getting value for binary sub-key "0000"
            string value = dictionary["0000"]; // value will be "Zero"

            Assert.AreEqual("Zero", value);

            // Getting value for binary sub-key "0011"
            value = dictionary["0011"]; // value will be "Three"
            Assert.AreEqual("Three", value);

            // Getting value for int primary key 3
            value = dictionary[3]; // value will be "Three"
            Assert.AreEqual("Three", value);
        }
Example #3
0
        public static void TestAdd()
        {
            DualKeyDictionary <int, int, string> dict = new DualKeyDictionary <int, int, string>();

            dict.Add(0, 0, "0,0");
            dict.Add(0, 1, "0,1");
            dict.Add(1, 0, "1,0");
            dict.Add(1, 1, "1,1");

            Assert.AreEqual(dict.Count, 4);
            Assert.IsTrue(dict.ContainsKey(1, 1));
            Assert.AreEqual(dict[1, 1], "1,1");
        }
Example #4
0
        /// <summary>
        ///     Given a DualKeyDictionary with a key pair of type ( <typeparamref name="T1" />,
        ///     <typeparamref name="T2"></typeparamref>), which maps to a value that is an enumeration over elements of type
        ///     <typeparamref name="T4" />, return true iff there is an key entry consisting of the pair (
        ///     <paramref name="keyPart1" />, <paramref name="keyPart2" />) that has a non-null and non-empty key.
        /// </summary>
        /// <typeparam name="T1">The type of the first element of the paired key</typeparam>
        /// <typeparam name="T2">The type of the second element of the paired key.</typeparam>
        /// <typeparam name="T3">The type of the enumeration that is the value of the dictionary.</typeparam>
        /// <typeparam name="T4">The type of the elements inside the enumeration value.</typeparam>
        /// <param name="dict">The dual-key dictionary that we're checking for a key pair (with a nonempty and nonnull value)</param>
        /// <param name="keyPart1">The first item of the paired key.</param>
        /// <param name="keyPart2">The second item of the paired key.</param>
        /// <returns>
        ///     true iff there is an key entry consisting of the pair ( <paramref name="keyPart1" />,
        ///     <paramref name="keyPart2" />) that has a non-null and non-empty key.
        /// </returns>
        public static bool ContainsKeyNonEmptyNotNullValue <T1, T2, T3, T4>(this DualKeyDictionary <T1, T2, T3> dict,
                                                                            T1 keyPart1, T2 keyPart2) where T3 : HashSet <T4>
        {
            // Return false if the key doesn't exist.
            if (!dict.ContainsKey(keyPart1, keyPart2))
            {
                return(false);
            }

            // Return a value associated not just with checking if the value <keyPart1, keyPart2> is
            // in the Dictionary, and that its value is non-null and non-empty.
            T3 dictValue = dict[keyPart1, keyPart2];

            return(dictValue != null && !dictValue.IsEmpty());
        }
    private static void Main()
    {
        DualKeyDictionary<int, string, string> dictionary = new DualKeyDictionary<int, string, string>();

        // Adding "Zero" to dictionary with primary int key of 0
        dictionary.Add(0, "Zero");
        // Associating binary sub-key of "0000" with primary int key of 0
        dictionary.Associate("0000", 0);

        // Adding "Three" to dictionary with primary int key of 3 and a binary sub-key of "0011"
        dictionary.Add(3, "0011", "Three");

        // Getting value for binary sub-key "0000"
        string value = dictionary["0000"]; // value will be "Zero"
        Console.WriteLine(value);
        // Getting value for int primary key 0
        value = dictionary[0]; // val will be "Zero"
        Console.WriteLine(value);
    }
Example #6
0
    private static void Main()
    {
        DualKeyDictionary <int, string, string> dictionary = new DualKeyDictionary <int, string, string>();

        // Adding "Zero" to dictionary with primary int key of 0
        dictionary.Add(0, "Zero");
        // Associating binary sub-key of "0000" with primary int key of 0
        dictionary.Associate("0000", 0);

        // Adding "Three" to dictionary with primary int key of 3 and a binary sub-key of "0011"
        dictionary.Add(3, "0011", "Three");

        // Getting value for binary sub-key "0000"
        string value = dictionary["0000"]; // value will be "Zero"

        Console.WriteLine(value);
        // Getting value for int primary key 0
        value = dictionary[0]; // val will be "Zero"
        Console.WriteLine(value);
    }
Example #7
0
        void ClearGrid()
        {
            cellPosDictionary = new DualKeyDictionary<int, int, UIElement>();
            headerPosDictionary = new DualKeyDictionary<int,int, UIElement>();

            gridHeader.Children.Clear();
            gridHeader.ColumnDefinitions.Clear();

            grid.Children.Clear();
            grid.ColumnDefinitions.Clear();
            grid.RowDefinitions.Clear();
        }