Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] UpdateMaxCounts can contaminate the sorted state #7

Open
Validark opened this issue Jun 13, 2021 · 1 comment
Open

[BUG] UpdateMaxCounts can contaminate the sorted state #7

Validark opened this issue Jun 13, 2021 · 1 comment

Comments

@Validark
Copy link

Validark commented Jun 13, 2021

The UpdateMaxCounts function updates the termFrequencyCountChildMax field, which is also the field by which the Node.Children Lists are sorted. Since the sort call comes before the UpdateMaxCounts call in the following code, each layer is not actually guaranteed to be in sorted order.

else
{
curr.Children.Add((term, new Node(termFrequencyCount)));
//sort children descending by termFrequencyCountChildMax to start lookup with most promising branch
curr.Children.Sort((x, y) => y.Item2.termFrequencyCountChildMax.CompareTo(x.Item2.termFrequencyCountChildMax));
}
termCount++;
UpdateMaxCounts(nodeList, termFrequencyCount);
}
catch (Exception e) { Console.WriteLine("exception: " + term + " " + e.Message); }
}

And there is no sort call after this UpdateMaxCounts:

if ((common == term.Length) && (common == key.Length))
{
if (node.termFrequencyCount == 0) termCount++;
node.termFrequencyCount += termFrequencyCount;
UpdateMaxCounts(nodeList, node.termFrequencyCount);
}

In practice, this can subtly worsen performance.

Also, because UpdateMaxCounts updates termFrequencyCountChildMax in potentially all ancestor nodes, those layers would need to be sorted as well if every layer is supposed to maintain sorted order.

@wolfgarbe
Copy link
Owner

Thanks. I will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants