void ClientTxnSetTest::testAddRemove() { ISet<std::string> s = client->getSet<std::string>("testAddRemove"); s.add("item1"); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalSet<std::string> set = context.getSet<std::string>("testAddRemove"); assertTrue(set.add("item2")); assertEqual(2, set.size()); assertEqual(1, s.size()); assertFalse(set.remove("item3")); assertTrue(set.remove("item1")); context.commitTransaction(); assertEqual(1, s.size()); }
void SparseGenome::init_mutations(ISet &is) { int p = 2*is.size(); // number of "strands" = 2 * #individuals int i, j, k, l; // counters and temp indices int n; // number of individuals in set mutation_t si; // mutation effect of a single gene fitness_t xw; // change in fitness due to this gene double qi; // frequency of gene double gu; // genic mutation rate int x, nx; // id of individual, #individuals int nl = 0; // for debugging, keep track of #loci and int nm = 0; // #mutations affected by this step int *bin; // also keep track of distribution of mutation values IP *v; SparseGenome *sgp; n = is.size(); v = new IP[n]; for (i=0; i<n; i++) // copy individuals to local vector for faster access v[i] = is.remove(0); bin = new int[p+1]; // cout << "Placing initial mutations in " << p << " strands...." << endl; for (i=0; i<=p; i++) bin[i] = 0; gu = u/(2*gl); // genic rate = individual rate / number of genes // cout << "Genic mutation rate (U/2N) = " << gu << endl; // Iterate over all loci; pick a mutation effect for that locus, figure // out the expected frequency of a gene with that effect, and then add it // to selected individuals. In this loop 'i' is the locus index, 'j' // is the chromosome number for that locus, and 'k' is the index of the locus // within the chromosome. // optimization: knowing that get_gene() and set_gene() in Strand scan // from "left to right", start with the higher locus indices and count // down to 0 -- this way the lookups and insertions will all be done // in one step.... for (i = gl-1; i >= 0; i--) { j = i / chrlength; k = i % chrlength; si = new_mutation_value(s,rs); // get mutation effect qi = gu/hs(si); // frequency of allele with effect si if (qi > 1.0) qi = 1.0; nx = int(rbinomial(qi,p)); // number of genes expected to have this mutation if (nx > p) nx = p; // if (qi) { // cout << "locus " << i << ": "; // cout << ", si = " << si; // cout << ", hs = " << hs(si,0.0); // cout << ", qi = " << qi; // cout << ", nx = " << nx << endl; // } nm += nx; // record info on this mutation bin[nx] += 1; if (nx) nl += 1; while (nx) { x = rword(n); l = rword(2); sgp = (SparseGenome *)v[x]->genes; if (sgp->sa[j].get_gene(k,l) == 0.0) { xw = sgp->sa[j].set_gene(k,l,si); sgp->w *= xw; nx--; } } } // cout << "Distributed " << nm << " mutations across " << nl << " loci" << endl; // for (i=0; i<=p; i++) // cout << i << ": " << bin[i] << endl; }