opendht-2.1.4/src/routing_table.cpp
/* Split a bucket into two equal parts. */
Split a bucket into two equal parts.
Split a bucket into two equal parts .
bool
RoutingTable::split(const RoutingTable::iterator& b)
{
    InfoHash new_id;
    try {
        new_id = middle(b);
    } catch (const std::out_of_range& e) {
        return false;
    }
    insert(std::next(b), Bucket {b->af, new_id, b->time});
    std::list<Sp<Node>> nodes {};
    nodes.splice(nodes.begin(), b->nodes);
    while (!nodes.empty()) {
        auto n = nodes.begin();
        auto b = findBucket((*n)->id);
        if (b == end())
            nodes.erase(n);
        else
            b->nodes.splice(b->nodes.begin(), nodes, n);
    }
    return true;
}
bool RoutingTable :: split ( const RoutingTable :: iterator & b ) { InfoHash new_id ; try { new_id = middle ( b ) ; } catch ( const std :: out_of_range & e ) { return false ; } insert ( std :: next ( b ) , Bucket { b -> af , new_id , b -> time } ) ; std :: list < Sp < Node > > nodes { } ; nodes . splice ( nodes . begin ( ) , b -> nodes ) ; while ( ! nodes . empty ( ) ) { auto n = nodes . begin ( ) ; auto b = findBucket ( ( * n ) -> id ) ; if ( b == end ( ) ) nodes . erase ( n ) ; else b -> nodes . splice ( b -> nodes . begin ( ) , nodes , n ) ; } return true ; }
Split a bucket into two equal parts.
Split a bucket into two equal parts .
// Insert new bucket // Re-assign nodes