void StoreState::update(simulator::Simulation& simulation, units::Time dt) { auto _ = measure_time("diffusion.store-state", simulator::TimeMeasurementIterationOutput(simulation)); // Get data table auto& table = simulation.getDataTable("diffusion"); // Foreach coordinates for (auto&& c : range(m_diffusionModule->getGridSize())) { // Create new row auto row = table.addRow( makePair("iteration", simulation.getIteration()), makePair("totalTime", simulation.getTotalTime().value()), makePair("x", c.getX()), makePair("y", c.getY()) ); // Foreach signals for (auto signalId : m_diffusionModule->getSignalIds()) { table.setData(row, makePair( m_diffusionModule->getSignalName(signalId), m_diffusionModule->getSignal(signalId, c).value() ) ); } } }
void TestRbTree::testCase1() { RBTree<int, int> tree; vector<int> v; int i =0; for (int i = 0; i < 20; ++i) { v.push_back(i); } random_shuffle(v.begin(), v.end()); copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); cout << endl; stringstream sstr; for (i = 0; i < v.size(); ++i) { tree.Insert(makePair(v[i], i)); cout << "insert:" << v[i] << endl; //添加结点 } for (i = 0; i < v.size(); ++i) { cout << "Delete:" << v[i] << endl; tree.Delete(v[i]); //删除结点 tree.InOrderTraverse(); } cout << endl; tree.InOrderTraverse(); std::cout << "case1 passed" << std::endl; }
Storage::Link Storage::createLink(const std::string& path, const std::string& target, const std::string& prefix, const std::string& loader) { auto it = linkByPath_.find(path); if(it != linkByPath_.end()) return Link(); auto prefixIt = prefixByName_.find(prefix); if(prefixIt == prefixByName_.end()) return Link(); auto loaderIt = loaderByName_.find(loader); if(loaderIt == loaderByName_.end()) return Link(); LinkInfo info; info.target = target; info.prefix = prefix; info.loader = loader; info.level = LogLevel::kDefault; auto result = linkByPath_.emplace(makePair(path, info)); if(!result.second) return Link(); isChanged_ = true; return Link(this, result.first); }
void StoreMolecules::call(simulator::Simulation& simulation, object::Object& object, units::Time dt) { // Cast to parasite auto& parasite = object.castThrow<ParasiteBase>("Parasite object required"); // Get data table auto& table = simulation.getDataTable("molecules"); // Create new row // iteration;totalTime;id;molecules... table.addRow( makePair("iteration", simulation.getIteration()), makePair("totalTime", simulation.getTotalTime().value()), makePair("id", object.getId()), parasite.getMolecules() ); }
controller::Input::NamedVector LeapMotionPlugin::InputDevice::getAvailableInputs() const { static controller::Input::NamedVector availableInputs; if (availableInputs.size() == 0) { for (int i = 0; i < LeapMotionJointIndex::Size; i++) { auto channel = LeapMotionJointIndexToPoseIndex(static_cast<LeapMotionJointIndex>(i)); availableInputs.push_back(makePair(channel, getControllerJointName(channel))); } }; return availableInputs; }
controller::Input::NamedVector NeuronPlugin::InputDevice::getAvailableInputs() const { static controller::Input::NamedVector availableInputs; if (availableInputs.size() == 0) { for (int i = 0; i < controller::NUM_STANDARD_POSES; i++) { auto channel = static_cast<controller::StandardPoseChannel>(i); availableInputs.push_back(makePair(channel, controllerJointName(channel))); } }; return availableInputs; }
QList<QPair<QVariant, QTextCharFormat> > chathandlerprv::getSegmentation(QString s, QTextCharFormat format) { QStringList sl=s.split(" ", QString::SkipEmptyParts); QList<QPair<QVariant, QTextCharFormat> > text; foreach(s,sl) { if(isClickableLink(s)) { hash[e_hash_http].setAnchorHref(s); text<<makePair(s, hash[e_hash_http]); } else if(startswithCI(s, "wa://")) { hash[e_hash_wa].setAnchorHref(s); hash[e_hash_wa].setProperty(linkpropertyId, s); text<<makePair(tr("GAMELINK"), hash[e_hash_wa]); } else { if(S_S.getbool("chbsmileysinchatwindows")) text<<makePair(emot->contains(s),format); else text<<makePair(s,format); } } return text; }
void NameGen::train(string f){ ifstream in(f.c_str()); char name[256]; while(in.good()){ in.getline(name,256); mark[makePair(BEGIN_CHAR,BEGIN_CHAR)][name[0]]++; mark[makePair(BEGIN_CHAR,name[0])][name[1]]++; int x; for(x=2;name[x];x++) mark[makePair(name[x-2],name[x-1])][name[x]]++; mark[makePair(name[x-2],name[x-1])][END_CHAR]++; mark[makePair(name[x-1],END_CHAR)][END_CHAR]++; } }
void listAppend(Thread* t, object list, object value) { PROTECT(t, list); ++ listSize(t, list); object p = makePair(t, value, 0); if (listFront(t, list)) { set(t, listRear(t, list), PairSecond, p); } else { set(t, list, ListFront, p); } set(t, list, ListRear, p); }
bool Storage::Link::setPath(const std::string& path) { if(isNull()) return false; if(path == it_->first) return true; auto it = storage_->linkByPath_.find(path); if(it != storage_->linkByPath_.end()) return false; LinkInfo info = it_->second; storage_->linkByPath_.erase(it_); it_ = storage_->linkByPath_.emplace_hint(it, makePair(path, info)); storage_->isChanged_ = true; return true; }
bool Storage::Loader::setName(const std::string& name) { if(isNull()) return false; std::string oldName = it_->first; std::string path = it_->second; auto result = storage_->loaderByName_.emplace(makePair(name, path)); if(!result.second) return false; for(auto& it : storage_->linkByPath_) { if(it.second.loader == oldName) it.second.loader = name; } storage_->loaderByName_.erase(it_); storage_->isChanged_ = true; it_ = result.first; return true; }
string NameGen::genName(int max){ map<char,uint32_t> *chain=NULL; string out; char last[2]; last[0]=BEGIN_CHAR; last[1]=BEGIN_CHAR; char tmp=END_CHAR; for(int i=0;i<max;i++){ chain = &(mark[makePair(last[0],last[1])]); uint64_t tot=0; for(map<char,uint32_t>::iterator it=chain->begin();it!=chain->end();it++) tot+=it->second; if(tot==0) return "error"; int64_t r = rand()%tot; for(map<char,uint32_t>::iterator it=chain->begin();it!=chain->end();it++){ r-=it->second; if(r<0){ tmp=it->first; break; } } if(tmp==END_CHAR) break; out+=tmp; last[0]=last[1]; last[1]=tmp; } return out; }
Input::NamedPair makeAxisPair(Action action, const QString& name) { return makePair(ChannelType::AXIS, action, name); }
refObject skolemize(refObject layer, refObject type) { struct { refFrame link; int count; refObject first; refObject labeler; refObject last; refObject layer; refObject next; refObject type; } f0; // IS SKOLEMIZABLE. Test if TYPE, which is ground in LAYER, can be the base of // a Skolem type. It can be, if it has a subtype that's different from itself. // For example, OBJ has an infinite number of such subtypes but INT0 has none. // The WHILE loop helps simulate tail recursions. bool isSkolemizable(refObject layer, refObject type) { while (true) { if (isName(type)) { getKey(r(layer), r(type), layer, type); } else // Visit a type. If LABELER says we've been here before, then return false. If // we haven't, then record TYPE in LABELER so we won't come here again. if (isPair(type)) { if (gotKey(toss, toss, f0.labeler, type)) { return false; } else { refObject pars; setKey(f0.labeler, type, nil, nil); switch (toHook(car(type))) // Visit a trivially Skolemizable type. An ALTS, FORM, or GEN type can have an // ALTS type as a subtype. A REF or ROW type can have NULL as a subtype. { case altsHook: case arraysHook: case formHook: case genHook: case jokerHook: case referHook: case rowHook: case skoHook: case tuplesHook: { return true; } // Visit a type that is trivially not Skolemizable. case cellHook: case char0Hook: case char1Hook: case int0Hook: case int1Hook: case int2Hook: case listHook: case nullHook: case real0Hook: case real1Hook: case strTypeHook: case symHook: case voidHook: { return false; } // Visit an ARRAY type. It's Skolemizable if its base type is. case arrayHook: { type = caddr(type); break; } // Visit a PROC type. It's Skolemizable if (1) it has a Skolemizable parameter // type, (2) it has the missing name NO NAME as a parameter name, (3) it has a // Skolemizable yield type. case procHook: { type = cdr(type); pars = car(type); while (pars != nil) { pars = cdr(pars); if (car(pars) == noName) { return true; } else { pars = cdr(pars); }} pars = car(type); while (pars != nil) { if (isSkolemizable(layer, car(pars))) { return true; } else { pars = cddr(pars); }} type = cadr(type); break; } // Visit a TUPLE type. It's Skolemizable if it has a Skolemizable slot type or // if it has the missing name NO NAME as a slot name. case tupleHook: { pars = cdr(type); while (pars != nil) { pars = cdr(pars); if (car(pars) == noName) { return true; } else { pars = cdr(pars); }} pars = cdr(type); while (pars != nil) { if (isSkolemizable(layer, car(pars))) { return true; } else { pars = cddr(pars); }} return false; } // Visit a prefix type. It's Skolemizable if its base type is. case typeHook: case varHook: { type = cadr(type); break; } // Visit an illegal type. We should never get here. default: { fail("Got ?%s(...) in isSkolemizable!", hookTo(car(type))); }}}} // Visit an illegal object. We should never get here either. else { fail("Got bad type in isSkolemizable!"); }}} // Lost? This is SKOLEMIZE's body. These identities show what's going on. // // S(type T B) => T S(B) // S(U) => ?sko(U) // S(V) => V // // Here S(X) is the Skolem type for type X. T is a series of zero or more TYPE // prefixes. B is a type, U is a type with at least one subtype different from // itself, and V is a type with no subtypes different from itself. push(f0, 6); f0.labeler = pushLayer(nil, plainInfo); f0.layer = layer; f0.type = type; while (isName(f0.type)) { getKey(r(f0.layer), r(f0.type), f0.layer, f0.type); } if (isCar(f0.type, typeHook)) { f0.type = cadr(f0.type); if (isSkolemizable(f0.layer, f0.type)) { if (isCar(f0.type, typeHook)) { f0.first = f0.last = makePair(hooks[typeHook], nil); f0.type = cadr(f0.type); while (isCar(f0.type, typeHook)) { f0.next = makePair(hooks[typeHook], nil); cdr(f0.last) = makePair(f0.next, nil); f0.last = f0.next; f0.type = cadr(f0.type); } f0.next = makePrefix(skoHook, f0.type); cdr(f0.last) = makePair(f0.next, nil); } else { f0.first = makePrefix(skoHook, f0.type); }} else { f0.first = makePair(car(f0.type), cdr(f0.type)); }} else { fail("Type type expected in skolemize!"); } pop(); destroyLayer(f0.labeler); return f0.first; }
bool Storage::reload() { storageFilePath_.clear(); logSocketPath_.clear(); binariesPath_.clear(); prefixByName_.clear(); loaderByName_.clear(); linkByPath_.clear(); // Add default WINE prefix std::string name = "default"; std::string path = FileSystem::realPath("~") + "/.wine"; prefixByName_.emplace(makePair(name, path)); // Add default WINE loader name = "default"; path = FileSystem::fullNameFromPath("wine"); loaderByName_.emplace(makePair(name, path)); // Initialize default values binariesPath_ = INSTALL_PREFIX "/bin"; const char* string = getenv("TMPDIR"); std::string tempPath = string ? string : "/tmp"; logSocketPath_ = tempPath + "/" PROJECT_NAME ".sock"; defaultLogLevel_ = LogLevel::kTrace; // Find and read a configuration file string = getenv("XDG_CONFIG_PATH"); std::string configPath = string ? string : std::string(); if(configPath.empty()) configPath = "~/.config"; configPath = FileSystem::realPath(configPath); if(configPath.back() != '/') configPath += '/'; if(!FileSystem::isDirExists(configPath)) return false; storageFilePath_ = configPath + PROJECT_NAME "/" PROJECT_NAME ".conf"; std::ifstream file(storageFilePath_); if(!file.is_open()) return false; Json::Value root; Json::Reader reader; if(!reader.parse(file, root, false)) return false; // Load general variables auto value = root["binaries_path"]; if(!value.isNull()) binariesPath_ = value.asString(); value = root["log_socket_path"]; if(!value.isNull()) logSocketPath_ = value.asString(); value = root["default_log_level"]; if(!value.isNull()) { defaultLogLevel_ = static_cast<LogLevel>(value.asInt()); if(defaultLogLevel_ < LogLevel::kQuiet || defaultLogLevel_ > LogLevel::kFlood) defaultLogLevel_ = LogLevel::kTrace; } // Load prefixes Json::Value prefixes = root["prefixes"]; for(uint i = 0; i < prefixes.size(); ++i) { Json::Value prefix = prefixes[i]; name = prefix["name"].asString(); path = prefix["path"].asString(); if(name.empty() || path.empty()) continue; prefixByName_.emplace(makePair(name, path)); } // Load loaders Json::Value loaders = root["loaders"]; for(uint i = 0; i < loaders.size(); ++i) { Json::Value loader = loaders[i]; name = loader["name"].asString(); path = loader["path"].asString(); if(name.empty() || path.empty()) continue; loaderByName_.emplace(makePair(name, path)); } // Load links Json::Value links = root["links"]; for(uint i = 0; i < links.size(); ++i) { Json::Value link = links[i]; LinkInfo info; info.target = link["target"].asString(); info.loader = link["loader"].asString(); if(info.loader.empty()) info.loader = "default;"; info.prefix = link["prefix"].asString(); if(info.prefix.empty()) info.prefix = "default;"; auto value = link["log_level"]; if(value.isNull()) { info.level = LogLevel::kDefault; } else { info.level = static_cast<LogLevel>(value.asInt()); if(info.level < LogLevel::kDefault || info.level > LogLevel::kFlood) info.level = LogLevel::kDefault; } path = link["path"].asString(); linkByPath_.emplace(makePair(path, info)); } return true; }
refObject makingType(refChar name, int align, int size) { return makePair(hooks[strTypeHook], makePair(bufferToString(name), makePair(makeInteger(align), makePair(makeInteger(size), nil)))); }
Input::NamedPair makeButtonPair(Action action, const QString& name) { return makePair(ChannelType::BUTTON, action, name); }
Input::NamedPair makePosePair(Action action, const QString& name) { return makePair(ChannelType::POSE, action, name); }
{ setKey(layers, internSecretName(string), type, value); } // MAKING TYPE. Make an external type with specified NAME, ALIGNment and SIZE. // We always call this function via the macro MAKE TYPE (see ORSON/GLOBAL). refObject makingType(refChar name, int align, int size) { return makePair(hooks[strTypeHook], makePair(bufferToString(name), makePair(makeInteger(align), makePair(makeInteger(size), nil)))); } // Make simple types. The garbage collector must explicitly mark the ones that // names aren't bound to. (See ORSON/HUNK.) cellSimple = makePair(hooks[cellHook], nil); char0Simple = makePair(hooks[char0Hook], nil); char1Simple = makePair(hooks[char1Hook], nil); int0Simple = makePair(hooks[int0Hook], nil); int1Simple = makePair(hooks[int1Hook], nil); int2Simple = makePair(hooks[int2Hook], nil); listSimple = makePair(hooks[listHook], nil); nullSimple = makePair(hooks[nullHook], nil); real0Simple = makePair(hooks[real0Hook], nil); real1Simple = makePair(hooks[real1Hook], nil); voidSimple = makePair(hooks[voidHook], nil); // Bind names to simple types. bindName("char0", makePrefix(typeHook, char0Simple), char0Simple); bindName("char1", makePrefix(typeHook, char1Simple), char1Simple);