Skip to content

NUM_ELEMENTS optimization for apultra_optimize_forward #21

@ghost

Description

my optimization

int NUM_ELEMENTS = 0;

// Get a pointer to an array
apultra_arrival** pDestSlotsPtr = &pDestSlots;

// Size of the entire pointer array
size_t arraySize = sizeof(*pDestSlotsPtr);

// Size of one pointer
size_t elemSize = sizeof(*pDestSlotsPtr[0]);

// Calculate the number of elements
NUM_ELEMENTS = arraySize / elemSize;

int left = 0;
int right = NUM_ELEMENTS - 1; // NUM_ELEMENTS - size of the pDestSlots array

while (left <= right) {
    int mid = left + (right - left) / 2;

    if (pDestSlots[mid].cost < nCodingChoiceCost) {
        left = mid + 1;
    }
    else {
        right = mid - 1;
    }
}

int n = left; // found index

after this code

   if (nCodingChoiceCost < pDestSlots[nArrivalsPerPosition - 1].cost ||
      (nCodingChoiceCost == pDestSlots[nArrivalsPerPosition - 1].cost && nScore < pDestSlots[nArrivalsPerPosition - 1].score &&
         nRepOffset != pDestSlots[nArrivalsPerPosition - 1].rep_offset)) {
      int exists = 0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions