//------------------------------------------------------------------------------
int pop(Workers& workers) { 
    assert(workers.size() > 0);
    std::set< worker_info >::iterator back = --workers.end();
    const int ret = back->id();
    workers.erase(back);
    return ret;
}
//------------------------------------------------------------------------------
//if worker already present remove it and re-insert it in the right
//position
void push(Workers& workers, int id) {

    Workers::iterator it = std::find_if(workers.begin(),
                               workers.end(),
                               [id](const worker_info& wi){
                                   return wi.id() == id;
                               });
    if(it != workers.end()) workers.erase(it);
    
    workers.insert(worker_info(id));
}
//------------------------------------------------------------------------------
//elements are ordered from highest to lowest
//1) find the first element which has a time > expiration time
//2) remove all elements from that element to last element is set
void purge(Workers& workers, const duration& cutoff) {
    typedef Workers::iterator WI;
    WI start =  std::find_if(
                    workers.begin(),
                    workers.end(),
                    [&cutoff](const worker_info& wi) { 
                    return 
                        std::chrono::duration_cast<std::chrono::milliseconds>(
                            std::chrono::steady_clock::now()
                            - wi.timestamp()
                            ) > cutoff;
                        });
    if(start == workers.end()) return;
    workers.erase(start, workers.end());
               
}