QVariant SuovaFileInfo::information(const QString &key) const { QString shortKey = withoutContext(key); // nie:title --> title if( shortKey == "fileLastAccessed") return accessed(); else if( shortKey == "fileLastModified") return modified(); else if( shortKey == "fileName") return fileName(); else if( shortKey == "fileSize") return bytes(); else if( shortKey == "contentCreated") return created(); else if( shortKey == "isStoredAs") return urn(); else if( shortKey == "mimeType") return mimetype(); else if( shortKey == "title") return title(); else if( shortKey == "url") return url(); return QVariant(); }
void Tracker::send_request(TRACKER_EVENT event ) { m_status = TRACKER_STATUS_UPDATING; std::string urn(m_params); if (urn.find('?') < urn.length()) urn.append("&"); else urn.append("?"); urn.append("info_hash="); urn.append(m_infohash); urn.append("&peer_id="); char peer_id[PEER_ID_LENGTH + 1]; memset(peer_id, 0, PEER_ID_LENGTH + 1); m_g_cfg->get_peer_id(peer_id); urn.append(peer_id); char t[256]; urn.append("&port="); sprintf(t, "%d", m_g_cfg->get_port()); urn.append(t); if (event != TRACKER_EVENT_STARTED) { urn.append("&downloaded="); sprintf(t, "%lld", m_torrent->get_downloaded() - m_downloaded); urn.append(t); urn.append("&uploaded="); sprintf(t, "%lld", m_torrent->get_uploaded() - m_uploaded); urn.append(t); } else { urn.append("&downloaded=0&uploaded=0"); } urn.append("&left="); sprintf(t, "%lld", m_torrent->get_length() - m_torrent->get_downloaded()); urn.append(t); urn.append("&numwant="); sprintf(t, "%d", m_g_cfg->get_tracker_numwant()); urn.append(t); urn.append("&compact=1"); urn.append("&supportcrypto=0"); const char * TRACKER_EVENT_STR[4] = {"&event=started", "&event=stopped", "&event=completed",""}; urn.append(TRACKER_EVENT_STR[event]); std::string http = "GET "; http.append(urn); http.append(" HTTP/1.0\r\nUser-Agent: DinosaurBT\r\nHost: "); http.append(m_host); http.append("\r\n"); http.append("Connection: close\r\n\r\n"); m_nm->Socket_send(m_sock, http.c_str(), http.length(), true); }
QList<QVariant> SuovaFileInfo::allInformation() const { QList<QVariant> information; information << accessed() << modified() << fileName() << bytes() << created() << urn() << mimetype() << title() << url(); return information; }
/* shuffle produces a ronaom list by doing len exchanges */ PRIVATE void shuffle(int *list, int len) { int i, rn; for (i=0;i<len;i++) { int temp; rn = i + (int) (urn()*(len-i)); /* [i..len-1] */ /* swap element i and rn */ temp = list[i]; list[i] = list[rn]; list[rn] = temp; } }
PRIVATE react * Original_reaction (simulation * S, interpreter * L) { float P; react *reaction; /* this looks asymmetric, but is not; for observe that we could also call the symmetric lambda_action(lambda, 1, S, L) and choose randomly between the two products. This, however, is statistically the same as calling lambda_action(lambda, 0, S, L) and relying on the randomness in the choice sequence of the reactants. */ lambda_action (0, S, L); if (lambda.action[0] == NULL) return NULL; reaction = (react *) space (sizeof (react)); /* one product (terminate product-array with NULL) */ reaction->product[0] = lambda.action[0]; /* apply copy filter? */ P = S->Org[lambda.f[0]->sysid]->Filter.fun.copy_prob; if (P == 1.) /* no */ return reaction; /* do we have a copy action? */ if (strcmp (reaction->product[0], lambda.f[0]->object) == 0 || strcmp (reaction->product[0], lambda.f[1]->object) == 0) { /* yes, we do */ if (P != 0.) { if (urn () < P) return reaction; } free (lambda.action[0]); free (reaction); return NULL; } else return reaction; }
PUBLIC char *random_string(int l, const char symbols[]) { char *r; int i, rn, base; base = (int) strlen(symbols); r = (char *) space(sizeof(char)*(l+1)); for (i = 0; i < l; i++) { rn = (int) (urn()*base); /* [0, base-1] */ r[i] = symbols[rn]; } r[l] = '\0'; return r; }
nsresult WritePropertiesTo(nsIRDFDataSource* aDataSource, const char* aProviderType, FILE* out) { // attempt to mimic nsXMLRDFDataSource::Flush? nsCOMPtr<nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1"); nsCOMPtr<nsIRDFResource> providerRoot; nsCAutoString urn(NS_LITERAL_CSTRING(urn_prefix) + nsDependentCString(aProviderType) + NS_LITERAL_CSTRING(":root")); rdfService->GetResource(urn, getter_AddRefs(providerRoot)); nsCOMPtr<nsIRDFContainer> providerContainer = do_CreateInstance("@mozilla.org/rdf/container;1"); providerContainer->Init(aDataSource, providerRoot); nsCOMPtr<nsISimpleEnumerator> providers; providerContainer->GetElements(getter_AddRefs(providers)); PRBool hasMore; providers->HasMoreElements(&hasMore); for (; hasMore; providers->HasMoreElements(&hasMore)) { nsCOMPtr<nsISupports> supports; providers->GetNext(getter_AddRefs(supports)); nsCOMPtr<nsIRDFResource> kid = do_QueryInterface(supports); const char* providerUrn; kid->GetValueConst(&providerUrn); // remove the prefix, the provider type, and the trailing ':' // (the compiler will optimize out the -1 + 1 providerUrn += (sizeof(urn_prefix)-1) + strlen(aProviderType) + 1; WriteAttributes(aDataSource, aProviderType, providerUrn, kid, out); } return NS_OK; }
PRIVATE char * choose_law (organization * Org) { double coin, s; int i; if (Org->Params.num_laws == 1) return Org->Law[0].expr; coin = urn (); s = 0.0; for (i = 0; i < Org->Params.num_laws; i++) { s += Org->Law[i].prob; if (s > coin) return Org->Law[i].expr; } nrerror ("chose_law: no law chosen "); }
PRIVATE void make_start(char* start, const char *structure) { int i,j,k,l,r,length; int *table, *S, sym[MAXALPHA], ss; length=strlen(start); table = (int *) space(sizeof(int)*length); S = (int *) space(sizeof(int)*length); make_ptable(structure, table); for (i=0; i<strlen(start); i++) S[i] = encode_char(toupper(start[i])); for (i=0; i<strlen(symbolset); i++) sym[i] = i; for (k=0; k<length; k++) { if (table[k]<k) continue; if (((urn()<0.5) && isupper(start[k])) || islower(start[table[k]])) { i = table[k]; j = k; } else { i = k; j = table[k]; } if (!pair[S[i]][S[j]]) { /* make a valid pair by mutating j */ shuffle(sym, (int) base); for (l=0; l<base; l++) { ss = encode_char(symbolset[sym[l]]); if (pair[S[i]][ss]) break; } if (l==base) { /* nothing pairs start[i] */ r = 2*int_urn(0, npairs-1); start[i] = pairset[r]; start[j] = pairset[r+1]; } else start[j] = symbolset[sym[l]]; } } free(table); free(S); }
PUBLIC int int_urn(int from, int to) { return ( ( (int) (urn()*(to-from+1)) ) + from ); }
int sel_nb(void) { char trans, **s; int next, i; double pegel = 0.0, schwelle = 0.0, zufall = 0.0; int found_stop=0; /* before we select a move, store current conformation in cache */ /* ... unless it just came from there */ if ( !is_from_cache ) put_in_cache(); else /* laplace stuff */ for (i=0; i<top; i++) { L += (GSV.currE - energies[i]); D++; } is_from_cache = 0; /* draw 2 different a random number */ schwelle = urn(); while ( zufall==0 ) zufall = urn(); /* advance internal clock */ if (totalflux>0) zeitInc = (log(1. / zufall) / totalflux); else { if (GSV.grow>0) zeitInc=GSV.grow; else zeitInc = GSV.time; } Zeit += zeitInc; /* laplace stuff */ sumK += L*zeitInc; sumKK += L*L*zeitInc; sumD += D*zeitInc; if (GSV.grow>0 && GSV.len < strlen(GAV.farbe_full)) grow_chain(); /* meanE /= (double)top; */ /* normalize boltzmann weights */ schwelle *=totalflux; /* and choose a neighbour structure next */ for (next = 0; next < top; next++) { pegel += bmf[next]; if (pegel > schwelle) break; } /* in case of rounding errors */ if (next==top) next=top-1; /* process termination contitiones */ /* is current structure identical to a stop structure ?*/ for (found_stop = 0, s = GAV.stopform; *s; s++) { if (strcmp(*s, GAV.currform) == 0) { found_stop = (s - GAV.stopform) + 1; break; } } if ( ((found_stop > 0) && (GTV.fpt == 1)) || (Zeit > GSV.time) ) { /* met condition to stop simulation */ /* laplace stuff */ double K, KK, N, sigma; K = sumK/Zeit; KK = sumKK/Zeit; N = sumD/Zeit; /* graph Laplacian is - Laplace-Beltrami operator */ sigma = -1.0*sqrt((KK-K*K)/N)/(K/N); /* this gose to stdout */ if ( !GTV.silent ) { printf("%s %6.2f %10.3f", GAV.currform, GSV.currE, Zeit); /* laplace stuff*/ if (GTV.phi) printf(" %8.3f %8.3f %3g", zeitInc, L, D); if (GTV.verbose) printf(" %4d _ %d", top, lmin); if (found_stop) printf(" X%d\n", found_stop);/* found a stop structure */ else printf(" O\n"); /* time for simulation is exceeded */ /* laplace stuff */ if (GTV.phi) printf("Curvature fluctuation sigma = %7.5f\n", sigma); fflush(stdout); } /* this goes to log */ /* comment log steps of simulation as well !!! %6.2f round */ if ( found_stop ) { fprintf(logFP," X%02d %12.3f", found_stop, Zeit); /* laplace stuff */ if (GTV.phi) fprintf(logFP, " %3g %7.5f", GSV.phi, sigma); fprintf(logFP,"\n"); } else { fprintf(logFP," O %12.3f", Zeit); /* laplace stuff */ if (GTV.phi) fprintf(logFP, " %3g %7.5f", GSV.phi, sigma); fprintf(logFP," %d %s\n", lmin, GAV.currform); } GAV.subi[0] = xsubi[0]; GAV.subi[1] = xsubi[1]; GAV.subi[2] = xsubi[2]; fprintf(logFP, "(%5hu %5hu %5hu)", GAV.subi[0], GAV.subi[1], GAV.subi[2]); fflush(logFP); Zeit = 0.0; /* reset laplace stuff for next trajectory */ sumT = 0.0; sumK = 0.0; sumKK = 0.0; sumD = 0.0; L = 0.0; D = 0.0; /* highestE = OhighestE = -1000.0; */ reset_nbList(); return(1); } else { /* continue simulation */ int flag = 0; if( (!GTV.silent) && (GSV.currE <= GSV.stopE+GSV.cut) ) { if (!GTV.lmin || (lmin==1 && strcmp(GAV.prevform, GAV.currform) != 0)) { char format[64]; flag = 1; sprintf(format, "%%-%ds %%6.2f %%10.3f", strlen(GAV.farbe_full)); printf(format, GAV.currform, GSV.currE, Zeit); } /* laplace stuff */ if (GTV.phi) { printf(" %8.3f %8.3f %3g", zeitInc, L, D); L = D = 0.0; /* reset L and D for next structure */ } if ( flag && GTV.verbose ) { int ii, jj; if (next<0) trans='g'; /* growth */ else { ii = neighbor_list[2*next]; jj = neighbor_list[2*next+1]; if (abs(ii) < GSV.len) { if ((ii > 0) && (jj > 0)) trans = 'i'; else if ((ii < 0) && (jj < 0)) trans = 'd'; else if ((ii > 0) && (jj < 0)) trans = 's'; else trans = 'S'; } else { if ((ii > 0) && (jj > 0)) trans = 'I'; else trans = 'D'; } } printf(" %4d %c %d", top, trans, lmin); } if (flag) printf("\n"); } } /* store last lmin seen, so we can avoid printing the same lmin twice */ if (lmin==1) strcpy(GAV.prevform, GAV.currform); #if 0 if (lmin==1) { /* went back to previous lmin */ if (strcmp(GAV.prevform, GAV.currform) == 0) { if (OhighestE < highestE) { highestE = OhighestE; /* delete loop */ strcpy(highestS, OhighestS); } } else { strcpy(GAV.prevform, GAV.currform); OhighestE = 10000.; } } if ( strcmp(GAV.currform, GAV.startform)==0 ) { OhighestE = highestE = -1000.; highestS[0] = 0; } /* log highes energy */ if (GSV.currE > highestE) { OhighestE = highestE; highestE = GSV.currE; strcpy(OhighestS, highestS); strcpy(highestS, GAV.currform); } #endif if (next>=0) update_tree(neighbor_list[2*next], neighbor_list[2*next+1]); else { clean_up_rl(); ini_or_reset_rl(); } reset_nbList(); return(0); }