本文整理汇总了C++中Bits类的典型用法代码示例。如果您正苦于以下问题:C++ Bits类的具体用法?C++ Bits怎么用?C++ Bits使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bits类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Bits
int RM_FileHandle::DeleteRec(RID &rid) {
//检测错误
int index;
Bytes head = (Bytes)bpm->getPage(fileid, rid.GetPageid(), index);
Bits* slots = new Bits(head, pernum);
if (!slots->bit_get(rid.GetSlotid())) {
//cout << "[RM_FileHandle-Del]Warning: RID doesn't exist" << endl;
return 1;
}
//删除对应记录以及更新空项记录和未满数据页页码记录
int first_index;
BufType first_head = bpm->getPage(fileid, 0, first_index); //打开第一页
int empty_page = *(int*)(first_head + EMPTY_PAGE_OFFSET_4BYTE); //获取未满的最前面数据页页码
int empty_rid_offset = EMPTY_RID_OFFSET_BYTE; //获取下一可插入项的偏移
RID* current_empty_rid = (RID*)(head + empty_rid_offset); //获取下一可插入项
int next_page_offset = NEXT_EMPTY_PAGE_BYTE; //获取下一个含空项页页码的偏移
int next_page = *(int*)(head + next_page_offset); //获取下一个含空项页页码
slots->bit_setzero(rid.GetSlotid()); //删除该记录
bpm->markDirty(index); //将该页标记为脏页
if (current_empty_rid->GetSlotid() == -1) { //若之前为满页
current_empty_rid->slotid = rid.GetSlotid(); //将下一可插入记录项置成当前删除记录
*(int*)(first_head + EMPTY_PAGE_OFFSET_4BYTE) = rid.GetPageid();//则将第一页的值的页码更改为本页码
*(int*)(head + next_page_offset) = empty_page; //本页码的下一空项页改为第一页原来存的页码值
bpm->markDirty(first_index);
}
else {
if (current_empty_rid->slotid > rid.GetSlotid()) { //更新下一可插入项的偏移槽的值
current_empty_rid->slotid = rid.GetSlotid();
}
}
return 0;
}
示例2: main
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;
}
示例3: makeVariable
void EagerBitblaster::makeVariable(TNode var, Bits& bits) {
Assert(bits.size() == 0);
for (unsigned i = 0; i < utils::getSize(var); ++i) {
bits.push_back(utils::mkBitOf(var, i));
}
d_variables.insert(var);
}
示例4: naive_gen_bits
Bits naive_gen_bits() {
Grid grid = naive_gen_grid();
Bits ret;
ret.init();
backtrack_to_bits(grid, &ret);
return ret;
}
示例5: addMatches
bool Matches::addMatches( char *s, int32_t slen, mf_t flags ) {
// . do not breach
// . happens a lot with a lot of link info text
if ( m_numMatchGroups >= MAX_MATCHGROUPS ) {
return true;
}
// get some new ptrs for this match group
Words *wp = &m_wordsArray [ m_numMatchGroups ];
Bits *bp = &m_bitsArray [ m_numMatchGroups ];
Pos *pb = &m_posArray [ m_numMatchGroups ];
// set the words class for this match group
if ( !wp->set( s, slen, true ) ) {
return false;
}
// bits vector
if ( ! bp->setForSummary ( wp ) ) {
return false;
}
// position vector
if ( ! pb->set ( wp ) ) {
return false;
}
// record the start
int32_t startNumMatches = m_numMatches;
// sometimes it returns true w/o incrementing this
int32_t n = m_numMatchGroups;
// . add all the Match classes from this match group
// . this increments m_numMatchGroups on success
bool status = addMatches( wp, NULL, NULL, bp, pb, flags );
// if this matchgroup had some, matches, then keep it
if ( m_numMatches > startNumMatches ) {
return status;
}
// otherwise, reset it, useless
wp->reset();
bp->reset();
pb->reset();
// do not decrement the counter if we never incremented it
if ( n == m_numMatchGroups ) {
return status;
}
// ok, remove it
m_numMatchGroups--;
return status;
}
示例6: print_bitset
void
print_bitset(Bits b, size_t size = 0)
{
if (size == 0)
size = b.size();
for (size_t pos = b.find_first(); pos < size && pos != string::npos; pos = b.find_next(pos))
{
std::cout << pos << ", ";
}
std::cout << std::endl;
}
示例7:
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);
}
示例8: __hashbits
void __hashbits(hash_t *hash, void *data, uint32_t size) {
// compute hash of data.
Bits bits(size * 8);
ByteArrayToBits(data, size, bits);
Bits hashBits = _hasher->hash(bits);
for (uint32_t i = 0; i < hashBits.size() / 8; i++) {
uint8_t* chunk = &(((uint8_t*)hash)[i]);
*chunk = 0;
for (uint32_t j = 0; j < 8; j++) {
*chunk |= (hashBits[DB_HASH_NUM_BITS - (i * 8 + j) - 1] << j);
}
}
}
示例9: Assert
bool TLazyBitblaster::hasValue(TNode a) {
Assert (hasBBTerm(a));
Bits bits;
getBBTerm(a, bits);
for (int i = bits.size() -1; i >= 0; --i) {
prop::SatValue bit_value;
if (d_cnfStream->hasLiteral(bits[i])) {
prop::SatLiteral bit = d_cnfStream->getLiteral(bits[i]);
bit_value = d_satSolver->value(bit);
if (bit_value == prop::SAT_VALUE_UNKNOWN)
return false;
} else {
return false;
}
}
return true;
}
示例10: createSeedMapCache
Bits<256> Block::getSeedHash(Epoch epochs)
{
if(Block::epochToSeedMap.size() <= 0 || Block::seedToEpochMap.size() <= 0)
{
createSeedMapCache();
}
if(epochs < 2048)
{
return Block::epochToSeedMap[epochs];
}
else
{
Bits<256> seedHash = Block::epochToSeedMap[2047];
for (uint64_t i = 2047; i < epochs; ++i)
{
SHA3_256(seedHash.ptr(), seedHash.ptr(), 32);
}
return seedHash;
}
}
示例11: generateSummary
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());
}
示例12: qDebug
void Drum::creator()
{
if(game->count->counter>0)
{
int random=rand()%2;
if(random==true)
{
qDebug()<<"bit1 out";
Bits *bits = new Bits();
scene()->addItem(bits);
bits->setPos(800,50);
}
if(random==false)
{
qDebug()<<"bit2 out";
Bits2 *bits2 = new Bits2();
scene()->addItem(bits2);
bits2->setPos(800,50);
}
}
}
示例13: permute_bits
Bits Permutation::permute_bits(Bits* bits) {
Bits ret;
ret.init();
for(int i=0; i < 81; i++) {
// p: spot in ret
Spot p = spot_of_idx(i);
// px: spot in bits
Spot px = permute_spot(p);
if(bits->has_value(px)) {
ret.set_value(p, permute_val(bits->get_value(px)));
} else {
for(int k=1; k <=9; k++) {
if(!bits->has_candidate(px, k)) {
ret.remove_candidate(p, permute_val(k));
}
}
}
}
return ret;
}
示例14: test2
double test2() {
int p0 = 1;
Bits * obj = new Bits();
clock_t start = clock();
int my_answer = obj->minBits(p0);
clock_t end = clock();
delete obj;
cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
int p1 = 1;
cout <<"Desired answer: " <<endl;
cout <<"\t" << p1 <<endl;
cout <<"Your answer: " <<endl;
cout <<"\t" << my_answer <<endl;
if (p1 != my_answer) {
cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
return -1;
}
else {
cout <<"Match :-)" <<endl <<endl;
return (double)(end-start)/CLOCKS_PER_SEC;
}
}
示例15: inputFile
void Block::createSeedMapCache()
{
uint64_t seedMapFileSize = 2048*(256/8);
uint8_t seedMap[seedMapFileSize];
std::ifstream inputFile( "seedmap", std::ios::binary );
if(inputFile.fail())
{
Bits<256> seedHash;
for(size_t i=0 ; i<2048 ; i++)
{
uint8_t* ptr = &seedMap[i*(256/8)];
memcpy(ptr,seedHash.ptr(),32);
Block::epochToSeedMap[i] = Bits<256>(seedHash);
Block::seedToEpochMap[seedHash] = i;
SHA3_256(seedHash.ptr(), seedHash.ptr(), 32);
}
std::ofstream outputFile( "seedmap", std::ofstream::out );
outputFile.write((char*)seedMap, seedMapFileSize);
outputFile.flush();
outputFile.close();
}
else
{
inputFile.read((char*)seedMap,seedMapFileSize);
inputFile.close();
for(size_t i=0 ; i<2048 ; i++)
{
uint8_t* ptr = &seedMap[i*(256/8)];
Block::epochToSeedMap[i] = Bits<256>(ptr);
Block::seedToEpochMap[Bits<256>(ptr)] = i;
}
}
}