Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                return;
            }
            if (eHTG.validator(textBox2.Text) == 1)
            {
                return;
            }
            foreach (string s in eht.array)
            {
                if (s == textBox2.Text)
                {
                    MessageBox.Show("Такая запись уже содержится в справочнике", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            if (eht.mapSize == 0)
            {
                eht  = new experimetalHashTable(Convert.ToInt32(this.textBox7.Text));
                eHTG = new experimentalHTGuben(Convert.ToInt32(this.textBox7.Text));
            }
            eht.pushBackArray(textBox2.Text);
            eHTG.pushBackArray(textBox2.Text);
            Tuple <int, string, int> x = eht.calcHashAndInsertion(textBox2.Text, eht.arraySize - 1, dataGridView1, ins);

            textBox8.Text = x.Item1.ToString();
            eHTG.addHashTable(textBox2.Text, dataGridView2);
            if (x.Item2 != "")
            {
                textBox3.Text = "было";
            }
            else
            {
                textBox3.Text = "не было";
            }
        }
Пример #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            usedCreate = 1;
            if (Convert.ToInt32(this.textBox6.Text) > Convert.ToInt32(this.textBox7.Text))
            {
                MessageBox.Show("Число записей не может быть больше размера хеш-таблицы", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            this.dataGridView1.Rows.Clear();
            this.dataGridView2.Rows.Clear();
            ins = 0;

            if (eht.mapSize == 0)
            {
                eht  = new experimetalHashTable(Convert.ToInt32(this.textBox7.Text));
                eHTG = new experimentalHTGuben(Convert.ToInt32(this.textBox7.Text));
            }

            if (eht.mapSize != 0)
            {
                eht  = new experimetalHashTable(Convert.ToInt32(this.textBox7.Text));
                eHTG = new experimentalHTGuben(Convert.ToInt32(this.textBox7.Text));
            }

            if (textBox5.Text != "")
            {
                eHTG.constanta = Convert.ToDouble(textBox5.Text);
            }

            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                path = ofd.FileName;
                StreamReader sr       = new StreamReader(ofd.FileName);
                string       fromFile = "";
                while (fromFile != null)
                {
                    if (eht.arraySize == 251)
                    {
                        break;
                    }
                    fromFile = sr.ReadLine();
                    if (fromFile == null)
                    {
                        break;
                    }
                    eht.pushBackArray(fromFile);
                    eHTG.pushBackArray(fromFile);
                }
                sr.Close();
                using (sr = new StreamReader(ofd.FileName))
                {
                    for (int i = 0; i < Convert.ToInt32(this.textBox6.Text); i++)
                    {
                        fromFile = sr.ReadLine();
                        if (fromFile == null)
                        {
                            MessageBox.Show("Число записей в справочнике меньше заданного числа для эксперимента\n" +
                                            "Проведён эксперимент для " + i + " записей", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        Tuple <int, string, int> y = eht.calcHashAndInsertion(eht.array[i], i, dataGridView1, ins);
                        if (y.Item2 != "")
                        {
                            textBox3.Text = "было";
                        }
                        if (y.Item2 != "")
                        {
                            textBox3.Text = "было";
                        }
                        eHTG.addHashTable(eht.array[i], dataGridView2);
                        ins++;
                    }
                }
                if (textBox3.Text == "")
                {
                    textBox3.Text = "не было";
                }
                sr.Close();
            }
        }