Skip to content
cpp
int getRange(std::string& key, std::vector<double>& res, 
                uint64_t start, uint64_t end)
{
    res.clear(); // 清空 res
    
    // lambda 表达式中 第一个参数为比较值 start, 第二个参数来自迭代器 (*iter);
    // 第一个 timestamp >= start 的 迭代器
    auto first = std::lower_bound(_metBuf[key].begin(), _metBuf[key].end(), start, 
        [&](const metData &data, const int &ts){
        return ts < data.timestamp;
    });
    
    // 第一个 timestamp > end 的 迭代器
    auto last = std::upper_bound(_metBuf[key].begin(), _metBuf[key].end(), end, 
        [&](const metData &data, const int &ts){
        return ts < data.timestamp;
    });
    
    // 解析赋值
    // ...
    
    return res.size();
}

基于 VitePress 构建