Example #1
0
        public IndexDynamicTest()
        {
            var uniqPath = Path+DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace(":"," ")+ DateTime.Now.Second.ToString()+ @"/";

            Directory.CreateDirectory(uniqPath);
            tableView = new TableView(uniqPath+ "table", TpTableElement);

            tableView.Fill(Enumerable.Range(0, NumberOfRecords).Select(i =>
                (object) (new object[] {i.ToString(), i })));
            // Делаем индекс
            var ha = new IndexHalfkeyImmutable<string>(uniqPath + "dyna_index_str_half")
            {
                Table = tableView,
                KeyProducer = va => (string) ((object[]) (((object[]) va)[1]))[0],
                HalfProducer = k => k.GetHashModifiedBernstein()
            };
            ha.Scale = new ScaleCell(uniqPath + "dyna_index_str_half") {IndexCell = ha.IndexCell};
            ha.Build();
            sIndex = new IndexDynamic<string, IndexHalfkeyImmutable<string>>(true)
            {
                Table = tableView,
                KeyProducer = va => (string) ((object[]) (((object[]) va)[1]))[0],
                IndexArray = ha
            };
            iIndex = new IndexDynamic<int, IIndexImmutable<int>>(true,
                new IndexKeyImmutable<int>(uniqPath + "int", tableView,
                    va => (int) ((object[]) (((object[]) va)[1]))[1],
                    new ScaleCell(uniqPath + "iisndexScale")));

            iIndex.Build();
        }
Example #2
0
        public static void Main7()
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            string path = "../../../Databases/";
            int NumberOfRecords = 100000000;
            Random rnd = new Random();
            Console.WriteLine("Start Universal Index. Main7()");

            PType tp_table_element = new PTypeRecord(
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("age", new PType(PTypeEnumeration.integer)));
            TableView table = new TableView(path + "table", tp_table_element);
            sw.Restart();
            bool tobuild = false;
            if (tobuild)
            {
                table.Fill(Enumerable.Range(0, NumberOfRecords).Select(i =>
                    (object)(new object[] { i.ToString(), i == NumberOfRecords / 2 ? -1 : i })));
                sw.Stop();
                Console.WriteLine("Load Table of {0} elements ok. Duration {1}", NumberOfRecords, sw.ElapsedMilliseconds);
            }
            else table.Warmup();
            sw.Restart();
            // Делаем индекс
            var ha = new IndexHalfkeyImmutable<string>(path + "dyna_index_str_half")
            {
                Table = table,
                KeyProducer = va => (string)((object[])(((object[])va)[1]))[0],
                HalfProducer = k => k.GetHashCode()
            };
            ha.Scale = new ScaleCell(path + "dyna_index_str_half") { IndexCell = ha.IndexCell };
            bool tobuild_h_index = false;
            if (tobuild_h_index)
            {
                ha.Build();
            }
            else
            {
                ha.Warmup();
                //ha.BuildScale();
            }
            IndexDynamic<string, IndexHalfkeyImmutable<string>> h_index = new IndexDynamic<string, IndexHalfkeyImmutable<string>>(true)
            {
                Table = table,
                KeyProducer = va => (string)((object[])(((object[])va)[1]))[0],
                IndexArray = ha
            };
            Console.WriteLine("h_index Build ok. Duration {0}", sw.ElapsedMilliseconds);
            sw.Restart();
            int cnt = 0;
            for (int i = 0; i < 1000; i++)
            {
                int c = h_index.GetAllByKey(rnd.Next(NumberOfRecords * 3 / 2 - 1).ToString()).Count();
                if (c > 1) Console.WriteLine("Unexpected Error: {0}", c);
                cnt += c;
            }
            sw.Stop();
            Console.WriteLine("1000 GetAllByKey ok. Duration={0} cnt={1}", sw.ElapsedMilliseconds, cnt);
        }