void* hashmapMemoize(Hashmap* map, void* key, void* (*initialValue)(void* key, void* context), void* context) { int hash = hashKey(map, key); size_t index = calculateIndex(map->bucketCount, hash); Entry** p = &(map->buckets[index]); while (true) { Entry* current = *p; // Add a new entry. if (current == NULL) { *p = createEntry(key, hash, NULL); if (*p == NULL) { errno = ENOMEM; return NULL; } void* value = initialValue(key, context); (*p)->value = value; map->size++; expandIfNecessary(map); return value; } // Return existing value. if (equalKeys(current->key, current->hash, key, hash, map->equals)) { return current->value; } // Move to next entry. p = ¤t->next; } }
/********************************************************* * getLines returns a representation of each line from * * the input files as a map<string, vector<string> > to * * be passed to the user defined reduce function. * * ******************************************************/ void RunReduce::getLines(unorderedMap &keyValues) { std::vector<std::string> lines; std::vector<std::string>::const_iterator linesIT; merger<std::string>(lines, files_); for(linesIT = lines.begin();linesIT!=lines.end();linesIT++) { std::string key(getKey(*linesIT)); std::vector<std::string> values; parseMapLine(values, *linesIT); if(keyValues.find(key) == keyValues.end()) { //Not in structure strVectorPtr initialValue(new std::vector<std::string>(values)); keyValues[key] = initialValue; } else { //Contained in structure std::vector<std::string>::const_iterator valuesIT = values.begin(); std::vector<std::string>::const_iterator end = values.end(); while(valuesIT != end) { keyValues[key]->push_back(*valuesIT); ++valuesIT; } } } }
// initial solution void Domain1D::_getInitialSoln(doublereal* x) { for (size_t j = 0; j < m_points; j++) { for (size_t n = 0; n < m_nv; n++) { x[index(n,j)] = initialValue(n,j); } } }
SeriesTitleEntry::SeriesTitleEntry(BookInfoDialog &dialog) : ZLComboOptionEntry(true), myInfoDialog(dialog) { const AuthorList &authors = myInfoDialog.myBook->authors(); myOriginalValuesSet.insert(initialValue()); myOriginalValuesSet.insert(""); const Library &library = Library::Instance(); for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) { library.collectSeriesTitles(*it, myOriginalValuesSet); } }
EXPORT_C void PlayerApplicationSettingsResourceInit::DefineAttributesL(MPlayerApplicationSettingsObserver& aSettings, CResourceFile& aResourceFile) { // Read the settings from the resource file RResourceReader reader; reader.OpenLC(&aResourceFile, KAVRCPResourceId); // Check the version of this resource file TUint16 formatVersion = reader.ReadUint16L(); if (formatVersion != KAVRCPFormatVersion) { reader.Close(); User::Leave(KErrCorrupt); } // Find out how many settings this resource file contains TInt settingsCount = reader.ReadUint16L(); if (settingsCount < 0) { reader.Close(); User::Leave(KErrCorrupt); } // read the settings from aResource RArray<TUint> values; RArray<TPtrC8> valueTexts; CleanupClosePushL(values); CleanupClosePushL(valueTexts); // Read each AVRCP attribute setting in turn for (int i = 0; i < settingsCount; i++) { values.Reset(); valueTexts.Reset(); // Read attribute, description text, initial value and defined values TUint attributeID(reader.ReadUint8L()); TUint initialValue(reader.ReadUint8L()); TPtrC8 attributeText(reader.ReadTPtrC8L()); TInt valuesCount(reader.ReadUint16L()); for (int j = 0; j < valuesCount; j++) { TUint thisValue = reader.ReadUint8L(); TPtrC8 thisDescription = reader.ReadTPtrC8L(); values.AppendL(thisValue); valueTexts.AppendL(thisDescription); } // Now define this attribute, then continue to next attribute aSettings.DefineAttributeL(attributeID, attributeText, values, valueTexts, initialValue); } // cleaning up values and valueTexts CleanupStack::PopAndDestroy(3); // values, valueTexts, reader }
const std::vector<std::string> &AbstractEncodingEntry::values() const { if (initialValue() == Book::AutoEncoding) { static std::vector<std::string> AUTO_ENCODING; if (AUTO_ENCODING.empty()) { AUTO_ENCODING.push_back(Book::AutoEncoding); } return AUTO_ENCODING; } std::map<std::string,std::vector<std::string> >::const_iterator it = myValues.find(myInitialSetName); return it->second; }
void TestSetValue() { mitk::Label::Pointer label = mitk::Label::New(); mitk::Label::PixelType initialValue(0); mitk::Label::PixelType valueToBeCompared = label->GetValue(); CPPUNIT_ASSERT_MESSAGE("Initial label has wrong value", initialValue == valueToBeCompared); label->SetValue(12345); valueToBeCompared = 12345; initialValue = label->GetValue(); CPPUNIT_ASSERT_MESSAGE("Label has wrong value", initialValue == valueToBeCompared); }
const std::vector<std::string> &SeriesTitleEntry::values() const { myValues.clear(); std::set<std::string> valuesSet; valuesSet.insert(initialValue()); valuesSet.insert(""); if (!myOriginalAuthor.isNull()) { myInfoDialog.myCollection.collectSeriesNames(myOriginalAuthor, valuesSet); } AuthorPtr currentAuthor = myInfoDialog.myAuthorDisplayNameEntry->myCurrentAuthor; if (!currentAuthor.isNull() && (currentAuthor != myOriginalAuthor)) { myInfoDialog.myCollection.collectSeriesNames(currentAuthor, valuesSet); } for (std::set<std::string>::const_iterator it = valuesSet.begin(); it != valuesSet.end(); ++it) { myValues.push_back(*it); } return myValues; }
const std::vector<std::string> &AuthorDisplayNameEntry::values() const { if (myValues.empty()) { const std::string &initial = initialValue(); bool addInitial = true; const std::vector<AuthorPtr> &authors = myInfoDialog.myCollection.authors(); for (std::vector<AuthorPtr>::const_iterator it = authors.begin(); it != authors.end(); ++it) { const std::string name = (*it)->displayName(); if (addInitial && (name == initial)) { addInitial = false; } myValues.push_back(name); } if (addInitial) { myValues.push_back(initial); } } return myValues; }
// Edit the string in a separate dialog, for convenience void ecTextEditorCtrl::OnLeftDClick(wxMouseEvent& event) { ecValueWindow* parent = (ecValueWindow*) GetParent(); ecConfigItem* item = parent->GetCurrentConfigItem(); ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc(); wxString initialValue(GetValue()); initialValue.Replace("\\n", "\n"); // remove escaping of newline chars ecEditStringDialog dialog(initialValue, wxGetApp().GetTopWindow(), ecID_EDIT_STRING_DIALOG); if (dialog.ShowModal() == wxID_OK) { wxString val = dialog.GetValue() ; // This control will have been deleted at this point, due to losing the focus. // So update the item, not the control. // wxTextCtrl::SetValue(val); doc->SetValue(*item, val); } }
void RBEC::run() { initialize(); buildMatrixStruct(); initialValue(); FEMFunction <double, DIM> phi2(fem_space); do { stepForward(); for (int i = 0; i < fem_space.n_dof(); ++i) phi2(i) = phi_re(i) * phi_re(i); phi2.writeOpenDXData("phi2.dx"); std::cout << "t = " << t << std::endl; } while (t < 3); };
const std::vector<std::string> &AuthorDisplayNameEntry::values() const { if (myValues.empty()) { const std::string &initial = initialValue(); bool addInitial = true; const AuthorList &authors = Library::Instance().authors(); for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) { if (it->isNull()) { continue; } const std::string name = (*it)->name(); if (addInitial && (name == initial)) { addInitial = false; } myValues.push_back(name); } if (addInitial) { myValues.push_back(initial); } } return myValues; }
void AbstractEncodingEntry::onAccept(const std::string &value) { if (initialValue() != Book::AutoEncoding) { onAcceptValue(myValueByName[value]); } }
ProgramChoiceEntry::ProgramChoiceEntry(const ProgramCollection &collection) : myCollection(collection) { myValue = initialValue(); }