Understanding Code Question

I went through one code on the network .

I did not understand the following logic. This code works and works very fast.

for (int i = 0; i < typo_word_vec.size(); i++)
{
        float each_typo_word_len = (float)typo_word_vec[i].size();
        int start_range = each_typo_word_len - floor((each_typo_word_len / lower_bound_word_size) * each_typo_word_len) - 1;
        if (start_range < 1)
                start_range = 1;
        int end_range = each_typo_word_len + ceil((each_typo_word_len / upper_bound_word_size) * each_typo_word_len) + 1;
        if (end_range > src_word_max_len)
                end_range = src_word_max_len - 1;

        call_get_dist(i, start_range, end_range);
}  

But I do not understand what the logic of using start_rangeand is end_range. What basic algorithm or theory is used here.

+3
source share
1 answer

You really should have put a few more lines - we definitely need to check all the code to understand something.

As I understand it, the words "source" are ordered by size. The words “candidate” may be shorter or longer than their potential match. This is what start_range and end_range are used for.

Although I find it difficult to understand why the author does not use

start_range = 0;
end_range = src_word_max_len;

EDIT: , ( readme.txt):

pythonand php, , ( ). "cpp" ++, STL, , , ( : ). , , java . : http://www.facebook.com/careers/puzzles.php?puzzle_id=17

, , .

+1

All Articles