yakra / DataProcessing

Data Processing Scripts and Programs for Travel Mapping Project
0 stars 0 forks source link

segments, waypoints, pointers, functions #241

Open yakra opened 1 year ago

yakra commented 1 year ago

After Waypoints & HighwaySegment objects are stored in sequential memory:


HighwaySegment::waypoint1 and waypoint2 could become functions. Saves a chunk of RAM, but would things run slower?

Waypoint* HighwaySegment::waypoint1()
{   return this - route->segment_list.data() + route->point_list.data();
}

Waypoint* HighwaySegment::waypoint2()
{   return this - route->segment_list.data() + route->point_list.data() + 1;
}

Would functions returning pointers to a Waypoint's adjacent HighwaySegments be useful? Maybe for concurrency detection or concurrency augments?

HighwaySegment* Waypoint::segment1()
{   size_t index = this - route->point_list.data();
    return index ? route->segment_list.data() + index - 1 : 0;
}

HighwaySegment* Waypoint::segment2()
{   size_t index = this - route->point_list.data();
    return index != route->point_list.data() + route->point_list.size() - 1
    ? route->segment_list.data() + index - 1
    : 0;
}