basic_functions.cpp 1.59 KB
Newer Older
limingbo's avatar
limingbo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include "basic_functions.h"

int8_t checkTime(const double &time, const Time_Duration &timeDuration){
    if(time < timeDuration.start_sec){
        return -1;
    }else if(time < timeDuration.end_sec){
        return 1;
    }else {
        return -2;
    }
}

int8_t checkTime(const double &time, const vector<Time_Duration> &timeDurations){
    bool has_before = false, has_after = false;
    for(const auto &durations : timeDurations){
        int8_t ret = checkTime(time, durations);
        if(ret == -1){
            has_before = true;
        }else if(ret == -2){
            has_after = true;
        }else if(ret == 1){
            return 1;
        }
    }
    if(has_after && !has_before){
        return -2;
    }else if(has_before && !has_after){
        return -1;
    }
}

vector<pair<uint32_t, uint32_t>> getIndexPeriod(const uint32_t size,
                                                const uint8_t threadCnt)
{
    vector<pair<uint32_t, uint32_t>> ret;
    uint32_t whole_frame_cnt = size;
    uint32_t min_frame_cnt = whole_frame_cnt / threadCnt;
    uint32_t max_frame_cnt = min_frame_cnt + 1;
    uint8_t max_divide_cnt = whole_frame_cnt % threadCnt;
    uint32_t start_index = 0, last_item_cnt = 0;
    for(uint8_t thread_index = 0; thread_index < threadCnt; thread_index++){
        uint32_t item_cnt;
        if(thread_index < max_divide_cnt){
            item_cnt = max_frame_cnt;
        }else{
            item_cnt = min_frame_cnt;
        }
        start_index += last_item_cnt;
        ret.push_back(make_pair(start_index, item_cnt));
        last_item_cnt = item_cnt;
    }
    return ret;
}