-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add cost stamps #1745
base: master
Are you sure you want to change the base?
Add cost stamps #1745
Conversation
Co-authored-by: jere8184 <[email protected]>
/** | ||
* Cost stamp vector. | ||
*/ | ||
std::vector<std::optional<cost_stamp_t>> cost_stamps; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to make sure cost_stamps
is initialised in the constructor with the correct size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good so far.
In addition to the fixes to the comments I made, you should also add unit tests for stamping and unstamping the cost field in tests.cpp
.
this->cost_stamps[idx]->original_cost = original_cost; | ||
this->cost_stamps[idx]->stamp_time = stamped_at; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this code will work, i.e. it could segfault because the optional value is not initialized. You have to explicitely assign it a cost_stamp_t
struct before you can access the members directly. So you have to write something like
this->cost_stamps[idx] = cost_stamp_t{
orginal_cost,
stamped_at,
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Learning the ropes of c++ here.
* @param cost Cost to set. | ||
* @param stamped_at Time at which the cost cell is to be stamped. | ||
* | ||
* @return True if the cell was successfully stamped, false if the cell was already stamped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the benefit over overwriting the stamp? I'm just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I was considering what would happen if one stamp was placed, and then if another stamp was placed while the first was active. If the stamp is overwritten, how do we communicate with the object that placed the first stamp? If that first object unstamps, it would unstamp the second object's stamp value. If instead we tell the second object that there is already a stamp in place there, we avoid data miscommunication. The downside is that we can't double-stamp, but that would be the downside with stamp overwriting as well.
Co-authored-by: Christoph Heine <[email protected]>
Co-authored-by: Christoph Heine <[email protected]>
fixes #1676.