public void MethodTestListMemory()
        {
            List <IndiceHashData> listaHashData = new List <IndiceHashData>();

            listaHashData.Clear();
            for (int i = 0; i < 1000; i++)
            {
                IndiceHashData ihashd = new IndiceHashData();
                ihashd.hash      = i;
                ihashd.enderecos = new List <long>();
                listaHashData.Add(ihashd);
            }

            string data1 = "22/12/2019";

            data1 = data1.Substring(0, 2) + data1.Substring(3, 2);
            int hashResult1 = int.Parse(data1) % 1000;
            var ihd1        = listaHashData.Where(x => x.hash == hashResult1).FirstOrDefault();

            ihd1.enderecos.Add(1000);

            string data2 = "23/12/2019";

            data2 = data2.Substring(0, 2) + data2.Substring(3, 2);
            int hashResult2 = int.Parse(data2) % 1000;
            var ihd2        = listaHashData.Where(x => x.hash == hashResult2).FirstOrDefault();

            ihd2.enderecos.Add(1100);

            string data3 = "22/12/2019";

            data3 = data3.Substring(0, 2) + data3.Substring(3, 2);
            int hashResult3 = int.Parse(data3) % 1000;
            var ihd3        = listaHashData.Where(x => x.hash == hashResult3).FirstOrDefault();

            ihd3.enderecos.Add(1200);

            string data       = "2212";
            int    hashResult = int.Parse(data) % 1000;
            var    ihd        = listaHashData.Where(x => x.hash == hashResult).FirstOrDefault();

            CollectionAssert.AreEqual(ihd.enderecos, new List <long>()
            {
                1000, 1200
            });
        }
Beispiel #2
0
        private void CarregarIndiceHashData()
        {
            Console.Clear();
            Console.WriteLine("Carregando. Aguarde...");
            listaHashData.Clear();
            for (int i = 0; i < 1000; i++)
            {
                IndiceHashData ihd = new IndiceHashData();
                ihd.hash      = i;
                ihd.enderecos = new List <long>();
                listaHashData.Add(ihd);
            }

            try
            {
                using (FileStream readStream = new FileStream(strNameFile, FileMode.Open))
                {
                    while (readStream.Position < readStream.Length)
                    {
                        if (readStream.Position > 0)
                        {
                            readStream.Position += 1;
                        }
                        long posicao = readStream.Position;

                        BinarySearchAlgorithm bsa = new BinarySearchAlgorithm();
                        StrFile oReturn           = bsa.GetFileValue <StrFile>(readStream);
                        string  data = oReturn.Data.Trim() + "9";
                        data = data.Substring(0, 2) + data.Substring(3, 2);
                        int hashResult = int.Parse(data) % 1000;
                        var ihd        = listaHashData.Where(x => x.hash == hashResult).FirstOrDefault();
                        ihd.enderecos.Add(posicao);
                    }
                }

                Console.WriteLine("Pressione uma tecla para continuar.");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }