#include "train_locations.h"

// pattern trainLocations(train : Train, location : Segment) {
// 	Train.location(train, location);
// }

// Optimized and original queries are the same

void train_locations_matcher(ModelRoot *model, TrainLocationsFrame *frame,
                             int startOpIndex,
                             TrainLocationsMatchSet *results) {
  int match_cntr = 0;

  int loop_bound0 = model->train_count;
  for (int i0 = 0; i0 < loop_bound0; i0++) {
    frame->train = model->trains[i0];
    frame->location = frame->train->location;
    if (frame->location != NULL) {
      results->matches[match_cntr].location = frame->location;
      results->matches[match_cntr++].train = frame->train;
    }
  }

  results->size = match_cntr;
}
