Пример #1
0
//DFS with heuristic
void DFSBoard::DoDFS(){
  //TODO: choose an answer of the line with minimum possible answer() -> use heuristic to fill board -> check other lineis legal or not -> if legal, next line
  puts("doDFS");
  vector<int> rowOrder(r);
  int nowr = 0;
  rowOrder[nowr] = getRowWithMinBranch(nowr, rowOrder);
  while(nowr <= r){
    puts("nowroworder");
    for(int i = 0; i <= nowr; i++)
      printf("%d ", rowOrder[i]);
    puts("");
    if(isAllSolved())
      return;
    if(!tryFillRowHeuristic(rowOrder[nowr])){//try all possibilities to fill the row, will filling next answer after previous called
      if(nowr == 0){
	puts("rewind to the first row: no solution:");
	break;
      }
      //all possibilities in row nowr are failed, recover board to previous row(nowr-1)
      lastfillStart[rowOrder[nowr]].clear();
      Rewind(rowOrder[--nowr]);
    } else {// fill answer success, continue filling next row
      rowOrder[++nowr] = getRowWithMinBranch(nowr, rowOrder);
      if(nowr == r)//complete, check column again
	if(isDFSAnswerCorrect())
	  return;
	else
	  Rewind(rowOrder[--nowr]);
    }
  }
}
bool EMMediaTransitionTrackRepository::SaveData(EMProjectDataSaver* p_opSaver)
{
	p_opSaver -> SaveString("EMMediaTransitionTrackRepository - Begin");
	
	LockContainer();
	uint32 vCount = 0;
	Rewind();
	while(Current() != NULL)
	{
		if(! Current() -> IsObjectDeleted())
			vCount++;
		Next();
	}
	p_opSaver -> SaveUInt32(vCount);

	Rewind();
	while(Current() != NULL)
	{
		if(! Current() -> IsObjectDeleted())
			Current() -> SaveData(p_opSaver);
		Next();
	}
	UnlockContainer();

	p_opSaver -> SaveString("EMMediaTransitionTrackRepository - End");

	return true;
}
Пример #3
0
int
AvgByCount(double ts,
	  double input_val,
	  void *state_set,
	  int tau,
	  double *out_ts,
	  double *out_val)
{
	int ierr;
	double curr_ts;
	double curr_val;
	double count;
	double acc;
	int size;
	int read;
	
	Rewind(state_set);
	
	size = SizeOf(state_set);
	
	acc = input_val;
	*out_ts = ts;
	count = 1.0;
	read = 0;
	while((ReadEntry(state_set,&curr_ts,&curr_val) != 0) &&
	      (count < tau))
	{
		read += 1;
		
		/*
		 * -1 because input_val counts
		 */
		if((size - read) < (tau-1))
		{
			acc += curr_val;
/*
printf("%f ",curr_val);
*/
			count += 1;
		}
	}
	
/*
printf("%f ",input_val);
printf(" | ");
*/

	*out_val = acc / count;
	
	Rewind(state_set);
	return(1);
}
Пример #4
0
void SDTSPolygonReader::AssembleRings( SDTSTransfer * poTransfer,
                                       int iPolyLayer )

{
    if( bRingsAssembled )
        return;

    bRingsAssembled = TRUE;

/* -------------------------------------------------------------------- */
/*      To write polygons we need to build them from their related      */
/*      arcs.  We don't know off hand which arc (line) layers           */
/*      contribute so we process all line layers, attaching them to     */
/*      polygons as appropriate.                                        */
/* -------------------------------------------------------------------- */
    for( int iLineLayer = 0;
         iLineLayer < poTransfer->GetLayerCount();
         iLineLayer++ )
    {
        if( poTransfer->GetLayerType(iLineLayer) != SLTLine )
            continue;

        SDTSLineReader *poLineReader = reinterpret_cast<SDTSLineReader *>(
            poTransfer->GetLayerIndexedReader( iLineLayer ) );
        if( poLineReader == nullptr )
            continue;

        poLineReader->AttachToPolygons( poTransfer, iPolyLayer );
        poLineReader->Rewind();
    }

    if( !IsIndexed() )
        return;

/* -------------------------------------------------------------------- */
/*      Scan all polygons indexed on this reader, and assemble their    */
/*      rings.                                                          */
/* -------------------------------------------------------------------- */
    Rewind();

    SDTSFeature *poFeature = nullptr;
    while( (poFeature = GetNextFeature()) != nullptr )
    {
        SDTSRawPolygon  *poPoly
            = reinterpret_cast<SDTSRawPolygon *>( poFeature );

        poPoly->AssembleRings();
    }

    Rewind();
}
Пример #5
0
void logger::OpenFile(string const& path)
{
	filePath = path;

	//检查文件是否存在
	fstream file;
	file.open(path + SUFFIX_LOG, ios::in | ios::out | ios::binary);
	if (!file)
	{
		cerr << "No file!" << endl;
		exit(EXIT_FAILURE);
	}

	//检查文件大小是否正确
	int begin = file.tellg();
	file.seekg(0, ios::end);
	int end = file.tellg();
	if ((end - begin) < 4)
	{
		cerr << "Size error!" << endl;
		exit(EXIT_FAILURE);
	}

	//初始化logger类中的fileSize和xChecksum
	fileSize = end - begin;
	file.seekp(0, ios::beg);
	file.read((char*)(&xChecksum), 4);//读取文件中存储的xChecksum
	file.close();

	//对log文件大小进行核查
	Rewind();
	uint32_t  xChecksum_tmp = checkLogFile();
	Rewind();
	//文件大小与xChecksum记录的大小不一致,删除文件
	if (xChecksum != xChecksum_tmp)
	{

		cerr << "xChecksum error!" << endl << "Bad log file!" << endl;
		//是否Truncate? 是的,Truncate!
		// TODO
		//由于更新xCheckSum的时候数据库发生崩溃, 则会导致整个log文件不能使用.
		//所以暂时放弃xCheckSum, 之后将xCheckSum改为由booter管理.
		fstream file(path + SUFFIX_LOG, ios::trunc);
		if (file.is_open())
		{
			file.close();
		}
		exit(EXIT_FAILURE);
	}
}
Пример #6
0
int CopyDataSet(void *s, void *d, int count)
{
    DataSet *src = (DataSet *)s;
    DataSet *dst = (DataSet *)d;
    int i;
    int j;

    if(count > SizeOf(src))
    {
        return(0);
    }

    if(src->fields != dst->fields)
    {
        return(0);
    }

    while(SizeOf(dst) < count)
    {
        ExpandData((void *)dst);
    }

    for(i=0; i < count; i++)
    {
        for(j=0; j < src->fields; j++)
        {
            dst->data[j][i] = src->data[j][i];
        }
    }
    dst->data_c = count;
    Rewind(dst);

    return(1);
}
Пример #7
0
xyMultimap_t baseXYData::GetAccumulation(bool inProcents )
{
	double x,y,n=0;
	xyMultimap_t map;
	std::map<double, int> tmp;
	std::map<double, int>::iterator it;

	// loop all values
	// increment tmp[y] by one when occur
	Rewind();
	while( GetNextXY(x, y) )
	{
		if(tmp.find(y)==tmp.end())tmp[y]=1;
		else tmp[y]++;
		n++;
	}
	// insert values to result map
	// map[Y] = number of value occurs
	for(it=tmp.begin(); it != tmp.end(); ++it)
	{
		y = it->second;
		if(inProcents) y=(y/n)*100.0;
		map.insert(pair<double, double>(it->first, y ) );
	}
	return map;
}
Пример #8
0
xyMultimap_t baseXYData::GetDNL(bool arithMean, double *En, std::vector<double> *Evect)
{
	xyMultimap_t map;
	int i=0;
	double  E=0 //expected value
			,ysum = getYsum()
			,xmax = GetMaxX()
			,x=0,y=0;

	if(arithMean) E = getArithmeticMean();
	else if(En) E=*En;
	else if (Evect==0 ) E = ( ysum / (xmax+1) );            //default
	else if (Evect->size() != m_data.size() ) return map;   //must be same size

	Rewind();
	while( GetNextXY(x, y) )
	{
		if(!arithMean && Evect==0) y = y / E - 1;
		else if(arithMean) y -= E;
		else if(Evect) y -= (*Evect)[i++];

		if(Evect){
			y /= (*Evect)[i-1];
		} else{
			y /= E;
		}

		map.insert(pair<double, double>(x,y));

	}
	return map;
}
Пример #9
0
int checkRepeatExpression(char *expression)
{
	Rewind();

	char *first = nextToken();
	char *second = nextToken();
	char *third = nextToken();
	char *fourth = nextToken();
	char *fifth = nextToken();

	if (checkREPEAT(first, strlength(first))&&
		checkN(second, strlength(second))&&
		checkTIMES(third, strlength(third))&&
		checkCommandList(fourth, strlength(fourth))&&
		checkEND(fifth, strlength(fifth))) 
	{
		free(first);
		free(second);
		free(third);
		free(fourth);
		free(fifth);
		return 1;
	} else 
	{
		free(first);
		free(second);
		free(third);
		free(fourth);
		free(fifth);
		return 0;
	}

	return 1;
}
Пример #10
0
HRESULT
SoundD3D::Play()
{
	if (IsPlaying())  return S_OK;
	if (!buffer)      return E_FAIL;

	HRESULT hr = E_FAIL;

	if (IsDone())
	hr = Rewind();

	if (IsReady()) {
		if (moved)
		Localize();

		if (flags & LOOP || flags & STREAMED)
		hr = buffer->Play(0, 0, DSBPLAY_LOOPING);
		else
		hr = buffer->Play(0, 0, 0);

		if (SUCCEEDED(hr))
		status = PLAYING;
	}

	return hr;
}
Пример #11
0
bool
EMInputRepository	::	SetAsActiveMIDIInput(int32 p_vInputID, int32 p_vOutputID)
{
	LockContainer();
	try
	{
		Rewind();
		while(Current() != NULL)
		{
			EMRealtimeInputDescriptor* opInput = Current();
			if((opInput -> GetType() & EM_TYPE_MIDI) > 0)
			{
				EMRealtimeMIDIInputDescriptor* opMIDIInput =
					 static_cast<EMRealtimeMIDIInputDescriptor*>(opInput);

				if(opMIDIInput -> GetID() == p_vInputID)
					opMIDIInput -> SetActive(true, p_vOutputID);
				else
					opMIDIInput -> SetActive(false, 0);
			}
			Next();
		}
	}
	catch(...)
	{
		EMDebugger("ERROR! Exception while setting active MIDI track!");
	}
	UnlockContainer();
	return true;
}
Пример #12
0
void hsStream::SetPosition(uint32_t position)
{
    if (position == fPosition)
        return;
    Rewind();
    Skip(position);
}
Пример #13
0
int64 EMMediaClipRepository::CountClipsForTrack(const EMMediaTrack* p_opTrack, EMMediaType p_eSpecType)
{
	int64 vCount = 0;
	LockContainer();
	try
	{
		Rewind();
		while(Current() != NULL)
		{
			if(Current() -> GetTrack() -> GetID() == p_opTrack -> GetID() &&
				! Current() -> IsObjectDeleted() && (p_eSpecType & Current() -> GetType()) != 0)
				vCount++;

			if(Current() -> GetTrack() == NULL)
				EMDebugger("ERROR! NULL as track owner!");
			Next();
		}
	}
	catch(...)
	{
		EMDebugger("ERROR! Exception in EMMediaClipRepository::CountClipsForTrack");
	}
	UnlockContainer();
	return vCount;
}
Пример #14
0
void
vsDisplayList::ApplyOffset(const vsVector2D &offset)
{
	vsAssert( !m_instanceParent, "Tried to apply an offset to an instanced display list!" );

	vsTransform2D currentTransform;

	Rewind();
	op *o = PopOp();

	while(o)
	{
		if ( o->type == OpCode_VertexArray )
		{
			vsVector3D pos;
			int count = o->data.GetUInt();
			float *shuttle = (float *) o->data.p;

			for ( int i = 0; i < count; i++ )
			{
				shuttle[0] += offset.x;
				shuttle[1] += offset.y;

				shuttle += 3;
			}
		}

		o = PopOp();
	}
}
Пример #15
0
VolumeRoster::VolumeRoster(const char* options)
{
	// TODO:
	std::string string("export LC_ALL=C; ");
	string.append("df ").append(options);
	CommandStreamBuffer df(string.c_str(), "r");
	std::istream stream(&df);

	std::string line;
	std::getline(stream, line); // Skip the first line
	while (std::getline(stream, line)) {
		std::istringstream iss(line);

		volume_info info;
		std::string dummy;
		iss >> info.name;
		iss >> info.total;
		iss >> dummy;
		iss >> info.free;
		iss >> dummy;
		iss >> info.type;

		// TODO: filesystem, other
		fItems.push_back(info);
	}

	Rewind();
}
Пример #16
0
XnStatus PlayerNode::HandleEndRecord(EndRecord record)
{
	XN_VALIDATE_INPUT_PTR(m_pNodeNotifications);
	XnStatus nRetVal = record.Decode();
	XN_IS_STATUS_OK(nRetVal);
	DEBUG_LOG_RECORD(record, "End");

	if (!m_bDataBegun)
	{
		XN_LOG_WARNING_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI, "File does not contain any data!");
	}

	nRetVal = m_eofReachedEvent.Raise();
	XN_IS_STATUS_OK(nRetVal);

	if (m_bRepeat)
	{
		nRetVal = Rewind();
		XN_IS_STATUS_OK(nRetVal);
	}
	else
	{
		m_bEOF = TRUE;
		CloseStream();
	}

	return XN_STATUS_OK;	
}
Пример #17
0
static afs_int32
rewindFile(struct butm_tapeInfo *info)
{
    struct progress *p;
    afs_int32 code = 0;
    afs_int32 error;

    p = (struct progress *)info->tmRock;

    POLL();

    error = Rewind(p->fid);

    POLL();

    if (error) {
	info->status |= BUTM_STATUS_SEEKERROR;
	ERROR_EXIT(BUTM_IOCTL);
    }

    info->position = (isafile ? 0 : 1);
    info->kBytes = info->nBytes = 0;
    info->nFiles = info->nRecords = 0;
    p->reading = p->writing = 0;

  error_exit:
    if (error)
	info->error = error;
    return (code);
}
Пример #18
0
void Mp3Decoder::OpenFile()
{
    GuardPtr = NULL;
    ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks);
    if(!ReadBuffer)
    {
        if(file_fd)
            delete file_fd;
        file_fd = NULL;
        return;
    }

    u8 dummybuff[4096];
    int ret = Read(dummybuff, 4096, 0);
    if(ret <= 0)
    {
        if(file_fd)
            delete file_fd;
        file_fd = NULL;
        return;
    }

    SampleRate = (u32) Frame.header.samplerate;
    Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT);
    Rewind();
    Decode();
}
Пример #19
0
void StdFileInput::SetPosition(std::size_t n)
{
    Rewind();
    
    for (std::size_t i = 0; i < n; ++i)
        Next();
}
int OGRXPlaneReader::StartParsing( const char * pszFilename )
{
    fp = VSIFOpen( pszFilename, "rt" );
    if (fp == NULL)
        return FALSE;

    const char* pszLine = CPLReadLine(fp);
    if (!pszLine || (strcmp(pszLine, "I") != 0 &&
                     strcmp(pszLine, "A") != 0))
    {
        VSIFClose(fp);
        fp = NULL;
        return FALSE;
    }

    pszLine = CPLReadLine(fp);
    if (!pszLine || IsRecognizedVersion(pszLine) == FALSE)
    {
        VSIFClose(fp);
        fp = NULL;
        return FALSE;
    }

    CPLFree(this->pszFilename);
    this->pszFilename = CPLStrdup(pszFilename);

    nLineNumber = 2;
    CPLDebug("XPlane", "Version/Copyright : %s", pszLine);

    Rewind();

    return TRUE;
}
Пример #21
0
void MPEG::RenderFinal(SDL_Surface *dst, int x, int y)
{
    Stop();
    if ( VideoEnabled() ) {
        videoaction->RenderFinal(dst, x, y);
    }
    Rewind();
}
Пример #22
0
bool Loader::MoveTo(int pos)
{
	int curPos = ftell(f);
	if (curPos > pos)
		return Rewind(curPos - pos);
	else
		return FastForward(pos - curPos);
}
Пример #23
0
	DirectoryCookie(Directory* directory)
		:
		directory(directory),
		state(0),
		registered(false)
	{
		Rewind();
	}
Пример #24
0
/*!	\brief Returns the number of entries in this directory.
	CountEntries() uses the directory iterator also used by GetNextEntry(),
	GetNextRef() and GetNextDirents(). It does a Rewind(), iterates through
	the entries and Rewind()s again. The entries "." and ".." are not counted.
	\return
	- the number of entries in the directory (not counting "." and "..").
	- \c B_PERMISSION_DENIED: Directory permissions didn't allow operation.
	- \c B_NO_MEMORY: Insufficient memory for operation.
	- \c B_LINK_LIMIT: Indicates a cyclic loop within the file system.
	- \c B_BUSY: A node was busy.
	- \c B_FILE_ERROR: A general file error.
	- \c B_NO_MORE_FDS: The application has run out of file descriptors.
	\see GetNextEntry(), GetNextRef(), GetNextDirents(), Rewind()
*/
int32
BDirectory::CountEntries()
{
	status_t error = Rewind();
	if (error != B_OK)
		return error;
	int32 count = 0;
	BPrivate::Storage::LongDirEntry entry;
	while (error == B_OK) {
		if (GetNextDirents(&entry, sizeof(entry), 1) != 1)
			break;
		if (strcmp(entry.d_name, ".") != 0 && strcmp(entry.d_name, "..") != 0)
			count++;
	}
	Rewind();
	return (error == B_OK ? count : error);
}
Пример #25
0
TreeIterator::TreeIterator(BPlusTree* tree, struct btrfs_key &key)
	:
	fTree(tree),
	fCurrentKey(key)
{
	Rewind();
	tree->_AddIterator(this);
}
Пример #26
0
void MPEG::RenderFinal()
{
    Stop();
    if ( VideoEnabled() ) {
        videoaction->RenderFinal();
    }
    Rewind();
}
OverlaysEnum::OverlaysEnum(OverlaysContainer *pOverlays)
	: refCount(0)
{
	//	Create a copy of overlays.
	for each (Overlay *p in *pOverlays)
		overlays.push_back(p);

	Rewind();
}
Пример #28
0
void StringList::Reset()
{
  Rewind();
  StringData.Reset();
  StringDataW.Reset();
  PosDataW.Reset();
  StringsCount=0;
  SavePosNumber=0;
}
Пример #29
0
BRecentItemsList::BRecentItemsList(int32 maxItems, bool navMenuFolders)
	:
	fMaxItems(maxItems),
	fNavMenuFolders(navMenuFolders)
{
	InitIconPreloader();
		// need the icon cache
	Rewind();
}
Пример #30
0
//-------------------------------------------------------------------------------------------------
void KeyValues::Erase() {

	for( unsigned int i = 0; i < root.values.size(); i++ ) {
		DeleteSection( root.values[i].section );
	}
	
	Rewind();

}