Skip to content

Commit ec139f7

Browse files
committed
fixup! fix: rt_api history
1 parent 2b4c8d6 commit ec139f7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

api/dsr_rt_api.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,16 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, const std::vector<fl
200200

201201
auto timestamp_index = 0;
202202
int index = 0;
203+
bool update_index = true;
203204
if (timestamp.has_value()) {
204205
std::vector<int64_t> diffs;
205206
std::transform(time_stamps.begin(), time_stamps.end(), std::back_inserter(diffs),
206207
[t = *timestamp](auto &val) {
207208
return ((int64_t)t - (int64_t)val > 0) ? ((int64_t)t - (int64_t)val) : std::numeric_limits<int64_t>::min();
208209
});
209-
210+
210211
auto pos = (((std::min_element(diffs.begin(), diffs.end())) - diffs.begin())) % HISTORY_SIZE;
211-
212+
212213
if (!head_o.has_value()) {
213214
timestamp_index = 0;
214215
} else {
@@ -221,6 +222,7 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, const std::vector<fl
221222
if (pos == timestamp_index && *timestamp < time_stamps[pos]) {return;}
222223
if (pos > timestamp_index) {
223224
pos = timestamp_index;
225+
update_index = false;
224226
}
225227

226228
time_stamps.erase(time_stamps.begin() + timestamp_index);
@@ -234,7 +236,6 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, const std::vector<fl
234236
rot_pack.insert(rot_pack.begin() + pos*BLOCK_SIZE + 1, rot_euler[1]);
235237
rot_pack.insert(rot_pack.begin() + pos*BLOCK_SIZE + 2, rot_euler[2]);
236238
time_stamps.insert(time_stamps.begin() + pos, *timestamp);
237-
238239

239240
} else {
240241
if (!head_o.has_value()) {
@@ -264,8 +265,10 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, const std::vector<fl
264265
it->second.write(std::move(rot));
265266
std::tie(it, new_el) = e.attrs().insert_or_assign("rt_translation", mvreg<CRDTAttribute> ());
266267
it->second.write(std::move(tr));
267-
std::tie(it, new_el) = e.attrs().insert_or_assign("rt_head_index", mvreg<CRDTAttribute> ());
268-
it->second.write(std::move(head_index));
268+
if (update_index) {
269+
std::tie(it, new_el) = e.attrs().insert_or_assign("rt_head_index", mvreg<CRDTAttribute> ());
270+
it->second.write(std::move(head_index));
271+
}
269272
std::tie(it, new_el) = e.attrs().insert_or_assign("rt_timestamps", mvreg<CRDTAttribute> ());
270273
it->second.write(std::move(timestamps));
271274
}
@@ -396,8 +399,7 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, std::vector<float> &
396399
});
397400

398401
auto pos = (((std::min_element(diffs.begin(), diffs.end())) - diffs.begin())) % HISTORY_SIZE;
399-
400-
402+
401403
if (!head_o.has_value()) {
402404
timestamp_index = 0;
403405
} else {
@@ -422,7 +424,6 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, std::vector<float> &
422424
rot_pack.insert(rot_pack.begin() + pos*BLOCK_SIZE + 1, rot_euler[1]);
423425
rot_pack.insert(rot_pack.begin() + pos*BLOCK_SIZE + 2, rot_euler[2]);
424426
time_stamps.insert(time_stamps.begin() + pos, *timestamp);
425-
426427

427428
} else {
428429
if (!head_o.has_value()) {

0 commit comments

Comments
 (0)