Skip to content

Fix bug with lost values on bounds and little optimization#37

Merged
yannrichet merged 1 commit intoyannrichet:masterfrom
maxkrivich:master
Oct 13, 2017
Merged

Fix bug with lost values on bounds and little optimization#37
yannrichet merged 1 commit intoyannrichet:masterfrom
maxkrivich:master

Conversation

@maxkrivich
Copy link
Copy Markdown
Contributor

Problem code

for (int i = 0; i < values.length; i++) {
for (int j = 0; j < h.length; j++) {
if (((bounds[j + 1] - values[i]) * (bounds[j] - values[i]) < 0) || ((bounds[j] == values[i])))
h[j]++;
}
}

Description of the bug

Sometimes happens what some values just losing on distribution intervals.

Optimization

Obviously, one value cannot contain several different boundaries. That's why after that we have to break out the inner cycle.

Proposed solution

for (int i = 0; i < values.length; i++) {
	for (int j = 0; j < h.length; j++) {
		if (((bounds[j + 1] - values[i]) * (bounds[j] - values[i]) <= 0) || ((bounds[j] == values[i])))
			h[j]++;
			break;
	}
}

@yannrichet yannrichet merged commit 0e0d2d9 into yannrichet:master Oct 13, 2017
@maxkrivich
Copy link
Copy Markdown
Contributor Author

maxkrivich commented Oct 13, 2017

@yannrichet forget add brackets for if block. My bad =(

@maxkrivich
Copy link
Copy Markdown
Contributor Author

Here you can find original solution https://gist.github.com/maxkrivich/925c8e5aa3853a6766459cad0f6f9fb7

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

Successfully merging this pull request may close these issues.

2 participants