NS_IMETHODIMP mozSpellChecker::RemoveWordFromPersonalDictionary(const nsAString &aWord) { nsresult res; PRUnichar empty=0; if (!mPersonalDictionary) return NS_ERROR_NULL_POINTER; res = mPersonalDictionary->RemoveWord(PromiseFlatString(aWord).get(),&empty); return res; }
void Dictionary::BatchDelete(){ ifstream inp ("deletions.txt"); string line; int found_count = 0; if(inp.is_open()){ while(getline(inp,line)){ found_count += RemoveWord(line); } } else{ cout << "Error : Reading deletions.txt!\n"; } cout << "Removed Words count = " << found_count << endl; }
//If we are a leaf node, then remove ourselves and decrement our parent's counter void Dictionary::RemoveWord(DictionaryNode* node) { //Multiple people can try to remove this node at the same time, but only one will succeed bool expected = false; if (node->mIsDisabled.compare_exchange_strong(expected, true, std::memory_order_relaxed, std::memory_order_relaxed)) { DictionaryNode* parent = node->mParent; //fetch_sub is a post-decrement if (parent->mChildrenCount.fetch_sub(1) == 1 && !parent->mIsDisabled.load() && (!parent->mIsWord || (parent->mIsWord && parent->mIsFound))) { //If a node no longer has children and has nothing depending on it, then we can try to cascade remove that one too RemoveWord(parent); } } }