本文整理汇总了C++中unordered_map::end方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::end方法的具体用法?C++ unordered_map::end怎么用?C++ unordered_map::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char** argv)
{
log.execname (basename (argv[0]));
log << "starting" << endl;
vector<string> args (&argv[1], &argv[argc]);
//Print a usage error if the there are too many input commands
if (args.size() > 2) usage();
//Otherwise get the host and port from daemon
string host = get_cix_server_host (args, 0);
in_port_t port = get_cix_server_port (args, 1);
//Begin to parse the input lines
if (args.size() == 1)
{////
string prog_name = args[0];
size_t rc_find = prog_name.find(".");
//Case unable to find server name
if(rc_find == string::npos)
{
host = get_cix_server_host (args,1);
port = get_cix_server_port (args,0);
}
//Case: found server name
else
{
host = get_cix_server_host (args,0);
port = get_cix_server_port (args,1);
}
}
//Case: Default, run with args 0, args 1
else
{
host = get_cix_server_host (args, 0);
port = get_cix_server_port (args, 1);
}
log << to_string (hostinfo()) << endl;
//Starter code: try to connect
try
{
log << "connecting to " << host << " port " << port << endl;
client_socket server (host, port);
log << "connected to " << to_string (server) << endl;
//Infinite loop, prog_name input from cin and parse it
for (;;) {
string line;
getline (cin, line);
if (cin.eof()) throw cix_exit();
if (SIGINT_throw_cix_exit) throw cix_exit();
//Begin to make
//Minor loop, cleans input from cin
size_t end = 0;
vector<string> cleaned_line;
for (;;)
{
size_t start = line.find_first_not_of (" \t", end);
if (start == string::npos) break;
end = line.find_first_of (" \t", start);
cleaned_line.push_back (line.substr (start, end - start));
}
//If there is nothing there, then continue through
if(cleaned_line.size() == 0)
{
continue;
}
//Log the command and find it in the map
log << "command " << cleaned_line[0] << endl;
const auto& itor = command_map.find (cleaned_line[0]);
cix_command cmd = itor == command_map.end()
? CIX_ERROR : itor->second;
//Switch depending on the command type
switch (cmd) {
case CIX_EXIT:
throw cix_exit();
break;
case CIX_HELP:
cix_help();
break;
case CIX_LS:
cix_ls (server);
break;
case CIX_GET:
//Check for invalid get command
if(cleaned_line.size() < 2)
{
cout << "Error: Invalid arguments to: get" << endl;
break;
}
cix_get (server, cleaned_line[1]);
break;
case CIX_PUT:
//.........这里部分代码省略.........
示例2: gao_test
// from train_cat_item_item to find better match one
void gao_test(char * test_file_txt, char * output_file_txt){
fstream item_online_test_file(test_file_txt);
ofstream item_output_file(output_file_txt);
double st = clock();
int now = 0, SHOW = 1;
LL test_item;
while(item_online_test_file >> test_item){
vector<PDL> ans;
unordered_map<LL, bool> has;
LL bias = 100000;
double sstt = clock();
if(now++ % SHOW == 0)
cerr<<"now:\t"<<now<<endl;
// add most buyers for first choice
vector<PLL> vec_buyer;// (buyertimes, item)
unordered_map<LL, int> item_bought_times;
vector<LL> & buyers = item_buyers[test_item];
cerr<<"check buyer number = "<<buyers.size()<<endl;
for(int i = 0; i < buyers.size(); i++){
LL buyer = buyers[i];
vector<LL> & bought_items = buyer_items[buyer];
for(int j = 0; j < bought_items.size(); j++){
LL another_item = bought_items[j];
if (another_item == test_item)
continue;
LL aic = item_cat[another_item],
tic = item_cat[test_item];
//if(cat_cat_map[haxi(aic, tic)]) // if logical reasonable, cat-cat can be matched
if(cat_cat_map.find(haxi(aic, tic)) != cat_cat_map.end())
item_bought_times[another_item]++;
}
}
for(unordered_map<LL, int>::iterator it = item_bought_times.begin(); it != item_bought_times.end(); it++){
vec_buyer.push_back(PLL(it->second, it->first));
}
sort(vec_buyer.begin(), vec_buyer.end());
reverse(vec_buyer.begin(), vec_buyer.end());
int sz = vec_buyer.size(), max_bought = 0;
if (sz > 0){
cerr<<"max buyer number:\t"<<vec_buyer[0].first<<"\tmaxitem:\t"<<vec_buyer[0].second<<"\tmin buyer number:\t"<<vec_buyer[sz - 1].first<<"\tminitem:\t"<<vec_buyer[sz - 1].second<<endl;
max_bought = vec_buyer[0].first;
}
for(int i = 0; i < vec_buyer.size(); i++){
if((int)ans.size() >= OUTNUM)
break;
LL item = vec_buyer[i].second;
int times = vec_buyer[i].first;
if(max_bought > 1 && times == 1) continue;
ans.push_back(PLL(bias * times, item));
has[item] = true;
}
cerr<<"total item bought number = "<<ans.size()<<endl;
// prob similarity search
LL test_item_cat = item_cat[test_item];
vector<PLL> &vp = train_cat_item_item[test_item_cat];
vector<double> prob_left(vp.size());
vector<vector<PDL> > vvp(vp.size());
for (int i = 0; i < vp.size(); i++){
vvp[i] = same[vp[i].second];
prob_left[i] = similarity(test_item, vp[i].first);
}
vector<int> pt(vvp.size(), 0);
for (int c = 0; ; c++){
if((int)ans.size() >= OUTNUM)
break;
int w = -1;
double max_prob = -1111111;
LL choose_item = -1;
bool check = false;
for(int i = 0; i < vvp.size(); i++){
int p = pt[i];
vector<PDL>& vpdl = vvp[i];
if (p >= (int) vpdl.size()) continue;
check = true;
double prob = prob_left[i] * vpdl[p].first;
if (prob > max_prob){
max_prob = prob;
w = i;
choose_item = vpdl[p].second;
}
}
if(check == false) break;
pt[w]++;
if(has.find(choose_item) == has.end()){
ans.push_back(PDL(max_prob, choose_item));
has[choose_item] = true;
}
}
// sometime no need to sort
//sort(ans.begin(), ans.end());
//reverse(ans.begin(), ans.end());
//.........这里部分代码省略.........
示例3: DataKmerCount
unsigned long DataKmerCount(char* combinefileName, char* outputFileDir, char* shortName, int k, unsigned long power, bool doubleStrand, bool zeroCountOut)
{
// Initialize total_DataNum. total_DataNum records the total number of kmer in rth dataset
unsigned long total = 0;
ifstream fin(combinefileName); //EDIT fin(argv[1])
// unsigned long copynumber;
// cout << "begin scan" << endl;
// Begin to scan lines in dataset from top to the bottom
// countKmer ONLY for single strand
while(fin.getline(seq,seqlength))
{
//cout << seq << endl;
if (doubleStrand == false) {
// sinlge strand
total += SeqKmerCountSingle(seq, k, power);
// cout << "seq" << endl;
}else{
// double strand
total += SeqKmerCount(seq, k, power);
}
}
cout << "total characters: " << total << endl;
fin.close();
// Output kmer count-pw files
char kstr[5]; sprintf(kstr, "%d", k);
char kmerCountfile[1000];
if (outputFileDir == NULL) {
strcpy(kmerCountfile,shortName);
strcat(kmerCountfile,"_k");
strcat(kmerCountfile,kstr);
}else{
strcpy(kmerCountfile,outputFileDir);
strcat(kmerCountfile,shortName);
strcat(kmerCountfile,"_k");
strcat(kmerCountfile,kstr);
}
if (doubleStrand == false) {
// single strand
strcat(kmerCountfile,"_ss_wc");
}else{
strcat(kmerCountfile,"_ds_wc");
}
cout << "kmerCountFileName: " << kmerCountfile << endl;
ofstream foutKmerCount(kmerCountfile);
if (zeroCountOut == false) {
// only output those occurring
// Sort the kmer
vector<unsigned long> temp;
for( unordered_map<unsigned long,unsigned long>::iterator i = HashTable.begin(); i!= HashTable.end(); i++) temp.push_back(i->first);
sort(temp.begin(), temp.end());
// print
for(vector<unsigned long>::iterator j = temp.begin(); j!=temp.end(); j++)
{
unsigned long key = *j;
foutKmerCount << key << "," << HashTable[key] << endl;
}
}else {
// output all kmers
for(unsigned long key = 0; key < pow(4,k); key++)
{
foutKmerCount << key << "," << HashTable[key] << endl;
}
}
foutKmerCount.close();
return total;
}
示例4: ProcessDLLData
void ProcessDLLData(const wchar_t *filename, const wstring &mod_dir)
{
const IniFile *const dlldata = new IniFile(filename);
const IniGroup *group;
wstring dllname = dlldata->getWString("", "name");
HMODULE dllhandle;
if (dllhandles.find(dllname) != dllhandles.cend())
dllhandle = dllhandles[dllname];
else
{
dllhandle = GetModuleHandle(dllname.c_str());
dllhandles[dllname] = dllhandle;
}
if (dllexports.find(dllname) == dllexports.end())
{
group = dlldata->getGroup("Exports");
dllexportcontainer exp;
for (auto iter = group->cbegin(); iter != group->cend(); ++iter)
{
dllexportinfo inf;
inf.address = GetProcAddress(dllhandle, iter->first.c_str());
inf.type = iter->second;
exp.exports[iter->first] = inf;
}
dllexports[dllname] = exp;
}
const auto exports = &dllexports[dllname].exports;
dlltexlists.clear();
if (dlldata->hasGroup("TexLists"))
{
group = dlldata->getGroup("TexLists");
for (auto iter = group->cbegin(); iter != group->cend(); ++iter)
{
NJS_TEXLIST *key = (NJS_TEXLIST*)std::stoul(iter->first, nullptr, 16);
vector<string> valstr = split(iter->second, ',');
NJS_TEXLIST *value;
if (valstr.size() > 1)
value = ((NJS_TEXLIST**)(*exports)[valstr[0]].address)[std::stoul(valstr[1])];
else
value = (NJS_TEXLIST*)(*exports)[valstr[0]].address;
dlltexlists[key] = value;
}
}
dlllabels.clear();
group = dlldata->getGroup("Files");
for (auto iter = group->cbegin(); iter != group->cend(); ++iter)
{
auto type = dllfilefuncmap.find(split(iter->second, '|')[0]);
if (type != dllfilefuncmap.end())
type->second(mod_dir + L'\\' + MBStoUTF16(iter->first, CP_UTF8));
}
char buf[16];
for (unsigned int k = 0; k < 9999; k++)
{
snprintf(buf, sizeof(buf), "Item%u", k);
if (dlldata->hasGroup(buf))
{
group = dlldata->getGroup(buf);
const dllexportinfo &exp = (*exports)[group->getString("Export")];
auto type = dlldatafuncmap.find(exp.type);
if (type != dlldatafuncmap.end())
type->second(group, exp.address);
}
}
delete dlldata;
}
示例5:
bool isPowerOfThree01(int n) {
static unordered_map<int, bool> power;
if (power.size()==0) init(power);
return power.find(n) != power.end();
}
示例6: isUnique
bool isUnique(string word) {
string key = word.length()<3 ? word : word[0]+to_string(word.length()-2)+word[word.length()-1];
if(abbr.find(key)==abbr.end() || (abbr[key]==1 && dict[word])) return true;
else return false;
}
示例7: enregistrerLRUinterne
static int enregistrerLRUinterne(unsigned int *w,int tempo) {
static int vcardinal=0;
static int atempo=-1;
if (atempo!= tempo) {
vcardinal=cardinal;
fprintf(stderr,"LRU cache taille :%d sentence:%d card:%d h:%d old:%d new%d \n",lru_count,atempo,cardinal,hit,older,newer);
lru_count=0;
hit=0;
atempo=tempo;
}
hit++;
ram[0].w=w;
unordered_map <Pgram,int,hash_X ,hash_X>::iterator j =cache.find(ram);
// dump(cache,"in passe1");
if (j!= cache.end()) {
int p=j->second;
if (ram[p].tempo>=tempo) return -1;
ram[p].tempo=tempo;
if (p==newer) return -1;
if (older!=p) {
ram[ram[p].older].newer = ram[p].newer;
ram[ram[p].newer].older=ram[p].older;}
else {
ram[ram[p].newer].older=-1;
older=ram[p].newer;
}
assert (older>0);
//assert (older< vcardinal || vcardinal <1000);
ram[p].newer=-1;
ram[p].older=newer;
ram[newer].newer=p;
newer=p;
return -1;
}
lru_count++;
if (cardinal <TAILLEMAX) {
memcpy( ram[cardinal].w,w,ordreMax*sizeof(int));
ram[cardinal].older=newer;
ram[newer].newer=cardinal;
newer=cardinal;
ram[cardinal].tempo=tempo;
ram[cardinal].newer=-1;
cache[ram+cardinal]=cardinal;
cardinal ++;
ram[cardinal-1].val= 3*cardinal;
return cardinal-1;
}
dump(cache,"in pass1 av er");
assert(ram[older].tempo<tempo);
cache.erase(ram+older);
dump(cache,"in passe1 apr er");
memcpy( ram[older].w,w,ordreMax*sizeof(int));
ram[older].tempo=tempo;
ram[older].older=newer;
ram[newer].newer=older;
newer=older;
cache[ram+older]=older;
int tempOlder=older;
older=ram[older].newer;
assert(older>0);
//assert (older< vcardinal || vcardinal <1000);
ram[older].older=-1;
dump(cache,"in passe1 apr ins");
return tempOlder;
}
示例8: dfs
int dfs(TreeNode* node){
if(!node) return INT_MIN;
if(mps.find(node) != mps.end()) return mps[node];
int ret = node->val+max(0,max(dfs(node->left),dfs(node->right)));
mps[node] = ret; return ret;
}
示例9: do_command
void do_command(char *command_c, int client)
{
string command = command_c;
string output;
vector<string> tokens;
try {
tokens = tokenize(command);
} catch (...) {
server_send(client, "404 COMMAND NOT FOUND\n");
return;
}
if (tokens[0] == "SHORTEST_PATH_A2A") {
if ((tokens.size() < 3) || !bitcoin_address_quick_valid(tokens[1]) ||
!bitcoin_address_quick_valid(tokens[2])) {
server_send(client, "500 Arguments error.\n");
return;
}
output = find_path(tokens[1], tokens[2]);
if (!output.empty()) {
server_send(client, "BEGIN\n");
server_send(client, output);
server_send(client, "END\n");
} else {
server_send(client, "500 No path.\n");
}
return;
} else if (tokens[0] == "SUCCESSORS") {
if (tokens.size() < 2) {
server_send(client, "500 Arguments error.\n");
return;
}
server_send(client, "BEGIN\n");
unordered_set<string> successors = find_successors(tokens[1]);
if (!successors.empty()) {
for (auto& it : successors) {
output += it + ",";
}
/* Remove last character (,) */
try {
output.pop_back();
} catch (...) {
// Do nothing for now.
}
server_send(client, output + "\n");
server_send(client, "END\n");
} else server_send(client, "500 No successors.\n");
return;
} else if (tokens[0] == "PREDECESSORS") {
if ((tokens.size() < 2) || !bitcoin_address_quick_valid(tokens[1])) {
server_send(client, "500 Arguments error.\n");
return;
}
server_send(client, "BEGIN\n");
unordered_set<string> predecessors = find_predecessors(tokens[1]);
if (!predecessors.empty()) {
for (auto& it : predecessors) {
output += it + ",";
}
/* Remove last character (,) */
try {
output.pop_back();
} catch (...) {
// Do nothing for now.
}
server_send(client, output + "\n");
server_send(client, "END\n");
} else server_send(client, "500 No predecessors.\n");
return;
} else if (tokens[0] == "A2A") {
if ((tokens.size() < 3) || !bitcoin_address_quick_valid(tokens[1]) ||
!bitcoin_address_quick_valid(tokens[2])) {
server_send(client, "500 Arguments error.\n");
return;
}
server_send(client, "BEGIN\n");
unordered_set<string> tx_hashes = a2a(tokens[1], tokens[2]);
if (!tx_hashes.empty()) {
for (auto& it : tx_hashes) {
server_send(client, it + "\n");
}
server_send(client, "END\n");
} else server_send(client, "500 No transactions.\n");
return;
} else if (tokens[0] == "A2C") {
//.........这里部分代码省略.........
示例10: DP
dat DP( int len , int s0 , int s1 , int s2 , int k0 , int k1 , int k2 , bool& nok ){
int ee = enc( len , s0 , s1 , s2 , k0 , k1 , k2 );
nok = true;
if( len <= 0 ) return make_tuple( "" , "" , "" );
{
int vl0 = msk[ 0 ][ s0 + len - 1 ] ^ msk[ 0 ][ s0 - 1 ];
int vl1 = msk[ 1 ][ s1 + len - 1 ] ^ msk[ 1 ][ s1 - 1 ];
int vl2 = msk[ 2 ][ s2 + len - 1 ] ^ msk[ 2 ][ s2 - 1 ];
if( vl0 != vl1 or vl0 != vl2 ){
nok = false;
return make_tuple( "" , "" , "" );
}
}
{
auto it = memo.find( ee );
if( it != memo.end() ){
nok = it->second.second;
return it->second.first;
}
}
if( len == 1 ){
string cur = "";
cur += c[ 0 ][ s0 ];
memo[ ee ] = { make_tuple( cur , cur , cur ) , true };
return make_tuple( cur , cur , cur );
}
bool found = false;
dat ret = make_tuple("", "", "");
for( int root = 0 ; root < 26 ; root ++ ){
int at0 = at[ 0 ][ root ];
int at1 = at[ 1 ][ root ];
int at2 = at[ 2 ][ root ];
int s , t;
{
int llen = -1;
if( not check( s0 , len , k0 , at0 , llen ) ) continue;
if( not check( s1 , len , k1 , at1 , llen ) ) continue;
if( not check( s2 , len , k2 , at2 , llen ) ) continue;
s = (llen == -1 ? 0 : llen );
t = (llen == -1 ? len - 1 : llen );
}
for( int llen = s ; llen <= t ; llen ++ ){
int ssl[ 3 ] , kdl[ 3 ];
int ssr[ 3 ] , kdr[ 3 ];
upd( s0 , k0 , llen , ssl[ 0 ] , kdl[ 0 ] , ssr[ 0 ] , kdr[ 0 ] );
upd( s1 , k1 , llen , ssl[ 1 ] , kdl[ 1 ] , ssr[ 1 ] , kdr[ 1 ] );
upd( s2 , k2 , llen , ssl[ 2 ] , kdl[ 2 ] , ssr[ 2 ] , kdr[ 2 ] );
bool cok;
dat lret = DP( llen , ssl[ 0 ] , ssl[ 1 ] , ssl[ 2 ] ,
kdl[ 0 ] , kdl[ 1 ] , kdl[ 2 ] , cok );
if( not cok ) continue;
dat rret = DP( len - llen - 1 , ssr[ 0 ] , ssr[ 1 ] , ssr[ 2 ] ,
kdr[ 0 ] , kdr[ 1 ] , kdr[ 2 ] , cok );
if( not cok ) continue;
dat got;
Pre( got ) = (char)(root + 'A') + Pre( lret ) + Pre( rret );
In( got ) = In( lret ) + (char)(root + 'A') + In( rret );
Post( got ) = Post( lret ) + Post( rret ) + (char)(root + 'A');
if( not found or got < ret ){
found = true;
ret = got;
}
}
}
memo[ ee ] = { ret , found };
nok = found;
return ret;
}
示例11: main
int main() {
sae::io::vid_t gvid = 0, geid = 0;
// GraphBuilder is not efficient for this kind of large data.
cerr << "graph builder..." << endl;
sae::io::GraphBuilder<uint64_t> builder;
builder.AddVertexDataType("Author");
builder.AddVertexDataType("Publication");
builder.AddVertexDataType("JConf");
builder.AddEdgeDataType("Publish");
builder.AddEdgeDataType("Appear");
builder.AddEdgeDataType("Influence");
// build Authors
cerr << "building authors..." << endl;
{
ifstream authors_csv("authors.csv");
CSVReader authors_reader(authors_csv);
Author a;
string names;
vector<string> row;
authors_reader.readrow(row); // header
while (authors_reader.readrow(row)) {
a.id = stoi(row[0]);
a.names = split(row[1], ',');
a.position = row[2];
a.affiliation = row[3];
a.imgurl = row[4];
a.topics = split(row[5], ',');
a.h_index = stoi(row[6]);
a.publication_number = stoi(row[7]);
a.citation_number = stoi(row[8]);
aid_map[a.id] = gvid++;
builder.AddVertex(a.id, a, "Author");
}
}
// build Conferences
cerr << "building conferences..." << endl;
{
ifstream jconfs("jconf_name.txt");
JConf j;
while (jconfs >> j.id) {
getline(jconfs >> std::ws, j.name);
jconf_map[j.id] = gvid++;
builder.AddVertex(JCONF_BASE + j.id, j, "JConf");
}
}
// build Publications
cerr << "building publications and appear relations..." << endl;
{
ifstream pubs("publication.txt");
ifstream pub_ext("publication_ext.txt");
ifstream pub_topics("terms_given_publication.txt");
int pid, tmp_id, tmp_pubtopic_id;
string tmp_abstract, tmp_topics;
tmp_id = tmp_pubtopic_id = -1;
while (pubs >> pid) {
Publication p;
p.id = pid;
if (p.id % 10000 == 0) {
cerr << "publication" << p.id << std::endl;
}
getline(pubs.ignore(), p.title, '\t');
pubs >> p.jconf;
pubs >> p.year;
string authors;
getline(pubs.ignore(), authors, '\t'); // unused
string citation_number;
getline(pubs, citation_number);
if (citation_number.size() > 0) {
//cerr << "!!!" << citation_number << endl;
p.citation_number = stoi(citation_number);
} else {
p.citation_number = -1;
}
if (p.id > tmp_id) {
while (pub_ext >> tmp_id) {
getline(pub_ext.ignore(), tmp_abstract);
if (tmp_id >= p.id) break;
}
}
if (p.id > tmp_pubtopic_id) {
while (pub_topics >> tmp_pubtopic_id) {
getline(pub_topics.ignore(), tmp_topics);
if (tmp_id >= p.id) break;
}
}
if (p.id == tmp_id) {
p.abstract = tmp_abstract;
}
//.........这里部分代码省略.........
示例12: detect_known_colorspace
ustring ColorSpaceManager::detect_known_colorspace(ustring colorspace,
const char *file_format,
bool is_float)
{
if (colorspace == u_colorspace_auto) {
/* Auto detect sRGB or raw if none specified. */
if (is_float) {
bool srgb = (colorspace == "sRGB" || colorspace == "GammaCorrected" ||
(colorspace.empty() &&
(strcmp(file_format, "png") == 0 || strcmp(file_format, "tiff") == 0 ||
strcmp(file_format, "dpx") == 0 || strcmp(file_format, "jpeg2000") == 0)));
return srgb ? u_colorspace_srgb : u_colorspace_raw;
}
else {
return u_colorspace_srgb;
}
}
else if (colorspace == u_colorspace_srgb || colorspace == u_colorspace_raw) {
/* Builtin colorspaces. */
return colorspace;
}
else {
/* Use OpenColorIO. */
#ifdef WITH_OCIO
{
thread_scoped_lock cache_lock(cache_colorspaces_mutex);
/* Cached lookup. */
if (cached_colorspaces.find(colorspace) != cached_colorspaces.end()) {
return cached_colorspaces[colorspace];
}
}
/* Detect if it matches a simple builtin colorspace. */
bool is_scene_linear, is_srgb;
is_builtin_colorspace(colorspace, is_scene_linear, is_srgb);
thread_scoped_lock cache_lock(cache_colorspaces_mutex);
if (is_scene_linear) {
VLOG(1) << "Colorspace " << colorspace.string() << " is no-op";
cached_colorspaces[colorspace] = u_colorspace_raw;
return u_colorspace_raw;
}
else if (is_srgb) {
VLOG(1) << "Colorspace " << colorspace.string() << " is sRGB";
cached_colorspaces[colorspace] = u_colorspace_srgb;
return u_colorspace_srgb;
}
/* Verify if we can convert from the requested color space. */
if (!get_processor(colorspace)) {
OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
if (!config || !config->getColorSpace(colorspace.c_str())) {
VLOG(1) << "Colorspace " << colorspace.c_str() << " not found, using raw instead";
}
else {
VLOG(1) << "Colorspace " << colorspace.c_str()
<< " can't be converted to scene_linear, using raw instead";
}
cached_colorspaces[colorspace] = u_colorspace_raw;
return u_colorspace_raw;
}
/* Convert to/from colorspace with OpenColorIO. */
VLOG(1) << "Colorspace " << colorspace.string() << " handled through OpenColorIO";
cached_colorspaces[colorspace] = colorspace;
return colorspace;
#else
VLOG(1) << "Colorspace " << colorspace.c_str() << " not available, built without OpenColorIO";
return u_colorspace_raw;
#endif
}
}
示例13: if
/******************************************************************************
Description.: There is a separate instance of this function
for each connection. It handles all communication
once a connnection has been established.
Input Value.:
Return Value: -
******************************************************************************/
void *serverThread (void * inputsock)
{
int sock = *((int *)inputsock);
int n;
char buffer[100];
string userID;
char *threadType;
char fail[] = "failed";
// Receive the header
bzero(buffer, sizeof(buffer));
if (!orbit)
{
n = read(sock, buffer, sizeof(buffer));
if (n < 0)
{
errorSocket("ERROR reading from socket", sock);
}
}
// below is orbit mode, using MFAPI
else
{
MsgD.recv(sock, buffer, sizeof(buffer));
}
printf("[server] header content: %s\n\n",buffer);
threadType = strtok(buffer, ",");
userID = strtok(NULL, ",");
// grap the lock
pthread_mutex_lock(&user_map_lock);
// confirm that this user does not log in
if (user_map.find(userID) == user_map.end())
{
// put the new user into user map
user_map[userID] = 1;
}
else
{
if (user_map[userID] == 1)
{
// increase user thread count
user_map[userID] = 2;
}
else
{
// remember to unlock!
pthread_mutex_unlock(&user_map_lock);
// reponse to the client
if (!orbit)
{
if (write(sock, "failed", sizeof("failed")) < 0)
{
errorSocket("ERROR writting to socket", sock);
}
close(sock);
}
else
{
MsgD.send(sock, fail, sizeof(fail));
}
printf("[server] User exist. Connection closed.\n\n");
return 0;
}
}
pthread_mutex_unlock(&user_map_lock);
if (strcmp(threadType, "transmit") == 0)
{
server_transmit(sock, userID);
}
else if (strcmp(threadType, "result") == 0)
{
server_result(sock, userID);
}
else
{
if (!orbit)
{
close(sock);
}
printf("[server] Command Unknown. Connection closed.\n\n");
}
return 0;
}
示例14: server_transmit
/******************************************************************************
Description: function for transmitting the frames
Input Value.:
Return Value:
******************************************************************************/
void server_transmit (int sock, string userID)
{
// printf("transmitting part\n");
int n;
char response[] = "ok";
char file_name_temp[60];
char *file_name;
int write_length = 0;
int length = 0;
queue<string> *imgQueue = new queue<string>(); // queue storing the file names
// grap the lock
pthread_mutex_lock(&queue_map_lock);
queue_map[userID] = imgQueue; // put the address of queue into map
pthread_mutex_unlock(&queue_map_lock);
pthread_mutex_t queueLock; // mutex lock for queue operation
sem_t *sem_match = 0;
// init the mutex lock
if (pthread_mutex_init(&queueLock, NULL) != 0)
{
errorSocket("ERROR mutex init failed", sock);
}
if (!orbit)
{
char buffer[BUFFER_SIZE];
char *file_size_char;
int file_size;
int received_size = 0;
// reponse to the client
n = write(sock, response, sizeof(response));
if (n < 0)
{
pthread_mutex_destroy(&queueLock);
errorSocket("ERROR writting to socket", sock);
}
while (!global_stop)
{
received_size = 0;
// receive the file info
bzero(buffer, sizeof(buffer));
n = read(sock,buffer, sizeof(buffer));
if (n <= 0)
{
pthread_mutex_destroy(&queueLock);
// signal the result thread to terminate
sem_post(sem_match);
errorSocket("ERROR reading from socket", sock);
}
// store the file name and the block count
file_name = strtok(buffer, ",");
strcpy(file_name_temp, file_name);
if (debug) printf("\n[server] file name: [%s]\n", file_name);
file_size_char = strtok(NULL, ",");
file_size = strtol(file_size_char, NULL, 10);
if (debug) printf("file size: %d\n", file_size);
// calculate the time consumption here
struct timeval tpstart,tpend;
double timeuse;
gettimeofday(&tpstart,NULL);
// reponse to the client
n = write(sock, response, sizeof(response));
if (n <= 0)
{
pthread_mutex_destroy(&queueLock);
// signal the result thread to terminate
sem_post(sem_match);
errorSocket("ERROR writting to socket", sock);
}
if (!storm)
{
FILE *fp = fopen(file_name, "w");
if (fp == NULL)
{
printf("File:\t%s Can Not Open To Write!\n", file_name);
break;
}
int done = 0;
// receive the data from client and store them into buffer
bzero(buffer, sizeof(buffer));
while((length = recv(sock, buffer, sizeof(buffer), 0)))
{
if (length < 0)
{
//.........这里部分代码省略.........
示例15: getOutput
void getOutput( char* input, char* output, unordered_map<string, MSVS> & mp ){
unordered_map<string, vector<int> > mp_arr; // key is seqname(accession number), map is block indices
set<string> setKeys;
set<string> set_gene_details;
map<string, double > mp_gene_count; // key is geneID + transciptID , value is count
ifstream in;
ofstream out;
int i, index_num_mapping, num_mapping, index_mapping_list, index_host_read ;
string titles, cigar, len_M1, len_N, len_M2, genome_seqname, readLine, gene_count_output, gene_details_output;
// 11M101N40M , len_M1 = 11, len_N = 101, len_M2 = 40
vector<string> vecColumns, vecSamColumns;
int start, end, found, pos, pos_M1, index_read_length, read_length;
stringstream ss;
in.open( input );
out.open( output );
for( auto it = mp.begin() ; it != mp.end() ; ++it ){
vector<int> vec_empty;
mp_arr.insert( make_pair( it->first, vec_empty ) );
fillArr( mp_arr[ it->first ], it->second );
//cout << "seqname is :" << it->first << endl;
//cout << "arr size is :" << mp_arr[ it->first ].size() << endl;
}
// read titles
getline( in, titles );
vecColumns = split( titles, "\t");
index_host_read = getIndexOfColumn( vecColumns, "host_read" ); // MG00HS08:584:C5YUBACXX:6:1309:7776:84081_1:N:0:CAGATC
index_num_mapping = getIndexOfColumn( vecColumns, "#Tophat_Mapping" );
index_read_length = getIndexOfColumn( vecColumns, "host_read_length" );
index_mapping_list = index_num_mapping + 1;
out << titles << "\t#Gene_match\t#host_gene\thost_genes_details" << endl;
int count = 0;
while( getline( in, readLine ) ) {
out << readLine ;
vecColumns = split( readLine, "\t" );
num_mapping = atoi ( vecColumns[ index_num_mapping ].c_str() );
if( num_mapping != 1 ){ // not unique and thus annotation not needed
out << "\t\\\t\\\t\\" << endl;
continue;
}
setKeys.clear();
mp_gene_count.clear();
set_gene_details.clear();
gene_count_output = "\\";
gene_details_output = "\\";
// vecColumns[ index_mapping_list ] : 73,gi|568815578|ref|NC_000020.11|,8174332,50,101M#
vecSamColumns = split( vecColumns[ index_mapping_list ] , "," ) ;
int size = vecSamColumns.size();
cigar = vecSamColumns[ size - 1 ];
size = cigar.length();
cigar = cigar.substr( 0, size - 1 ); // remove # from 101M
found = cigar.find_first_not_of("0123456789MN");
if( found == string::npos ){
pos = cigar.find_first_of ( 'M' );
len_M1 = cigar.substr( 0, pos );
pos_M1 = pos;
pos = cigar.find_first_of ( 'N', pos_M1 + 1 );
if( pos == string::npos )
len_N = "";
else{
len_N = cigar.substr( pos_M1 + 1, pos - pos_M1 );
if ( cigar.find_first_of( 'N', pos + 1 ) != string::npos ) { // more than one N in CIGAR
out << "\t\\\t\\\t\\" << endl;
continue;
}
else
len_M2 = cigar.substr( pos + 1, cigar.size() - 1 - pos );
}
}
else { // not annotate
out << "\t\\\t\\\t\\" << endl;
continue;
}
start = atoi( &vecSamColumns[2][0] );
end = start + atoi( &len_M1[0] ) - 1;
genome_seqname = getSeqname( vecSamColumns[ 1 ] );
read_length = atoi( vecColumns[ index_read_length ].c_str() ) ;
getKeys ( start, end, mp_arr[ genome_seqname ], setKeys );
getGeneCount( start, end, setKeys, mp[ genome_seqname ], mp_gene_count, set_gene_details, vecColumns[index_host_read] );
if ( len_N != "" ){
start = end + atoi( &len_N[0] ) + 1;
end = start + atoi( &len_M2[0] ) -1;
setKeys.clear();
getKeys ( start, end, mp_arr[ genome_seqname ], setKeys );
getGeneCount( start, end, setKeys, mp[ genome_seqname ], mp_gene_count, set_gene_details, vecColumns[index_host_read] );
}
if( mp_gene_count.size() ){
vector<PAIR> vec_gene_count( mp_gene_count.begin(), mp_gene_count.end() );
//.........这里部分代码省略.........