Skip to content

Commit b8394a4

Browse files
committed
use pointer array
1 parent 1c7a0ce commit b8394a4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
214214

215215
// create copy of neighbours list, skipping empty entries so we can sort it separately from main list
216216
int16_t neighbours_count = 0;
217-
NeighbourInfo sorted_neighbours[MAX_NEIGHBOURS];
217+
NeighbourInfo* sorted_neighbours[MAX_NEIGHBOURS];
218218
for (int i = 0; i < MAX_NEIGHBOURS; i++) {
219219
auto neighbour = &neighbours[i];
220220
if (neighbour->heard_timestamp > 0) {
221-
sorted_neighbours[neighbours_count] = *neighbour;
221+
sorted_neighbours[neighbours_count] = neighbour;
222222
neighbours_count++;
223223
}
224224
}
@@ -227,26 +227,26 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
227227
if (order_by == 0) {
228228
// sort by newest to oldest
229229
MESH_DEBUG_PRINTLN("REQ_TYPE_GET_NEIGHBOURS sorting newest to oldest");
230-
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo &a, const NeighbourInfo &b) {
231-
return a.heard_timestamp > b.heard_timestamp; // desc
230+
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo* a, const NeighbourInfo* b) {
231+
return a->heard_timestamp > b->heard_timestamp; // desc
232232
});
233233
} else if (order_by == 1) {
234234
// sort by oldest to newest
235235
MESH_DEBUG_PRINTLN("REQ_TYPE_GET_NEIGHBOURS sorting oldest to newest");
236-
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo &a, const NeighbourInfo &b) {
237-
return a.heard_timestamp < b.heard_timestamp; // asc
236+
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo* a, const NeighbourInfo* b) {
237+
return a->heard_timestamp < b->heard_timestamp; // asc
238238
});
239239
} else if (order_by == 2) {
240240
// sort by strongest to weakest
241241
MESH_DEBUG_PRINTLN("REQ_TYPE_GET_NEIGHBOURS sorting strongest to weakest");
242-
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo &a, const NeighbourInfo &b) {
243-
return a.snr > b.snr; // desc
242+
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo* a, const NeighbourInfo* b) {
243+
return a->snr > b->snr; // desc
244244
});
245245
} else if (order_by == 3) {
246246
// sort by weakest to strongest
247247
MESH_DEBUG_PRINTLN("REQ_TYPE_GET_NEIGHBOURS sorting weakest to strongest");
248-
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo &a, const NeighbourInfo &b) {
249-
return a.snr < b.snr; // asc
248+
std::sort(sorted_neighbours, sorted_neighbours + neighbours_count, [](const NeighbourInfo* a, const NeighbourInfo* b) {
249+
return a->snr < b->snr; // asc
250250
});
251251
}
252252

@@ -264,7 +264,7 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
264264
}
265265

266266
// add next neighbour to results
267-
auto neighbour = &sorted_neighbours[index + offset];
267+
auto neighbour = sorted_neighbours[index + offset];
268268
uint32_t heard_seconds_ago = getRTCClock()->getCurrentTime() - neighbour->heard_timestamp;
269269
memcpy(&results_buffer[results_offset], neighbour->id.pub_key, pubkey_prefix_length); results_offset += pubkey_prefix_length;
270270
memcpy(&results_buffer[results_offset], &heard_seconds_ago, 4); results_offset += 4;

0 commit comments

Comments
 (0)