示例#1
0
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
0
文件: 293.cpp 项目: grokus/exp
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
0
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
0
Bits naive_gen_bits() {
	Grid grid = naive_gen_grid();
	Bits ret;
	ret.init();
	backtrack_to_bits(grid, &ret);
	return ret;
}
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
0
文件: 293.cpp 项目: grokus/exp
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
0
文件: Ticket.c 项目: seyko2/cfront-3
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
0
文件: exo.cpp 项目: PickXu/pantry
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
0
int RM_FileHandle::GetRec(RID &rid, RM_Record &rec) {
	int index;
	Bytes head = (Bytes)bpm->getPage(fileid, rid.GetPageid(), index);
	Bits* slots = new Bits(head, pernum);						//获取slot数组,先判断获取的记录是否为空
	if (!slots->bit_get(rid.GetSlotid())) {
		//	cout << "[RM_FileHandle]Invalid Record:Empty" << endl;
		return 1;
	}
	int offset = PAGE_HEAD_BYTE;
	offset = offset + rid.GetSlotid() * recordsize;
	char* get_data = new char[recordsize];
	memcpy(get_data,head + offset,recordsize);
	RM_Record *newR = new RM_Record(get_data, recordsize);
	rec = *newR;
	return 0;
}
示例#10
0
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;
}
示例#11
0
文件: 293.cpp 项目: grokus/exp
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);
    }
}
示例#12
0
int RM_FileHandle::UpdateRec(RID &rid, RM_Record &rec) {
	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-Update]Warning: RID doesn't exist,Maybe need Insert" << endl;
		return 1;
	}
	int offset = PAGE_HEAD_BYTE;
	offset = offset + recordsize * rid.GetSlotid();
	Bytes rlocation = (Bytes)head;
	rlocation = rlocation + offset;
	memcpy(rlocation, rec.GetRdata(), rec.GetSize());
	slots->bit_setone(rid.GetSlotid());

	bpm->markDirty(index);
	return 0;
}
示例#13
0
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;
    }
}
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, &sections, &bitsForSummary, &pos, &xml, &title, &url, &linkInfo));

	summary.setSummary(&xml, &words, &sections, &pos, &query, 180, 3, 3, 180, &url, &matches, title.getTitle(), title.getTitleLen());
}
示例#15
0
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);
        }
    }
}
示例#16
0
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;
}
示例#17
0
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;
	}
}
示例#18
0
/**
 * Returns the value a is currently assigned to in the SAT solver
 * or null if the value is completely unassigned.
 *
 * @param a
 * @param fullModel whether to create a "full model," i.e., add
 * constants to equivalence classes that don't already have them
 *
 * @return
 */
Node TLazyBitblaster::getVarValue(TNode a, bool fullModel) {
  if (!hasBBTerm(a)) {
    Assert(isSharedTerm(a));
    return Node();
  }
  Bits bits;
  getBBTerm(a, bits);
  Integer value(0);
  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);
      Assert (bit_value != prop::SAT_VALUE_UNKNOWN);
    } else {
      // the bit is unconstrainted so we can give it an arbitrary value
      bit_value = prop::SAT_VALUE_FALSE;
    }
    Integer bit_int = bit_value == prop::SAT_VALUE_TRUE ? Integer(1) : Integer(0);
    value = value * 2 + bit_int;
  }
  return utils::mkConst(BitVector(bits.size(), value));
}
示例#19
0
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;
        }
    }
}
示例#20
0
Bits RichEdit::SpellParagraph(const RichPara& para)
{
	int len = para.GetLength();
	Buffer<wchar> text(len);
	Buffer<int> lang(len);
	wchar *s = text;
	int *g = lang;
	for(int i = 0; i < para.GetCount(); i++) {
		const RichPara::Part& p = para[i];
		if(p.IsText()) {
			int l = p.text.GetLength();
			memcpy(s, p.text, l * sizeof(wchar));
			Fill(g, g + l, fixedlang ? fixedlang : p.format.language);
			s += l;
			g += l;
		}
		else {
			*s++ = 127;
			*g++ = 0;
		}
	}
	Bits e;
	s = text;
	wchar *end = text + len;
	while(s < end) {
		if(IsLetter(*s)) {
			const wchar *q = s;
			while(s < end && IsLetter(*s) || s + 1 < end && *s == '\'' && IsLetter(s[1]))
				s++;
			if(!SpellWord(q, int(s - q), lang[q - text]))
				e.Set(int(q - text), true, int(s - q));
		}
		else
			s++;
	}
	return e;
}
示例#21
0
void EagerBitblaster::bbTerm(TNode node, Bits& bits) {
  if (hasBBTerm(node)) {
    getBBTerm(node, bits);
    return;
  }

  d_bv->spendResource(options::bitblastStep());
  Debug("bitvector-bitblast") << "Bitblasting node " << node <<"\n";

  d_termBBStrategies[node.getKind()] (node, bits, this);

  Assert (bits.size() == utils::getSize(node));

  storeBBTerm(node, bits);
}
示例#22
0
/**
 * Returns the value a is currently assigned to in the SAT solver
 * or null if the value is completely unassigned.
 *
 * @param a
 * @param fullModel whether to create a "full model," i.e., add
 * constants to equivalence classes that don't already have them
 *
 * @return
 */
Node EagerBitblaster::getModelFromSatSolver(TNode a, bool fullModel) {
  if (!hasBBTerm(a)) {
    return fullModel? utils::mkConst(utils::getSize(a), 0u) : Node();
  }
  
  Bits bits;
  getBBTerm(a, bits);
  Integer value(0);
  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);
      Assert (bit_value != prop::SAT_VALUE_UNKNOWN);
    } else {
      if (!fullModel) return Node();
      // unconstrained bits default to false
      bit_value = prop::SAT_VALUE_FALSE;
    }
    Integer bit_int = bit_value == prop::SAT_VALUE_TRUE ? Integer(1) : Integer(0);
    value = value * 2 + bit_int;
  }
  return utils::mkConst(BitVector(bits.size(), value));
}
示例#23
0
void TLazyBitblaster::bbTerm(TNode node, Bits& bits) {

  if (hasBBTerm(node)) {
    getBBTerm(node, bits);
    return;
  }

  Debug("bitvector-bitblast") << "Bitblasting node " << node <<"\n";
  ++d_statistics.d_numTerms;

  d_termBBStrategies[node.getKind()] (node, bits,this);

  Assert (bits.size() == utils::getSize(node));

  storeBBTerm(node, bits);
}
示例#24
0
		bool has() const {
			return componentBits.get(getComponentType<T>());
		}
示例#25
0
int RM_FileHandle::InsertRec(RID &rid, RM_Record &rec) {		//这里的RID是插入后返回一个RID,其余成员函数都是需要一个RID

	int first_index;
	BufType first_head = bpm->getPage(fileid, 0, first_index);
	int empty_rid_offset = EMPTY_RID_OFFSET_BYTE;			//获取下一可插入项的偏移
	int next_page_offset = NEXT_EMPTY_PAGE_BYTE;			//获取下一个含空项页页码的偏移
	int slots_offset = SLOT_OFFSET_BYTE;					//获取slot偏移位置
	if (*(int*)(first_head + EMPTY_PAGE_OFFSET_4BYTE) != -1) {			//存在下一个空记录

		int insert_page_index;
		Bytes insert_page_head = (Bytes)bpm->getPage(fileid, first_head[EMPTY_PAGE_OFFSET_4BYTE], insert_page_index);
		bpm->markDirty(insert_page_index);						//肯定要修改,所以提前标记为脏页
		RID* current_empty_rid = (RID*)(insert_page_head + empty_rid_offset);	//下一可插入项
		int next_page = *(int*)(insert_page_head + next_page_offset);			//下一个含空项页页码
		Bits* slots = new Bits(insert_page_head + slots_offset, pernum);		//slots

		int offset = PAGE_HEAD_BYTE;
		offset = offset + recordsize * current_empty_rid->GetSlotid();
		Bytes rlocation = insert_page_head + offset;			//获取相应偏移后的地址
		memcpy(rlocation, rec.GetRdata(), rec.GetSize());			//插入该记录
		slots->bit_setone(current_empty_rid->GetSlotid());		//slot相应位子置1
		rid = *current_empty_rid;								//rid返回

		bool isfull = true;									//标记用,true表示当前页满
		for (int current_slot = current_empty_rid->GetSlotid() + 1; current_slot < pernum; current_slot++) {
			if (!slots->bit_get(current_slot)) {					//寻找下一个current_empty_rid,当slots[i]为0时说明该位为空
				isfull = false;
				current_empty_rid->SetSlotid(current_slot);		//修改下一个空项的位置
				break;
			}
		}
		if (isfull) {											//如果页满了
			first_head[EMPTY_PAGE_OFFSET_4BYTE] = next_page;	//当前数据页的下一页给第一页的含空项页
			bpm->markDirty(first_index);						//标记脏页
			current_empty_rid->SetSlotid(-1);					//slotid为-1表示没有下一项
			*(int*)(insert_page_head + next_page_offset) = -1;	//下一个含空项页页码表示当前页为满页
		}
	} else {													//均为满页,新建一页
		pagesum++;												//总页数新增一页
		first_head[PSIZE_OFFSET_4BYTE] = pagesum;				//修改总页数
		bpm->markDirty(first_index);							//标记为脏页
		int new_index;											//新建一个页,并将slot清零
		Bytes new_head = (Bytes)bpm->getPage(fileid, pagesum - 1, new_index);
		Bits* new_slots = new Bits(new_head + slots_offset, pernum);
		new_slots->all_zero();

		int new_offset = PAGE_HEAD_BYTE;						//slot[0]即为第一条记录,存储insert的记录
		Bytes rlocation = new_head + new_offset;
		memcpy(rlocation, rec.GetRdata(), rec.GetSize());
		new_slots->bit_setone(0);
		bpm->markDirty(new_index);								//标记为脏页

		RID new_rid;
		new_rid.SetFileid(-1);
		new_rid.SetPageid(pagesum - 1);
		new_rid.SetSlotid(1);
		*(RID*)(new_head + empty_rid_offset) = new_rid;			//下一可插入项更新为第1项
		rid = new_rid;
		rid.SetSlotid(0);
		first_head[EMPTY_PAGE_OFFSET_4BYTE] = pagesum - 1;		//第一页的含空项页设为当下的新增页
		*(int*)(new_head + next_page_offset) = -1;				//由于之前都是满页,这页显然没有后继页面,设为-1
	}
	return 0;
}
示例#26
0
int RM_FileScan::NextRec(RM_Record &rec, RID &rid) {
	if (isclose) {
		//cout << "[RM_FileScan]GetNextRec error: This filescan has been closed!" << endl;
		return 2;
	}
	//NULL1:当comparevalue为NULL且op为大小于中的一个时为用假,返回为空
	if(op <= GE && op >= LT && comparevalue == NULL)	return 1;

	bool get_flag = false;
	int index;
	Bytes head = (Bytes)filehandle->bpm->getPage(currentRid->GetFileid(), currentRid->GetPageid(), index);
	Bits* slots = new Bits(head, filehandle->GetPnum());
	Bytes record_head;
	int current_slotid = currentRid->GetSlotid();
	int current_pageid = currentRid->GetPageid();

	int offset = PAGE_HEAD_BYTE;
	while (!get_flag) {
//		cout << "fuck1" << endl;
		while ( current_slotid < filehandle->GetPnum() && slots->bit_get(current_slotid) == false) {
			current_slotid++;
		}
//		cout << "fuck2" << endl;
		if (current_slotid == filehandle->GetPnum()) {		//该页记录已全部遍历
			current_pageid++;
			current_slotid = 0;
			if (current_pageid == filehandle->GetPsum()) {	//说明该文件下所有页的所有记录都已遍历过.此时返回0表示已遍历完
				currentRid->SetPageid(current_pageid);
				currentRid->SetSlotid(current_slotid);
				return 1;
			}
			head = (Bytes)filehandle->bpm->getPage(currentRid->GetFileid(), current_pageid, index);
			slots->setData(head);
			offset = PAGE_HEAD_BYTE;
		} else {	//得到一个记录
//			cout << "fuck3" << endl;
			offset = PAGE_HEAD_BYTE;
			offset = offset + filehandle->GetRsize() * current_slotid;
			record_head = head + offset;
			int nullbits_offset = RECORD_NULLBITS_OFFSET_BYTE;
			Bits* nullbits = new Bits(record_head + nullbits_offset, attrcol+1);		//获取相应记录的null位图(一定长度)
			//NULL2.1:左边NULL且需要判等(不等),则直接通过null位图来判别
			//NULL2.2:左边NULL且op为大小于,直接返回true
//			cout << "fuck3.1" << endl;
			if(nullbits->bit_get(attrcol) == 0) {//左边为NULL
				if(op == NO) {
					get_flag = true;
				}
				if(op <= GE && op >= LT) {		//为理解方便写出来,实际没什么用
					get_flag = false;
				}
				if(op == EQ) {
					get_flag = (comparevalue == NULL);
				}
				if(op == NE) {
					get_flag = !(comparevalue == NULL);
				}
			} else /*if (comparevalue != 0)*/{//其他情况,进行相应比较
//				cout << "fuck3.2" << endl;
				char* value_head = record_head + attroffset;
//				enum AttrType{INTEGER,FLOAT,STRING};
//				enum CompOp{EQ,LT,GT,LE,GE,NE,NO};
//				cout << "11" << endl;
				const char* cmp1 = value_head;
				const char* cmp2 = (char*)comparevalue;
				const CompOp cmpop = op;
				const AttrType cmptype = type;
//				cout << "22" << endl;
				if  (comparevalue != 0 || op == NO){
//					cout << "33" << endl;
					get_flag = compareData(cmp1, cmpop, cmp2, cmptype);
				}
				else
					get_flag = false;

			}
//			cout << "fuck4" << endl;
			if (get_flag) {
				rec.SetSize(filehandle->GetRsize());
//				cout << "get_data: " << &get_data << " " << "head: " << &record_head << endl;
				rec.SetData(record_head);
			} else {
				current_slotid++;
			}
//			cout << "fuck5" << endl;
		}
	}
	//设置RID
	rid.SetFileid(-1);
	rid.SetPageid(current_pageid);
	rid.SetSlotid(current_slotid);
	//设置下一条记录的位置
	currentRid->SetPageid(current_pageid);
	currentRid->SetSlotid(current_slotid + 1);
	return 0;
}
// . 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		 );
}
示例#28
0
int main(int argc, char* argv[]) {
	srand((unsigned) time(0));
	
	Bits bits;
	//CSolver solver;
	
	int num = 100000;
	int solved = 0;
	
	clock_t start, finish;
	start = clock();
	
	//bits = naive_gen_bits();
	
	for(int i=0; i < num; i++) {
		
		//std::cin >> bits;
		//if(std::cin.eof()) { break; }
		//if(!csolver_unique_check(&solver, &bits)) { continue; }
		
		
		bits = naive_gen_bits();
		
		//Bits newbits;
		//newbits = bits;
		//CSolver solver;
		
		
		bool solving = true;
		while(solving) {
			
			std::vector<SimpleNakedSingle> snss = find_simple_naked_singles(&bits);
			if(snss.size() > 0) {
				for(int i=0; i < snss.size(); i++) {
					snss[i].apply(&bits);
				}
				continue;
			}
			
			std::vector<NakedSingle> nss = find_naked_singles(&bits);
			if(nss.size() > 0) {
				for(int i=0; i < nss.size(); i++) {
					nss[i].apply(&bits);
				}
				continue;
			}
			
			std::vector<HiddenSingle> hss = find_hidden_singles(&bits);
			if(hss.size() > 0) {
				for(int i=0; i < hss.size(); i++) {
					hss[i].apply(&bits);
				}
				continue;
			}
			
			std::vector<NHSubset> nhs = find_nh_subsets(&bits);
			if(nhs.size() > 0) {
				for(int i=0; i < nhs.size(); i++) {
					nhs[i].apply(&bits);
				}
				continue;
			}
			
			std::vector<Pointing> points = find_pointings(&bits);
			if(points.size() > 0) {
				for(int i=0; i < points.size(); i++) {
					points[i].apply(&bits);
				}
				continue;
			}
			
			std::vector<BoxLine> boxlines = find_boxlines(&bits);
			if(boxlines.size() > 0) {
				for(int i=0; i < boxlines.size(); i++) {
					boxlines[i].apply(&bits);
				}
				continue;
			}
			
			std::vector<NFish> nfishes = find_nfishes(&bits);
			if(nfishes.size() > 0) {
				for(int i=0; i < nfishes.size(); i++) {
					nfishes[i].apply(&bits);
				}
				continue;
			}
			
			std::vector<SimpleColoring> scs = find_simple_colorings(&bits);
			if(scs.size() > 0) {
				for(int i=0; i < scs.size(); i++) {
					scs[i].apply(&bits);
				}
				continue;
			}
			
			std::vector<YWing> ywings = find_ywings(&bits);
			if(ywings.size() > 0) {
				for(int i=0; i < ywings.size(); i++) {
					ywings[i].apply(&bits);
				}
				continue;
			}
			
			solving = false;
		}
		
		if(bits.complete()) {
			solved++;
			continue;
		}
		/*
		std::cout << bits;
		*/
	}
	
	finish = clock();
	
	printf("time: %2.5f sec\n",(double)(finish - start)/CLOCKS_PER_SEC);
	printf("%d problems processed\n", num);
	printf("%2.5f sec per grid average\n", (double)(finish - start)/((double)(CLOCKS_PER_SEC * num)));
	printf("%1.5f percent solvable.\n", (double)(solved)/(double)(num));
	
	return 0;
}
示例#29
0
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
}
示例#30
-10
Signal
BluetoothTransmitter::modulate(const Bits& input, double df) {
    Signal modOut(Ns * input.size());
    int offset = 0;
    double phase=getPhase();

    for (int i=0; i<input.size(); ++i) {
        for(int j=0; j<Ns; ++j) {
            double tt=twopi*df*(j+Ns*i)/((double)Ns);
            if (tt>twopi) { tt=fmod(tt,twopi); }
            double state = qsign(input[i])*s_qcoef[j] +
                           qsign(m_prev)*s_qcoef[j+Ns] + phase;
            modOut[offset+j] = exp(Sample(0.0,twopi* (m_hf * state)+tt));
        } // end j

        // Update phase and previous bit value
        phase += (m_prev ? -0.5 : 0.5);
        m_prev = input[i];
        offset += Ns;
    } // end i

    setPhase(phase);
    return modOut;
}