Ejemplo n.º 1
0
void MsgBuf::append(MsgBuf::Iterator first, MsgBuf::Iterator last)
{
    MsgBuf::Iterator it = container_.begin();
    MsgBuf::Iterator jt = first;
    KeyComp comp(comp_);

    while(jt != last) {
#ifdef FAST_VECTOR
        it = container_.lower_bound(it, jt->key, comp);
#else
        it = lower_bound(it, container_.end(), jt->key, comp);
#endif
        if (it == container_.end() || it->key != jt->key) {
            // important, it maybe invalid after insertion
            it = container_.insert(it, *jt);
            size_ += jt->size();
        } else {
            size_ -= it->size();
            it->destroy();
            *it = *jt;
            size_ += it->size();
        }
        jt ++;
    }
}
Ejemplo n.º 2
0
void MsgBuf::write(const Msg& msg)
{
#ifdef FAST_VECTOR
    MsgBuf::Iterator it = container_.lower_bound(msg, KeyComp(comp_));
#else
    MsgBuf::Iterator it = lower_bound(container_.begin(), 
        container_.end(), msg, KeyComp(comp_));
#endif
    if (it == end() || it->key != msg.key) {
        container_.insert(it, msg);
        size_ += msg.size();
    } else {
        size_ -= it->size();
        it->destroy();
        *it = msg;
        size_ += msg.size();
    }
}