void gen_admissible() { unsigned n = 2; while (n < NMAX) { b1.set(n); n *= 2; } overall |= b1; for (int i = 0; i < num_primes; i++) { uint64 p = primes[i]; do { size_t pos = b1.find_first(); uint64 j; while (pos != string::npos && (j = pos * p) < NMAX) { //cout << j << endl; b2.set(j); pos = b1.find_next(pos); } p *= primes[i]; } while (p < NMAX); overall |= b2; b1.clear(); b1.resize(NMAX + 1); b1.swap(b2); } }
int main (int argc, char *argv[]) { overall.resize(NMAX + 1); b1.resize(NMAX + 1); b2.resize(NMAX + 1); gen_admissible(); print_bitset(overall, 640); mpz_class p_prev = 0, p = 3; mpz_class max; mpz_set_ui(max.get_mpz_t(), NMAX); size_t pos = overall.find_first(); Bits pf; pf.resize(1000); while (pos != string::npos && p_prev < max) { mpz_swap(p_prev.get_mpz_t(), p.get_mpz_t()); mpz_nextprime(p.get_mpz_t(), p_prev.get_mpz_t()); //cout << "next prime: " << p << endl; unsigned uip = mpz_get_ui(p.get_mpz_t()); while (pos != string::npos && pos + 1 < uip) { pf.set(uip - pos); //cout << "pos: " << pos << ", total: " << total << endl; pos = overall.find_next(pos); } } unsigned total = 0; for (size_t pos = pf.find_first(); pos != string::npos; pos = pf.find_next(pos)) { total += pos; } cout << "total: " << total << endl; return 0; }
void Ticket_ATTLC::Validate(Bits& b) { unsigned int count = 0; while (b[count]) count++; while (count >= b.size()) b.size(b.size() + bits_increment); num = count; b.set(num); }
static void generateSummary( Summary &summary, char *htmlInput, const char *queryStr, const char *urlStr ) { Xml xml; ASSERT_TRUE(xml.set(htmlInput, strlen(htmlInput), 0, CT_HTML)); Words words; ASSERT_TRUE(words.set(&xml, true)); Bits bits; ASSERT_TRUE(bits.set(&words)); Url url; url.set(urlStr); Sections sections; ASSERT_TRUE(sections.set(&words, &bits, &url, "", CT_HTML)); Query query; ASSERT_TRUE(query.set2(queryStr, langEnglish, true)); LinkInfo linkInfo; memset ( &linkInfo , 0 , sizeof(LinkInfo) ); linkInfo.m_lisize = sizeof(LinkInfo); Title title; ASSERT_TRUE(title.setTitle(&xml, &words, 80, &query, &linkInfo, &url, NULL, 0, CT_HTML, langEnglish)); Pos pos; ASSERT_TRUE(pos.set(&words)); Bits bitsForSummary; ASSERT_TRUE(bitsForSummary.setForSummary(&words)); Phrases phrases; ASSERT_TRUE(phrases.set(&words, &bits)); Matches matches; matches.setQuery(&query); ASSERT_TRUE(matches.set(&words, &phrases, §ions, &bitsForSummary, &pos, &xml, &title, &url, &linkInfo)); summary.setSummary(&xml, &words, §ions, &pos, &query, 180, 3, 3, 180, &url, &matches, title.getTitle(), title.getTitleLen()); }
dt_t *ArrayInitializer::toDtBit() { #if DMDV1 unsigned size; unsigned length; unsigned tadim; dt_t *d; dt_t **pdtend; Type *tb = type->toBasetype(); //printf("ArrayInitializer::toDtBit('%s')\n", toChars()); Bits databits; Bits initbits; if (tb->ty == Tsarray) { /* The 'dim' for ArrayInitializer is only the maximum dimension * seen in the initializer, not the type. So, for static arrays, * use instead the dimension of the type in order * to get the whole thing. */ dinteger_t value = ((TypeSArray*)tb)->dim->toInteger(); tadim = value; assert(tadim == value); // truncation overflow should already be checked databits.resize(tadim); initbits.resize(tadim); } else { databits.resize(dim); initbits.resize(dim); } /* The default initializer may be something other than zero. */ if (tb->next->defaultInit()->toInteger()) databits.set(); size = sizeof(databits.data[0]); length = 0; for (size_t i = 0; i < index.dim; i++) { Expression *idx; Initializer *val; Expression *eval; idx = (Expression *)index.data[i]; if (idx) { dinteger_t value; value = idx->toInteger(); length = value; if (length != value) { error(loc, "index overflow %llu", value); length = 0; } } assert(length < dim); val = (Initializer *)value.data[i]; eval = val->toExpression(); if (initbits.test(length)) error(loc, "duplicate initializations for index %d", length); initbits.set(length); if (eval->toInteger()) // any non-zero value is boolean 'true' databits.set(length); else databits.clear(length); // boolean 'false' length++; } d = NULL; #ifdef IN_GCC pdtend = dtnbits(&d, databits.allocdim * size, (char *)databits.data, sizeof(databits.data[0])); #else pdtend = dtnbytes(&d, databits.allocdim * size, (char *)databits.data); #endif switch (tb->ty) { case Tsarray: { if (dim > tadim) { error(loc, "too many initializers, %d, for array[%d]", dim, tadim); } else { tadim = (tadim + 31) / 32; if (databits.allocdim < tadim) pdtend = dtnzeros(pdtend, size * (tadim - databits.allocdim)); // pad out end of array } break; } case Tpointer: case Tarray: // Create symbol, and then refer to it Symbol *s; s = static_sym(); s->Sdt = d; outdata(s); d = NULL; if (tb->ty == Tarray) dtsize_t(&d, dim); dtxoff(&d, s, 0, TYnptr); break; default: assert(0); } return d; #else return NULL; #endif }
// . return length stored into "buf" // . content must be NULL terminated // . if "useAnchors" is true we do click and scroll // . if "isQueryTerms" is true, we do typical anchors in a special way int32_t Highlight::set ( SafeBuf *sb, //char *buf , //int32_t bufLen , char *content , int32_t contentLen , // primary language of the document (for synonyms) char docLangId , Query *q , bool doStemming , bool useAnchors , const char *baseUrl , const char *frontTag , const char *backTag , int32_t fieldCode , int32_t niceness ) { Words words; if ( ! words.set ( content , contentLen , TITLEREC_CURRENT_VERSION, true , // computeId true ) ) // has html entites? return -1; int32_t version = TITLEREC_CURRENT_VERSION; Bits bits; if ( ! bits.set (&words,version,niceness) ) return -1; Phrases phrases; if ( !phrases.set(&words,&bits,true,false,version,niceness))return -1; //SafeBuf langBuf; //if ( !setLangVec ( &words , &langBuf , niceness )) return 0; //uint8_t *langVec = (uint8_t *)langBuf.getBufStart(); // make synonyms //Synonyms syns; //if(!syns.set(&words,NULL,docLangId,&phrases,niceness,NULL)) return 0; Matches matches; matches.setQuery ( q ); if ( ! matches.addMatches ( &words , &phrases ) ) return -1; // store m_numMatches = matches.getNumMatches(); return set ( sb , //buf , //bufLen , &words , &matches , doStemming , useAnchors , baseUrl , frontTag , backTag , fieldCode , q ); }