Example #1
0
 /// <summary>
 /// создает отсортированные по cmp_strings_function ключи для колонки number_of_key 
 /// </summary>
 public void load_key_for_file(int number_of_key)
 {
     current_string_of_file array_of_strings = new current_string_of_file(strings_in_byte, current_file_stream);
     bool was_insert = false;
     for (int counter = 0; counter < strings_in_byte.Count(); ++counter)
     {
             if (all_keys[number_of_key - 1].Count() == 0)
             {
                 all_keys[number_of_key - 1].Add(counter);
             }
             else
             {
                 for (int counter_2 = 0; counter_2 < all_keys[number_of_key - 1].Count(); ++counter_2)
                 {
                     //если cmp_strings_function после сравнения двух строк возращает значение больше 0  
                     if (cmp_strings_function(found_string(counter_2, number_of_key)
                         , create_string_from_index[counter][number_of_key - 1]) > 0)
                     {
                         //вставляем индекс новой строки на место индекса текущей строки
                         all_keys[number_of_key - 1].Insert(counter_2, counter);
                         was_insert = true;
                         break;
                     }
                 }
                 //если функция сравнения ни разу не возвращает значения больше 0
                 if (!was_insert)
                 {
                     //добавляем индекс новой строки в конец списка ключей
                     all_keys[number_of_key - 1].Add(counter);
                 }
                 was_insert = false;
             }
     }
 }
Example #2
0
        /// <summary>
        /// заполняет таблицу позиций конца строк (strings_in_byte) в файле 
        /// </summary>
        public void load_pointers_to_strings()
        {
            int max_size_of_one_string = 1024;
            int current_size_of_string = 0;
            buf_int_for_strings_check_points = 0;
            int count_read_bytes = 1;
            try
            {
                //while количество прочитанных байтов больше 0
                while (count_read_bytes != 0)
                {
                    if (strings_in_byte.Count() > 0)//если читаем не с начала файла
                    {
                        current_file_stream.Seek(strings_in_byte[strings_in_byte.Count() - 1], SeekOrigin.Begin);
                    }
                    else//если читаем с начала файла
                    {
                        current_file_stream.Seek(3, SeekOrigin.Begin);
                    }
                    count_read_bytes = current_file_stream.Read(buf_array, 0, 64000);
                    //заносим в цикле значения окончаний строк (в байтах) от начала файла
                    for (int counter = 0; counter < count_read_bytes; ++counter)
                    {
                        if (buf_array[counter] == 10)
                        {
                            strings_in_byte.Add(buf_int_for_strings_check_points);
                            current_size_of_string = 0;
                        }
                        else
                        {
                            ++current_size_of_string;
                            if (current_size_of_string > max_size_of_one_string)
                            {
                                throw new my_exception("Warning: too long string - byte list incomplete");
                            }
                        }
                        ++buf_int_for_strings_check_points;
                    }
                    //если прочитанный обьем данных меньше буфера значит мы достигли конца файла - завершаем цикл
                    if (count_read_bytes < 64000)
                    {
                        break;
                    }
                }
            }
            catch (my_exception current_exception)
            {
                Console.WriteLine(current_exception.current_exception);
            }

            //создаем обьект класса, который будет возвращать строку по индексу в strings_in_byte
            create_string_from_index = new current_string_of_file(strings_in_byte, current_file_stream);
        }