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

fix: remove items from index implementations grid and tree (regression) #357

Merged
merged 2 commits into from
Oct 23, 2023

Conversation

kschrab
Copy link
Contributor

@kschrab kschrab commented Oct 20, 2023

Description

  • When storing VehicleObject items in the Grid or QuadTree, they were stored as a key within a HashMap. When doing so, the hashCode of the object is used to store it in the map. However, when updating the object (e.g. adjusting its speed value), the object cannot be found anymore since its hashCode has changed and differs from the one stored in the map. This resulted in odd behavior and VehicleObjects could not be removed from the Grid or QuadTree and were therefore returned by the perception module,
  • With this PR the behavior is fixed. Now, internal maps in Grid and QuadTree do not store the VehicleObject items as a key for HashMaps, but only their hash value. This hash value is furthermore generated by the SpatialItemAdapter. The adapter implementation responsible for the VehicleObject now returns only the hashcode of its id which is immutable. This refactoring required in the Grid implementation a new wrapper class ItemKey to be used as a key for the internal HashMap, since direct access to the stored item was required.

Issue(s) related to this PR

  • Resolves internal issue 708

Affected parts of the online documentation

Changes in the documentation required?

Definition of Done

Prerequisites

  • You have read CONTRIBUTING.md carefully.
  • You have signed the Contributor License Agreement.
  • Your GitHub user id is linked with your Eclipse Account.

Required

  • The title of this merge request follows the scheme type(scope): description (in the style of Conventional Commits)
  • You have assigned a suitable label to this pull request (e.g., enhancement, or bugfix)
  • origin/main has been merged into your Fork.
  • Coding guidelines have been followed (see CONTRIBUTING.md).
  • All checks on GitHub pass.
  • All tests on Jenkins pass.

Requested (can be enforced by maintainers)

  • New functionality is covered by unit tests or integration tests. Code coverage must not decrease.
  • If a bug has been fixed, a new unit test has been written (beforehand) to prove misbehavior
  • There are no new SpotBugs warnings.

Special notes to reviewer

@kschrab kschrab added bugfix Pull requests that fixes a bug hacktoberfest-accepted labels Oct 20, 2023
@kschrab kschrab requested a review from schwepmo October 20, 2023 14:20
});
}
}

public void removeItem(T item) {
synchronized (tmpIndexA) {
CellIndex cellIndex = items.remove(item);
CellIndex cellIndex = items.remove(new ItemKey<>(adapter.getItemHash(item), item));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a little bit dirty? We have to instantiate a new ItemKey whenever we want to remove an item. 🤷 Also this is a duplicate of line 122. Maybe we can somewhat hide it by adding a method with the structure ItemKey<T> getKeyForItem(T Item)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't like either but I could not think of a better way. Performance/memory wise it should be okay to create this object just for removing the item. I followed your suggestions regarding hiding the instantiation.

@schwepmo
Copy link
Contributor

LGTM! Any reason you haven't checked any of the task boxes?

@schwepmo schwepmo closed this Oct 23, 2023
@schwepmo schwepmo reopened this Oct 23, 2023
@schwepmo schwepmo merged commit 1999ffd into main Oct 23, 2023
2 checks passed
@schwepmo schwepmo deleted the 708-remove-items-from-index branch October 23, 2023 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Pull requests that fixes a bug hacktoberfest-accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants