static INLINE PAIR *createPair(CRDS *crds, PCODE pcode, CODE left, CODE right, uint f_pos) { PAIR *pair = (PAIR *)malloc(sizeof(PAIR)); uint h; PAIR *q; PQUE *p_que = crds->p_que[pcode]; pair->pcode = pcode; pair->left = left; pair->right = right; pair->freq = 1; pair->f_pos = pair->b_pos = f_pos; pair->p_prev = pair->p_next = NULL; p_que->num_pairs++; if (p_que->num_pairs >= primes[p_que->h_num]) { rehash(crds, pcode); } h = hash_val(p_que->h_num, left, right); q = p_que->h_entry[h]; p_que->h_entry[h] = pair; pair->h_next = q; insertPair(crds, pair); return pair; }
void init(){ count = 0; while(!heap.empty()){ heap.pop(); } R_TreeNode<2,TupleId> root1 = t1->Root(); R_TreeNode<2,TupleId> root2 = t2->Root(); insertPair(root1,0, root2,0); }
void addPair(char* key, int value, hashTable* hTable) { hTable->loadFactor = insertPair(key, value, hTable->table, hTable->tableSize, hTable->loadFactor); if(hTable->loadFactor > hTable->maxLoad) { hTable->table = doubleSize(hTable->table, hTable->tableSize, hTable->loadFactor); hTable->loadFactor = hTable->loadFactor / 2; hTable->tableSize = hTable->tableSize * 2; } }
static INLINE void incrementPair(CRDS *crds, PAIR *target) { PQUE *p_que = crds->p_que[target->pcode]; if (target->freq >= p_que->p_max) { target->freq++; return; } removePair(crds, target); target->freq++; insertPair(crds, target); }
std::map< std::string, MB::StrVector > Resources::ResourceLists() { sf::Lock(this->mutex); std::map<std::string,MB::StrVector> ResourceList; std::list<MB::Content::ID*>::iterator typeItr; for (typeItr = this->types.begin(); typeItr != this->types.end(); typeItr++) { ID* resource = (*typeItr); resource->Type(); std::pair<std::string,MB::StrVector> insertPair(resource->Type(),resource->List()); ResourceList.insert(insertPair); } return ResourceList; }
static INLINE void decrementPair(CRDS *crds, PAIR *target) { PQUE *p_que = crds->p_que[target->pcode]; if (target->freq > p_que->p_max) { target->freq--; return; } if (target->freq == 1) { //destructPair(crds, target); } else { removePair(crds, target); target->freq--; insertPair(crds, target); } }
Tuple* produceNextTuple(){ while(!heap.empty() && !heap.top().isFinal()){ closestPairEntry e = heap.top(); heap.pop(); if(e.final1()){ R_TreeNode<2,TupleId> n2 = getNode2(e); for(int i=0;i<n2.EntryCount();i++){ if(n2.IsLeaf()){ R_TreeLeafEntry<2,TupleId> e2 = (R_TreeLeafEntry<2,TupleId>&)n2[i]; closestPairEntry entry(e,e2,e.getLevel2()+1); if(!prune(entry)){ heap.push(entry); } } else { R_TreeInternalEntry<2> e2 = (R_TreeInternalEntry<2>&)n2[i]; closestPairEntry entry(e,e2,e.getLevel2()+1); if(!prune(entry)){ heap.push(entry); } } } } else if(e.final2()){ R_TreeNode<2,TupleId> n1 = getNode1(e); for(int i=0;i<n1.EntryCount();i++){ if(n1.IsLeaf()){ R_TreeLeafEntry<2,TupleId> e1 = (R_TreeLeafEntry<2,TupleId>&)n1[i]; closestPairEntry entry(e1,e.getLevel1()+1, e); if(!prune(entry)){ heap.push(entry); } } else { R_TreeInternalEntry<2> e1 = (R_TreeInternalEntry<2>&)n1[i]; closestPairEntry entry(e1,e.getLevel2()+1, e); if(!prune(entry)){ heap.push(entry); } } } } else { // both are not final R_TreeNode<2,TupleId> n1 = getNode1(e); R_TreeNode<2,TupleId> n2 = getNode2(e); insertPair(n1,e.getLevel1()+1,n2,e.getLevel2()+1); } } if(heap.empty()){ // no more entries return 0; } closestPairEntry e = heap.top(); heap.pop(); TupleId tid1 = e.getTid1(); TupleId tid2 = e.getTid2(); Tuple* t1 = r1->GetTuple(tid1,true); Tuple* t2 = r2->GetTuple(tid2,true); if(t1==0 || t2==0){ cerr << "TupleId stored in rtree not found" << endl; cerr << " computing closest pair canceled" << endl; count = k; return 0; } Tuple* res = new Tuple(tt); Concat(t1,t2,res); t1->DeleteIfAllowed(); t2->DeleteIfAllowed(); count++; return res; }
void NVMap::appendPairs(StringVector vector, char delim) { for(StringVector::iterator itr = vector.begin(); itr != vector.end(); ++itr) insertPair(*itr, delim); }