PotionStructure& PotionStructure::operator =(const PotionStructure& originalStructure) { // If you're setting it equal to itself, do nothing. if(*this == originalStructure) { return *this; } // Otherwise, we delete the old queue to avoid memory leaks. chainDelete(); PotionNode *currentNode; PotionNode *otherNode = originalStructure.getFront(); while(otherNode) { currentNode = new PotionNode; if(currentNode) { if(otherNode == originalStructure.getFront()) { _first = currentNode; } else if(otherNode == originalStructure.getBack()) { _last = currentNode; } currentNode->setPotion(otherNode->getPotion()); otherNode = otherNode->getNext(); } } return *this; }
void deleteSelectedAlignments(std::vector<std::vector<Chain*>>& alignment_strings) { for (uint32_t i = 0; i < alignment_strings.size(); ++i) { for (uint32_t j = 0; j < alignment_strings[i].size(); ++j) { if (alignment_strings[i][j] != nullptr) { chainDelete(alignment_strings[i][j]); alignment_strings[i][j] = nullptr; } } std::vector<Chain*>().swap(alignment_strings[i]); } }
void LinkedBag<ItemType>::clear() { // if the head ptr is NULL then there is nothing to do if (headPtr == NULL) { return; } // otherwise call into the recursive destroyer of objects chainDelete(headPtr); // clean up headPtr = NULL; itemCount = 0; }
void LinkedBag<ItemType>::chainDelete(Node<ItemType>* ptrToDelete) { Node<ItemType>* nextPtr; // get the next pointer if there is one nextPtr = ptrToDelete->getNext(); // if there is, recursively call into this function with it if (nextPtr) //NULL should result in a false { chainDelete(nextPtr); } // Return node to the system ptrToDelete->setNext(NULL); delete ptrToDelete; ptrToDelete = NULL; }
skillNode& skillNode::operator =(const skillNode& originalNode) { chainDelete(); setValues(); // See above - sets the default values. // Copy each child of originalNode to *this. for(int i = 0; i < originalNode.getNumberOfChildren(); i++) { _children[i] = new skillNode; if(_children[i]) { // Recursion here - this does the exact same operation on children. *(_children[i]) = *originalNode[i]; _numberOfChildren++; } } _skill = originalNode.getSkill(); return *this; }
void* threadSelectAlignments(void* params) { auto thread_data = (ThreadSelectionData*) params; thread_data->dst.clear(); alignmentsExtract(thread_data->dst, thread_data->query, thread_data->alignments, thread_data->alignments_length); uint32_t selected_alignments_length = alignmentsSelect(thread_data->dst, thread_data->query, thread_data->threshold); for (uint32_t i = selected_alignments_length; i < thread_data->dst.size(); ++i) { chainDelete(thread_data->dst[i]); } thread_data->dst.resize(selected_alignments_length); delete thread_data; return nullptr; }
inventory& inventory::operator =(const inventory& originalInventory) { itemNode *tempNode; itemNode *otherNode = originalInventory.getHead(); itemNode *currentNode = _head; // Delete the list that was there before. chainDelete(); _head = NULL; tempNode = NULL; while(otherNode) { currentNode = new itemNode; if(currentNode) { *currentNode = *otherNode; // Using overloaded itemNode operator // on dereferenced pointers. } if(_head == NULL) { _head = currentNode; } if(tempNode) { tempNode->setNext(currentNode); } tempNode = currentNode; otherNode = otherNode->getNext(); } _weight = originalInventory.getWeight(); _count = originalInventory.getCount(); return *this; }
skillNode::~skillNode() { chainDelete(); return; }
PotionStructure::~PotionStructure() { chainDelete(); return; }
uint64_t searchDatabase(std::vector<std::vector<uint32_t>>& dst, const std::string& database_path, Chain** queries, int32_t queries_length, uint32_t kmer_length, uint32_t max_candidates, uint32_t num_threads) { fprintf(stderr, "** Searching database for candidate sequences **\n"); std::shared_ptr<Hash> query_hash = createHash(queries, queries_length, 0, queries_length, kmer_length); Chain** database = nullptr; int database_length = 0; int database_start = 0; FILE* handle = nullptr; int serialized = 0; readFastaChainsPartInit(&database, &database_length, &handle, &serialized, database_path.c_str()); uint64_t database_cells = 0; std::vector<float> min_scores(queries_length, 1000000.0); std::vector<std::vector<std::vector<Candidate>>> candidates(num_threads); uint32_t part = 1; float part_size = database_chunk / (float) 1000000000; while (true) { int status = 1; status &= readFastaChainsPart(&database, &database_length, handle, serialized, database_chunk); databaseLog(part, part_size, 0); uint32_t database_split_size = (database_length - database_start) / num_threads; std::vector<uint32_t> database_splits(num_threads + 1, database_start); for (uint32_t i = 1; i < num_threads; ++i) { database_splits[i] += i * database_split_size; } database_splits[num_threads] = database_length; std::vector<ThreadPoolTask*> thread_tasks(num_threads, nullptr); for (uint32_t i = 0; i < num_threads; ++i) { auto thread_data = new ThreadSearchData(query_hash, queries_length, min_scores, database, database_splits[i], database_splits[i + 1], kmer_length, max_candidates, candidates[i], i == num_threads - 1, part, part_size); thread_tasks[i] = threadPoolSubmit(threadSearchDatabase, (void*) thread_data); } for (uint32_t i = 0; i < num_threads; ++i) { threadPoolTaskWait(thread_tasks[i]); threadPoolTaskDelete(thread_tasks[i]); } for (int i = database_start; i < database_length; ++i) { database_cells += chainGetLength(database[i]); chainDelete(database[i]); database[i] = nullptr; } // merge candidates from all threads for (int32_t i = 0; i < queries_length; ++i) { for (uint32_t j = 1; j < num_threads; ++j) { if (candidates[j][i].empty()) { continue; } candidates[0][i].insert(candidates[0][i].end(), candidates[j][i].begin(), candidates[j][i].end()); std::vector<Candidate>().swap(candidates[j][i]); } if (num_threads > 1) { std::sort(candidates[0][i].begin(), candidates[0][i].end()); if (candidates[0][i].size() > max_candidates) { std::vector<Candidate> tmp(candidates[0][i].begin(), candidates[0][i].begin() + max_candidates); candidates[0][i].swap(tmp); } } if (!candidates[0][i].empty()) { min_scores[i] = candidates[0][i].back().score; } } databaseLog(part, part_size, 100); ++part; if (status == 0) { break; } database_start = database_length; } fprintf(stderr, "\n\n"); fclose(handle); deleteFastaChains(database, database_length); dst.clear(); dst.resize(queries_length); for (int32_t i = 0; i < queries_length; ++i) { dst[i].reserve(candidates[0][i].size()); for (uint32_t j = 0; j < candidates[0][i].size(); ++j) { dst[i].emplace_back(candidates[0][i][j].id); } std::vector<Candidate>().swap(candidates[0][i]); std::sort(dst[i].begin(), dst[i].end()); } return database_cells; }
inventory::~inventory() { chainDelete(); return; }