Esempio n. 1
0
    static void Main()
    {
        var coll = new Dictionary2d <int, int, AnyClass>();

        coll.Add(2, 3, new AnyClass("foo"));
        coll.Add(4, 2, new AnyClass("bar"));

        var foo = coll[2, 3];
        var bar = coll[4, 2];
    }
Esempio n. 2
0
        public void Simple()
        {
            Dictionary2d <string, string, int> d = new Dictionary2d <string, string, int>();

            d["jan", "white"]   = 15;
            d["jan", "black"]   = 3;
            d["mar", "white"]   = 12;
            d["april", "black"] = 13;
            d["april", "black"]++;

            Assert.Equal(4, d.Count);

            Assert.Equal(new string[] { "april", "jan", "mar" }, d.Key1);
            Assert.Equal(new string[] { "black", "white" }, d.Key2);

            Assert.Equal(15, d["jan", "white"]);
            Assert.Equal(3, d["jan", "black"]);
            Assert.Equal(12, d["mar", "white"]);
            Assert.Equal(13 + 1, d["april", "black"]);

            Assert.Equal(0, d["missing", "missing"]);
        }
Esempio n. 3
0
        public void Simple()
        {
            Dictionary2d<string, string, int> d = new Dictionary2d<string, string, int>();

            d["jan", "white"] = 15;
            d["jan", "black"] = 3;
            d["mar", "white"] = 12;
            d["april", "black"] = 13;
            d["april", "black"]++;

            Assert.Equal(4, d.Count);

            Assert.Equal(new string[] { "april", "jan", "mar"}, d.Key1);
            Assert.Equal(new string[] { "black", "white" }, d.Key2);

            Assert.Equal(15, d["jan", "white"]);
            Assert.Equal(3, d["jan", "black"]);
            Assert.Equal(12, d["mar", "white"]);
            Assert.Equal(13 + 1, d["april", "black"]);

            Assert.Equal(0, d["missing", "missing"]);
        }
Esempio n. 4
0
        static void Add(DataTable table, Dictionary2d<string, string, string> dict, ref int counter)
        {
            foreach (var row in table.Rows)
            {
                int i = 0;
                foreach (var name in row.ColumnNames)
                {
                    var value = row.Values[i];

                    dict[counter.ToString(), name] = value;
                    i++;
                }

                counter++;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Merge 2 datatables together assuming no common join key. 
        /// This will collapse common columns, but keep all rows. 
        /// This needs to deal with columns being in different orders        
        /// </summary>
        /// <param name="tables">set of tables to merge together</param>
        /// <returns>a merged table. The rows may be in a random order.</returns>
        public static MutableDataTable Join(IEnumerable<DataTable> tables)
        {
            var dict = new Dictionary2d<string, string, string>();
            int counter = 0;
            foreach (var dt in tables)
            {
                Add(dt, dict, ref counter);
            }

            var merge = DataTable.New.From2dDictionary(dict);

            // remove extra column that Dict2d added, and reorder to more closely match dataset
            var mutable = DataTable.New.GetMutableCopy(merge);

            IEnumerable<string> columnNames = new string[0];
            foreach (var dt in tables)
            {
                columnNames = columnNames.Concat(dt.ColumnNames);
            }
            var names = columnNames.Distinct(StringComparer.OrdinalIgnoreCase);

            var x = names.ToArray();
            mutable.KeepColumns(x);

            return mutable;
        }
Esempio n. 6
0
        static void Add(DataTable table, Dictionary2d<string, string, string> dict, ref int counter)
        {
            var names = (from name in table.ColumnNames select name.ToLowerInvariant()).ToArray();
            foreach (var row in table.Rows)
            {
                int i = 0;
                foreach (var name in names)
                {
                    var value = row.Values[i];

                    dict[counter.ToString(), name] = value;
                    i++;
                }

                counter++;
            }
        }