Node* Nonleaf::InsertMightSplit(Stat *Stats, const Entry &Ent, Node *Ptr) { short samegroup; Nonleaf *NewNode; int i1,i2,n1,n2,head1,head2; double d1, d2; Entry ent1,ent2; ent1.Init(Stats->Dimension); ent2.Init(Stats->Dimension); if (NotFull(Stats)) { entry[actsize]=Ent; child[actsize]=Ptr; actsize++; return NULL; } NewNode=new Nonleaf(Stats); Stats->MemUsed++; Stats->TreeSize++; NewNode->entry[NewNode->actsize]=Ent; NewNode->child[NewNode->actsize]=Ptr; NewNode->actsize++; this->FarthestTwoOut(Stats,this,NewNode,samegroup,i1,i2); switch (samegroup) { case 0: this->swap(this,0, this,i1); NewNode->swap(NewNode,0, NewNode,i2); break; case 1: this->swap(this,0, this,i1); NewNode->swap(NewNode,0, this,i2); break; default: print_error("Nonleaf::InsertMightSplit","Invalid group flag"); } n1=MaxSize(Stats); n2=1; head1=1; head2=1; ent1 = this->entry[0]; ent2 = NewNode->entry[0]; while (head1<n1) { d1 = distance(Stats->BDtype,ent1,this->entry[head1]); d2 = distance(Stats->BDtype,ent2,this->entry[head1]); if (d1<d2) { ent1+=this->entry[head1]; head1++; } else { this->assign(NewNode,head2,this,head1); this->assign(this,head1,this,n1-1); ent2+=NewNode->entry[head2]; head2++; n1--; n2++; } } this->actsize=n1; NewNode->actsize=n2; return(NewNode); }
void Add( F && x ) { std::unique_lock<std::mutex> locker(m_mutex); m_notFull.wait(locker,[this]{return m_stop || NotFull();}); if( m_stop ) { return; } m_queue.push_back(std::forward<F>(x)); m_notEmpty.notify_one(); }