.homeworks/hw6/Post.cpp
/* add a update TO a post */
add a update TO a post
add a update TO a post
void Post::operator+=(const Post& update)
{
    if (update.profile_id != this->profile_id &&
        update.post_id != this->post_id)
        throw "Error: Invalid Update (ID Not Match)";
    for (auto var: *update.links)
    {
        string key = var->getKey();
        if (!this->links_hash.count(key))
        {
            this->links_hash[key] = 1;
            this->links->push_back(var->clone());
        }
    }
    for (auto var : *update.comments)
    {
        CommentKeyPair thisKey = var.second->getKeyPair();
        if (this->comments->count(thisKey))
            *(*this->comments)[thisKey] += *var.second;
        else
            (*this->comments)[thisKey] = var.second->clone();
    }
    this->is_published = update.is_published;
    if (update.updated_time)
    {
        delete this->updated_time;
        this->updated_time = update.updated_time->clone();
    }
    for (auto var: *update.reactions)
        (*this->reactions)[var.second->getKey()] = var.second->clone();
    for (auto var: *update.receivers)
    {
        if (!this->receivers_hash.count(var->getKey()))
        {
            this->receivers_hash[var->getKey()] = 1;
            this->receivers->push_back(var->clone());
        }
    }
    for (auto var: *update.keywordTable)
        (*this->keywordTable)[var.first] = 1;
    if (update.location)
    {
        delete this->location;
        this->location = update.location->clone();
    }
}
void Post :: operator += ( const Post & update ) { if ( update . profile_id != this -> profile_id && update . post_id != this -> post_id ) throw " " ; for ( auto var : * update . links ) { string key = var -> getKey ( ) ; if ( ! this -> links_hash . count ( key ) ) { this -> links_hash [ key ] = 1 ; this -> links -> push_back ( var -> clone ( ) ) ; } } for ( auto var : * update . comments ) { CommentKeyPair thisKey = var . second -> getKeyPair ( ) ; if ( this -> comments -> count ( thisKey ) ) * ( * this -> comments ) [ thisKey ] += * var . second ; else ( * this -> comments ) [ thisKey ] = var . second -> clone ( ) ; } this -> is_published = update . is_published ; if ( update . updated_time ) { delete this -> updated_time ; this -> updated_time = update . updated_time -> clone ( ) ; } for ( auto var : * update . reactions ) ( * this -> reactions ) [ var . second -> getKey ( ) ] = var . second -> clone ( ) ; for ( auto var : * update . receivers ) { if ( ! this -> receivers_hash . count ( var -> getKey ( ) ) ) { this -> receivers_hash [ var -> getKey ( ) ] = 1 ; this -> receivers -> push_back ( var -> clone ( ) ) ; } } for ( auto var : * update . keywordTable ) ( * this -> keywordTable ) [ var . first ] = 1 ; if ( update . location ) { delete this -> location ; this -> location = update . location -> clone ( ) ; } }
add a update TO a post
add a update TO a post
// spacial case: id not matching // special case: update time smaller than origional post // to be update // get all new links // get the new comments or update to excesting comments // if this comment already exists, add to it // otherwise it is a new comment // change to new update time // get the new reactions // get the new receivers // get all the new keywords // update location