本文整理汇总了C++中map::count方法的典型用法代码示例。如果您正苦于以下问题:C++ map::count方法的具体用法?C++ map::count怎么用?C++ map::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseRoutes
/**
* parseRoutes - parses the routes in the route.dat file and
* calculates the distance between the ariports
*
* IN: mat - Adjacency matrix that contains the
* distance. mat[src][dest] where src is the starting airport and dest
* is the destination.
* IN: fileName - name of the routes file
* IN: alist - list of all the airports that is used to find the
* coorindates of the airport in the routes file.
*/
int parseRoutes(double **mat, string fileName, string *adj2Ap,
map<string, Airport> alist, set<string>& cities,
map<string, int>& lookup, struct Coordinates *coordinate) {
char buf[256];
char *token;
string src, dest;
int srcInx = 0, destInx = 0;
int apSrc = 0, apDest = 0;
int apCnt = 0, lkuCnt = 0;
int totAp = 0;
FILE *fp = fopen(fileName.c_str(), "r");
if (fp == NULL) {
printf("Error opening routes file");
exit(-1);
}
while(fgets(buf, sizeof(buf), fp)) {
token = strtok(buf, ",");
strtok(NULL, ",");
src = strtok(NULL, ",");
strtok(NULL, ",");
dest = strtok(NULL, ",");
cities.insert(alist[src].city);
cities.insert(alist[dest].city);
// Determine if airport is on the adj matrix
if (!lookup.count(src)) { // does not find src airport
lookup[src] = lkuCnt;
adj2Ap[apCnt++] = src;
apSrc = lkuCnt++;
totAp++;
(coordinate->visitedAirports).insert(src);
}
else {
apSrc = lookup[src];
}
if (!lookup.count(dest)) { // does not find dest airport
lookup[dest] = lkuCnt;
adj2Ap[apCnt++] = dest;
apDest = lkuCnt++;
totAp++;
(coordinate->visitedAirports).insert(dest);
}
else {
apDest = lookup[dest];
}
mat[apSrc][apDest] = 1;
// Haversine math here ~ real: 0.149 seconds
//mat[src][dest] = haversine(alist[src].latitude, alist[src].longitude,
// alist[dest].latitude, alist[dest].longitude);
//if no mat use... ~ real: 0.044 seconds
// 2/18 - Tim... just doing this, without calculation of haversine... ~ real: 0.120 seconds
}
fclose(fp);
return totAp;
}
示例2: signrawtransaction
//.........这里部分代码省略.........
UniValue prevTxs = params[1].get_array();
for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
const UniValue& p = prevTxs[idx];
if (!p.isObject())
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
UniValue prevOut = p.get_obj();
RPCTypeCheckObj(prevOut, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM)("scriptPubKey", UniValue::VSTR));
uint256 txid = ParseHashO(prevOut, "txid");
int nOut = find_value(prevOut, "vout").get_int();
if (nOut < 0)
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout must be positive");
vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey"));
CScript scriptPubKey(pkData.begin(), pkData.end());
{
CCoinsModifier coins = view.ModifyCoins(txid);
if (coins->IsAvailable(nOut) && coins->vout[nOut].scriptPubKey != scriptPubKey) {
string err("Previous output scriptPubKey mismatch:\n");
err = err + ScriptToAsmStr(coins->vout[nOut].scriptPubKey) + "\nvs:\n"+
ScriptToAsmStr(scriptPubKey);
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, err);
}
if ((unsigned int)nOut >= coins->vout.size())
coins->vout.resize(nOut+1);
coins->vout[nOut].scriptPubKey = scriptPubKey;
coins->vout[nOut].nValue = 0; // we don't know the actual output value
}
// if redeemScript given and not using the local wallet (private keys
// given), add redeemScript to the tempKeystore so it can be signed:
if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) {
RPCTypeCheckObj(prevOut, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM)("scriptPubKey", UniValue::VSTR)("redeemScript",UniValue::VSTR));
UniValue v = find_value(prevOut, "redeemScript");
if (!v.isNull()) {
vector<unsigned char> rsData(ParseHexV(v, "redeemScript"));
CScript redeemScript(rsData.begin(), rsData.end());
tempKeystore.AddCScript(redeemScript);
}
}
}
}
#ifdef ENABLE_WALLET
const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain);
#else
const CKeyStore& keystore = tempKeystore;
#endif
int nHashType = SIGHASH_ALL;
if (params.size() > 3 && !params[3].isNull()) {
static map<string, int> mapSigHashValues =
boost::assign::map_list_of
(string("ALL"), int(SIGHASH_ALL))
(string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY))
(string("NONE"), int(SIGHASH_NONE))
(string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY))
(string("SINGLE"), int(SIGHASH_SINGLE))
(string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY))
;
string strHashType = params[3].get_str();
if (mapSigHashValues.count(strHashType))
nHashType = mapSigHashValues[strHashType];
else
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param");
}
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
// Script verification errors
UniValue vErrors(UniValue::VARR);
// Sign what we can:
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
CTxIn& txin = mergedTx.vin[i];
const CCoins* coins = view.AccessCoins(txin.prevout.hash);
if (coins == NULL || !coins->IsAvailable(txin.prevout.n)) {
TxInErrorToJSON(txin, vErrors, "Input not found or already spent");
continue;
}
const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey;
txin.scriptSig.clear();
// Only sign SIGHASH_SINGLE if there's a corresponding output:
if (!fHashSingle || (i < mergedTx.vout.size()))
SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
// ... and merge in other signatures:
BOOST_FOREACH(const CMutableTransaction& txv, txVariants) {
txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, txv.vin[i].scriptSig);
}
ScriptError serror = SCRIPT_ERR_OK;
if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker(&mergedTx, i), &serror)) {
TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror));
}
}
示例3: main
int main() {
//assert(freopen("input.txt","r",stdin));
//assert(freopen("output.txt","w",stdout));
scanf("%d", &n);
/*add(root, 1);
add(root, 4);
add(root, 5);
add(root, 7);
while (true) {
int x;
cin >> x;
if (!x)
break;
cout << numG(root, x) << endl;
}
while (true) {
int x;
cin >> x;
if (!x)
break;
cout << numL(root, x) << endl;
}*/
/*for (int i = 1; i < 15; i++)
t[i] = i; */
for (int i = 1; i <= n; i++) {
int a, b;
scanf("%d %d", &a, &b);
if (ind.count(a) == 0)
ind[a] = a;
if (ind.count(b) == 0)
ind[b] = b;
swap(ind[a], ind[b]);
//swap(t[a], t[b]);
}
/*int cc = 0;
for (int i = 1; i < 15; i++)
for (int j = i + 1; j < 15; j++)
if (t[i] > t[j])
cc++;
cout << cc << endl;*/
for (map <int, int> :: iterator it = ind.begin(); it != ind.end(); it++) {
v.push_back(make_pair(it->first, it->second));
}
int prev = -1;
for (int i = 0; i < (int) v.size(); i++) {
int pos = v[i].first;
int cur = v[i].second;
if (prev != -1) {
int from = prev + 1, to = pos - 1;
if (to >= from) {
//cout << "F " << from << " " << to << " " << numG(root, from) << endl;
long long add = 1ll * numG(root, from) * (to - from + 1);
//cout << add << endl;
ans += add;
}
}
ans += numG(root, cur);
prev = pos;
add(root, cur);
}
root = NULL;
prev = -1;
for (int i = v.size() - 1; i >= 0; i--) {
int pos = v[i].first;
int cur = v[i].second;
if (prev != -1) {
int from = pos + 1, to = prev - 1;
if (to >= from) {
long long add = 1ll * numL(root, from) * (to - from + 1);
//cout << add << endl;
ans += add;
}
}
prev = pos;
add(root, cur);
}
cout << ans << endl;
return 0;
}
示例4: main
int main()
{
//freopen("in","r",stdin);
scanf("%d", &n);
Point source, sink;
source.init(); sink.init();
for (int i = 0; i < n; ++i) {
Point s, e;
s.init(); e.init();
if (e < s) swap(s, e);
segment[i] = Segment(s, e);
}
sort(segment, segment + n);
for (int i = 0; i < n; ++i) if (!hide[i]) {
interval[i].push_back(segment[i]);
for (int j = i + 1; j < n; ++j) if (!hide[j] && is_segment_same(segment[i], segment[j])) {
hide[j] = 1;
if (segment[j].s == interval[i][interval[i].size() - 1].e) {
interval[i][interval[i].size() - 1].e = segment[j].e;
} else {
interval[i].push_back(segment[j]);
}
}
}
//for (Segment p : interval[1]) printf("%.3f %.3f\n", p.s.x, p.s.y);
vector<int> que;
for (int i = 0; i < n; ++i) if (!hide[i]) {
que.clear();
for (int j = 0; j < n; ++j) if (i != j && !hide[j]) {
if (parallel(segment[i], segment[j])) continue;
Point p = get_intersect(segment[i], segment[j]);
que.push_back(count(p));
}
sort(que.begin(), que.end(), cmp);
int m = unique(que.begin(), que.end()) - que.begin();
//vector<Segment> :: iterator cur = interval[i].begin();
for (int k = 0; k < m - 1; ++k) {
int a = que[k];
int b = que[k+1];
edges[a].push_back(b);
edges[b].push_back(a);
// printf("%d\n", cur == interval[i].end());
//while (cur != interval[i].end() && cur->e < que[k]) ++cur;
// printf("%d\n", cur == interval[i].end());
for (vector<Segment> :: iterator cur = interval[i].begin(); cur != interval[i].end(); ++cur)
if (is_contains(*cur, Segment(point[que[k]], point[que[k+1]]))) weight[MP(a, b)] = weight[MP(b, a)] = 1;
}
}
int s = 0;
int t = 0;
for (int u = 0; u < total; ++u) {
for (int v : edges[u]) if (!vis.count(MP(u, v))) {
vis.insert(MP(u, v));
list.clear();
list.push_back(u);
bool can = dfs(v, u, u);
// for (int x : list) printf("%d ", x); printf("\n");
if (can) {
// if (list.size() < 3) while(1);
++area;
list.push_back(list[0]);
if (s == 0) s = point_location(source, area);
if (t == 0) t = point_location(sink, area);
for (int i = 0; i < (int) list.size() - 1; ++i) {
// assert(!belong.count(MP(list[i], list[i+1])));
// assert(!belong.count(MP(list[i+1], list[i])) || belong[MP(list[i+1], list[i])] != area);
belong[MP(list[i], list[i+1])] = area;
}
/*
for (int x = 0; x < (int) list.size() - 1; ++x)
for (int y = 0; y < (int) list.size() - 1; ++y)
assert(MP(list[x], list[x+1]) != MP(list[y+1], list[y]));
*/
} else {
for (int i = 0; i < (int) list.size() - 1; ++i) {
belong[MP(list[i], list[i+1])] = 0;
}
}
}
}
for (int u = 0; u < total; ++u) {
for (int v : edges[u]) {
// assert(u != v);
int a = belong[MP(u, v)];
int b = belong[MP(v, u)];
// assert(belong.count(MP(u, v)));
// assert(belong.count(MP(v, u)));
// assert(a != b || a == 0 || b == 0);
//if (a == b && a != 0) while(1);
int w = weight.count(MP(u,v)) ? weight[MP(u,v)] : 0;
gragh[a].push_back(MP(b, w));
//gragh[b].push_back(MP(a, w));
}
}
printf("%d\n", dijkstra(s, t));
//.........这里部分代码省略.........
示例5: ParseHashUO
uint256 ParseHashUO(map<string,UniValue>& o, string strKey)
{
if (!o.count(strKey))
return uint256();
return ParseHashUV(o[strKey], strKey);
}
示例6: strName
CScript
ParseScript(string s)
{
CScript result;
static map<string, opcodetype> mapOpNames;
if (mapOpNames.size() == 0)
{
for (int op = OP_NOP; op <= OP_NOP10; op++)
{
const char* name = GetOpName((opcodetype)op);
if (strcmp(name, "OP_UNKNOWN") == 0)
continue;
string strName(name);
mapOpNames[strName] = (opcodetype)op;
// Convenience: OP_ADD and just ADD are both recognized:
replace_first(strName, "OP_", "");
mapOpNames[strName] = (opcodetype)op;
}
}
vector<string> words;
split(words, s, is_any_of(" \t\n"), token_compress_on);
BOOST_FOREACH(string w, words)
{
if (all(w, is_digit()) ||
(starts_with(w, "-") && all(string(w.begin()+1, w.end()), is_digit())))
{
// Number
int64 n = atoi64(w);
result << n;
}
else if (starts_with(w, "0x") && IsHex(string(w.begin()+2, w.end())))
{
// Raw hex data, inserted NOT pushed onto stack:
std::vector<unsigned char> raw = ParseHex(string(w.begin()+2, w.end()));
result.insert(result.end(), raw.begin(), raw.end());
}
else if (w.size() >= 2 && starts_with(w, "'") && ends_with(w, "'"))
{
// Single-quoted string, pushed as data. NOTE: this is poor-man's
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
std::vector<unsigned char> value(w.begin()+1, w.end()-1);
result << value;
}
else if (mapOpNames.count(w))
{
// opcode, e.g. OP_ADD or OP_1:
result << mapOpNames[w];
}
else
{
BOOST_ERROR("Parse error: " << s);
return CScript();
}
}
return result;
}
示例7: is_d_written
int is_d_written(unsigned int addr)
{
return g_map_d_written.count(addr) > 0;
}
示例8: GetArg
int64_t GetArg(const std::string& strArg, int64_t nDefault)
{
if (mapArgs.count(strArg))
return atoi64(mapArgs[strArg]);
return nDefault;
}
示例9: input
bool input() {
for(int i=0;i<100;i++)for(int j=0;j<100;j++) unitmap[i][j]=0;
remainingTime = nextInt();
int currentStage = nextInt();
currentTurn = nextInt();
if (currentTurn == 0) {
// ターンをまたいで維持される変数はステージが新しくなった時点で初期化を行う。
stageStart();
// ステージが始まったことをデバッnグ出力。
// (クライアントで実行すると標準エラー出力は ./log/io/ 配下にログが出力される)
cerr << "stage:" << currentStage << endl;
}
currentResource = nextInt();
{
// 自分のユニットを読み込み。
map<int, Unit> mp;
int myNum = nextInt();
for (int i = 0; i < myNum; i++) {
int id = nextInt();
// 前ターンから知っているユニットはそのまま使う。
// (ユニットに設定した命令がターンをまたいでも引き継がれる実装)
Unit u;
if (myUnits.count(id) > 0) u = myUnits[id];
u.id = id;
u.y = nextInt();
u.x = nextInt();
unitmap[u.y][u.x] = 1;
u.hp = nextInt();
u.type = nextInt();
mp[id] = u;
if (u.type == CASTLE) {
myCastle = u;
// 城が左上と右下のコーナーどちらに近いかで 1P側・2P側を判断
isTopLeft = dist(myCastle.y, myCastle.x, 0, 0) < dist(myCastle.y, myCastle.x, 99, 99);
}else if(u.type == WORKER_FACTORY) workerFactoryMap[u.y][u.x] = true;
// 一度でも視界に入ったことがあるマスを更新
int view = VIEW_RANGE[u.type];
for (int sy = u.y - view; sy <= u.y + view; sy++)
for (int sx = u.x - view; sx <= u.x + view; sx++)
if (0 <= sy && sy < 100 && 0 <= sx && sx < 100 && dist(u.y, u.x, sy, sx) <= view)
see[sy][sx] = true;
}
// 死んだユニットをリストから除くため新しい map に追加して、置き換える。
map<int, Unit> mp1 = myUnits;
myUnits = mp;
if(mp1.size() != 0){
for(map<int, Unit>::iterator it = mp1.begin(); it != mp1.end(); it++) {
Unit u = it->second;
if(myUnits.count(u.id) == 0 && u.type == WORKER && !(u.cellNum == -1) && insCellMap[u.cellNum.y][u.cellNum.x] != 0)insCellMap[u.cellNum.y][u.cellNum.x]--;
}
}
}
{
// 敵のユニットを読み込み
map<int, Unit> mp;
int opNum = nextInt();
for (int i = 0; i < opNum; i++) {
int id = nextInt();
Unit u;
if (opUnits.count(id) > 0) u = opUnits[id];
u.id = id;
u.y = nextInt();
u.x = nextInt();
unitmap[u.y][u.x] = -1;
u.hp = nextInt();
u.type = nextInt();
mp[id] = u;
if (u.type == CASTLE) opCastle = u;
}
opUnits = mp;
}
{
// 資源の位置を読み込み
int resNum = nextInt();
resourcePoint.clear();
resourceFreePoint.clear();
resourceEmenyPoint.clear();
for (int i = 0; i < resNum; i++) {
int y = nextInt();
int x = nextInt();
point p;
bool flag=false;
p.x = x;
p.y = y;
if(isTopLeft){
if(dist(p.y,p.x,0,0) < 100){
for(auto i:resourceNearMyPoint){
if(p.x == i.x && p.y == i.y) flag=true;
}
if(!flag)resourceNearMyPoint.push_back(p);
}else if(dist(p.y,p.x,99,99) < 100){
for(auto i:resourceNearEmenyPoint){
if(p.x == i.x && p.y == i.y) flag=true;
}
if(!flag)resourceNearEmenyPoint.push_back(p);
}
}else{
if(dist(p.y,p.x,0,0) < 100){
//.........这里部分代码省略.........
示例10: solve
void solve() {
id.clear();
int nextId = 0;
string startStr, finishStr;
cin >> startStr >> finishStr;
assert(startStr != finishStr);
start = id[startStr] = nextId++;
finish = id[finishStr] = nextId++;
int trainCount; cin >> trainCount;
for (int i = 0; i < trainCount; ++i) {
string from, to; int m, t, p, d;
cin >> from >> to >> m >> t >> p >> d;
Train train;
train.to = id.count(to) ? id[to] : (id[to] = nextId++);
train.from = id.count(from) ? id[from] : (id[from] = nextId++);
train.departure = m;
train.duration = t;
train.probability = p / 100.0;
train.delay = d;
incoming[train.to].push_back(train);
}
int n = nextId;
for (int t = 0; t < 60; ++t) {
for (int i = 0; i < n; ++i) {
E[i][t] = 1e100;
}
E[finish][t] = 0.0;
}
priority_queue< pair<double, pair<int, int> > > q;
q.push( make_pair(0.0, make_pair(finish, 0)) );
while (q.size() > 0) {
double w = -q.top().first;
int v = q.top().second.first;
int arrivalTime = q.top().second.second;
q.pop();
if (cmp(w, E[v][arrivalTime]) > 0) continue;
for (int k = 0; k < incoming[v].size(); ++k) {
const Train &train = incoming[v][k];
assert(train.to == v);
int u = train.from;
for (int t = 0; t < 60; ++t) {
double e = expectedTrip(u, t, train);
if (cmp(e, E[u][t]) < 0) {
E[u][t] = e;
q.push( make_pair(-e, make_pair(u, t)) );
}
}
}
}
double ans = 1e100;
for (int t = 0; t < 60; ++t) {
ans = min(ans, E[start][t]);
}
if (ans < 10e20) {
printf("%.10lf\n", ans);
} else {
printf("IMPOSSIBLE\n");
}
for (int i = 0; i < nextId; ++i) {
incoming[i].clear();
}
}
示例11: main
int main() {
int cases;
cin >> cases;
for(int test = 1; test <= cases; test++) {
int edge, query;
cin >> edge >> query >> ws;
nodes.clear();
for(int i= 0; i < edge; i++) {
string authors, title;
getline(cin, authors, ':');
getline(cin, title);
vector<string> splitted;
istringstream iss(authors.c_str());
string split;
bool firstone = true;
while(getline(iss, split, ',')) {
if(firstone)
splitted.push_back(split);
else
splitted.push_back(split.substr(1));
firstone = false;
}
vector<string> names;
for(int j = 0; j < splitted.size() - 1; j +=2) {
names.push_back(splitted[j] + ", " + splitted[j+1]);
}
for(int j= 0; j < names.size(); j++) {
for(int k = j+1; k < names.size(); k++) {
string side1 = names[j];
string side2 = names[k];
if(nodes.count(side1) == 0) {
vector<string> side1adj;
side1adj.push_back(side2);
Node each(side1, side1adj);
nodes[side1] = each;
} else {
nodes[side1].adj.push_back(side2);
}
if(nodes.count(side2) == 0) {
vector<string> side2adj;
side2adj.push_back(side1);
Node each(side2, side2adj);
nodes[side2] = each;
} else {
nodes[side2].adj.push_back(side1);
}
}
}
}
bfs("Erdos, P.");
visited.clear();
cout << "Scenario " << test << endl;
for(int i = 0; i < query; i++) {
string querys;
getline(cin, querys);
if(nodes.count(querys) == 0 || nodes[querys].degree == -1)
cout << querys << " infinity" << endl;
else
cout << querys << " " << nodes[querys].degree << endl;
}
}
return 0;
}
示例12: ParseScript
CScript ParseScript(const std::string& s)
{
CScript result;
static map<string, opcodetype> mapOpNames;
if (mapOpNames.empty())
{
for (int op = 0; op <= OP_NOP10; op++)
{
// Allow OP_RESERVED to get into mapOpNames
if (op < OP_NOP && op != OP_RESERVED)
continue;
const char* name = GetOpName((opcodetype)op);
if (strcmp(name, "OP_UNKNOWN") == 0)
continue;
string strName(name);
mapOpNames[strName] = (opcodetype)op;
// Convenience: OP_ADD and just ADD are both recognized:
boost::algorithm::replace_first(strName, "OP_", "");
mapOpNames[strName] = (opcodetype)op;
}
}
vector<string> words;
boost::algorithm::split(words, s, boost::algorithm::is_any_of(" \t\n"), boost::algorithm::token_compress_on);
for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w)
{
if (w->empty())
{
// Empty string, ignore. (boost::split given '' will return one word)
}
else if (all(*w, boost::algorithm::is_digit()) ||
(boost::algorithm::starts_with(*w, "-") && all(string(w->begin()+1, w->end()), boost::algorithm::is_digit())))
{
// Number
int64_t n = atoi64(*w);
result << n;
}
else if (boost::algorithm::starts_with(*w, "0x") && (w->begin()+2 != w->end()) && IsHex(string(w->begin()+2, w->end())))
{
// Raw hex data, inserted NOT pushed onto stack:
std::vector<unsigned char> raw = ParseHex(string(w->begin()+2, w->end()));
result.insert(result.end(), raw.begin(), raw.end());
}
else if (w->size() >= 2 && boost::algorithm::starts_with(*w, "'") && boost::algorithm::ends_with(*w, "'"))
{
// Single-quoted string, pushed as data. NOTE: this is poor-man's
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
std::vector<unsigned char> value(w->begin()+1, w->end()-1);
result << value;
}
else if (mapOpNames.count(*w))
{
// opcode, e.g. OP_ADD or ADD:
result << mapOpNames[*w];
}
else
{
throw runtime_error("script parse error");
}
}
return result;
}
示例13: WriteHalos
int Fluidity::WriteHalos(const string& filename, const unsigned int& process, const unsigned int& nprocs, const map<int, int>& npnodes, const map<int, vector<vector<int> > >& send, const map<int, vector<vector<int> > >& recv){
#ifdef DDEBUG
// Input check
assert(process < nprocs);
assert(send.size() == recv.size());
for(map<int, vector<vector<int> > >::const_iterator sendIter = send.begin(), recvIter = recv.begin();sendIter != send.end() and recvIter != recv.end(), recvIter != recv.end();sendIter++, recvIter++){
assert(recv.count(sendIter->first) != 0);
assert(npnodes.count(sendIter->first) != 0);
assert(sendIter->second.size() == recvIter->second.size());
}
#endif
TiXmlDocument doc;
ostringstream buffer;
// XML header
TiXmlDeclaration* header = new TiXmlDeclaration("1.0", "utf-8", "");
doc.LinkEndChild(header);
// Add root node
TiXmlElement* rootEle = new TiXmlElement("halos");
doc.LinkEndChild(rootEle);
// Add process attribute to root node
buffer << process;
rootEle->SetAttribute("process", buffer.str());
buffer.str("");
// Add nprocs attribute to root node
buffer << nprocs;
rootEle->SetAttribute("nprocs", buffer.str());
buffer.str("");
// Add halo data for each level
map<int, int>::const_iterator npnodesIter = npnodes.begin();
for(map<int, vector<vector<int> > >::const_iterator sendLevelIter = send.begin(), recvLevelIter = recv.begin();sendLevelIter != send.end() and recvLevelIter != recv.end() and npnodesIter != npnodes.end();sendLevelIter++, recvLevelIter++, npnodesIter++){
// Add halo element to root element
TiXmlElement* haloEle = new TiXmlElement("halo");
rootEle->LinkEndChild(haloEle);
// Add level attribute to halo element
buffer << sendLevelIter->first;
haloEle->SetAttribute("level", buffer.str());
buffer.str("");
// Add n_private_nodes attribute to halo element
buffer << npnodesIter->second;
haloEle->SetAttribute("n_private_nodes", buffer.str());
buffer.str("");
// Add halo data for each process for each level
int j = 0;
for(vector<vector<int> >::const_iterator sendProcIter = sendLevelIter->second.begin(), recvProcIter = recvLevelIter->second.begin();sendProcIter != sendLevelIter->second.end() and recvProcIter != recvLevelIter->second.end();sendProcIter++, recvProcIter++, j++){
if(j == (int)nprocs){
break;
}
// Add halo_data element to halo element
TiXmlElement* dataEle = new TiXmlElement("halo_data");
haloEle->LinkEndChild(dataEle);
// Add process attribute to data element
buffer << j;
dataEle->SetAttribute("process", buffer.str());
buffer.str("");
// Add send data to data element
TiXmlElement* sendDataEle = new TiXmlElement("send");
dataEle->LinkEndChild(sendDataEle);
// Add data to send data element
for(vector<int>::const_iterator sendDataIter = sendProcIter->begin();sendDataIter != sendProcIter->end();sendDataIter++){
buffer << *sendDataIter << " ";
}
TiXmlText* sendData = new TiXmlText(buffer.str());
sendDataEle->LinkEndChild(sendData);
buffer.str("");
// Add receive data to data element
TiXmlElement* recvDataEle = new TiXmlElement("receive");
dataEle->LinkEndChild(recvDataEle);
// Add data to receive data element
for(vector<int>::const_iterator recvDataIter = recvProcIter->begin();recvDataIter != recvProcIter->end();recvDataIter++){
buffer << *recvDataIter << " ";
}
TiXmlText* recvData = new TiXmlText(buffer.str());
recvDataEle->LinkEndChild(recvData);
buffer.str("");
}
}
return doc.SaveFile(filename) ? 0 : -1;
}
示例14: theSignalHandlerProc
void theSignalHandlerProc(int signum)
{
assert(sigHandlers.count(signum) != 0);
assert(!sigHandlers[signum].empty());
sigHandlers[signum].back()->OnRaise(signum);
}
示例15: findLastCant
int findLastCant(const map<int, int> &S){
int i = 0;
while (S.count(i)) i++;
return i;
}