/* Look for segments in samples in the sample queue matching the data in ptr. Samples not matching are removed from the queue. If a match is found, the next time it will look for matches starting from the end of the previous matched segment. */
static int find_sample_match(const uint8_t *data, int len, HintSampleQueue *queue, int *pos, int *match_sample, int *match_offset, int *match_len)
/* Look for segments in samples in the sample queue matching the data in ptr. Samples not matching are removed from the queue. If a match is found, the next time it will look for matches starting from the end of the previous matched segment. */
static int find_sample_match(const uint8_t *data, int len, HintSampleQueue *queue, int *pos, int *match_sample, int *match_offset, int *match_len)
{
    while (queue->len > 0) {
        HintSample *sample = &queue->samples[0];
        if (sample->offset == 0 && sample->size > 5)
            sample->offset = 5;
        if (match_segments(data, len, sample->data, sample->offset,
                           sample->size, pos, match_offset, match_len) == 0) {
            *match_sample = sample->sample_number;
            sample->offset = *match_offset + *match_len + 5;
            if (sample->offset + 10 >= sample->size)
                sample_queue_pop(queue);
            return 0;
        }
        if (sample->offset < 10 && sample->size > 20) {
            sample->offset = sample->size/2;
        } else {
            sample_queue_pop(queue);
        }
    }
    return -1;
}