예제 #1
0
void UnivCharsetDesc::addBaseRange(const UnivCharsetDesc &baseSet,
				   WideChar descMin,
				   WideChar descMax,
				   WideChar baseMin,
				   ISet<WideChar> &baseMissing)
{
  UnivCharsetDescIter iter(baseSet);
  WideChar baseMax = baseMin + (descMax - descMin);
  WideChar iDescMin, iDescMax;
  UnivChar iBaseMin;
  WideChar missingBaseMin = baseMin;
  Boolean usedAll = 0;
  while (iter.next(iDescMin, iDescMax, iBaseMin) && iDescMin <= baseMax) {
    //  baseMin   baseMax
    //          iDescMin iDescMax
    if (iDescMax >= baseMin) {
      WideChar min = baseMin > iDescMin ? baseMin : iDescMin;
      if (min > missingBaseMin)
	baseMissing.addRange(missingBaseMin, min - 1);
      WideChar max = baseMax < iDescMax ? baseMax : iDescMax;
      missingBaseMin = max + 1;
      if (missingBaseMin == 0)
	usedAll = 1;
      ASSERT(min <= max);
      descToUniv_.addRange(descMin + (min - baseMin),
			   descMin + (max - baseMin),
			   iBaseMin + (min - iDescMin));
    }
  }
  if (!usedAll && baseMax >= missingBaseMin)
    baseMissing.addRange(missingBaseMin, baseMax);
}
예제 #2
0
unsigned RangeMap<From, To>::inverseMap(To to, From &from,
					ISet<WideChar> &fromSet,
					WideChar &count) const
{
  // FIXME use binary search
  unsigned ret = 0;
  count = wideCharMax;
  for (size_t i = 0; i < ranges_.size(); i++) {
    const RangeMapRange<From,To> &r = ranges_[i];
    if (r.toMin <= to && to <= r.toMin + (r.fromMax - r.fromMin)) {
      From n = r.fromMin + (to - r.toMin);
      WideChar thisCount = r.fromMax - n + 1;
      if (ret > 1) {
	fromSet.add(n);
	if (thisCount < count)
	  count = thisCount;
      }
      else if (ret == 1) {
	fromSet.add(from);
	fromSet.add(n);
	ret = 2;
	if (thisCount < count)
	  count = thisCount;
      }
      else {
	count = thisCount;
	from = n;
	ret = 1;
      }
    }
    else if (ret == 0 && r.toMin > to && (r.toMin - to < count))
      count = r.toMin - to;
  }
  return ret;
}
            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());
            }
예제 #4
0
파일: CharsetInfo.C 프로젝트: juddy/edcde
void CharsetInfo::getDescSet(ISet<Char> &set) const
{
    UnivCharsetDescIter iter(desc_);
    WideChar descMin, descMax;
    UnivChar univMin;
    while (iter.next(descMin, descMax, univMin)) {
        if (descMin > charMax)
            break;
        if (descMax > charMax)
            descMax = charMax;
        set.addRange(Char(descMin), Char(descMax));
    }
}
예제 #5
0
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;
}