_LUCENE_THREAD_FUNC(atomicIndexTest, _writer){
  IndexWriter* writer= (IndexWriter*)_writer;
  uint64_t stopTime = Misc::currentTimeMillis() + 1000*ATOMIC_SEARCH_RUN_TIME_SEC;
  int count = 0;
  try {
    while(Misc::currentTimeMillis() < stopTime && !atomicSearchFailed) {
      // Update all 100 docs...
      TCHAR buf[30];
      StringBuffer sb;
      for(int i=0; i<100; i++) {
        Document d;
        _i64tot(rand(), buf, 10);

        sb.clear();
        English::IntToEnglish(i+10*count, &sb);
        d.add(*_CLNEW Field(_T("contents"), sb.getBuffer() , Field::STORE_NO | Field::INDEX_TOKENIZED));

        _i64tot(i,buf,10);
        d.add(*_CLNEW Field(_T("id"), buf, Field::STORE_YES | Field::INDEX_UNTOKENIZED));
        Term* t = _CLNEW Term(_T("id"), buf);
        writer->updateDocument(t, &d);
        _CLDECDELETE(t);
      }

      count++;
    }
  } catch (CLuceneError& e) {
    fprintf(stderr, "err 1: #%d: %s\n", e.number(), e.what());
    atomicSearchFailed = true;
  }

  _LUCENE_THREAD_FUNC_RETURN(0);
}
Esempio n. 2
0
void CEffectsListDlg::initEffectsListDlg(HWND dlgHwnd)
{
	hwnd = dlgHwnd;
	lHwnd = GetDlgItem(dlgHwnd,IDC_EFFECTSLIST);
	t1Hwnd = GetDlgItem(dlgHwnd, IDC_FXSTART);
	t2Hwnd = GetDlgItem(dlgHwnd, IDC_FXSTOP);
	trkHwnd = GetDlgItem(dlgHwnd, IDC_FXTRACK);
	swapHwnd = GetDlgItem(dlgHwnd, IDC_SWAPINPUTS);
	TCHAR data[256];
	_i64tot(start, data, 10);
	SendMessage(t1Hwnd, WM_SETTEXT, 0, (LPARAM)data);
	_i64tot(stop, data, 10);
	SendMessage(t2Hwnd, WM_SETTEXT, 0, (LPARAM)data);
	_itot(track, data, 10);
	SendMessage(trkHwnd, WM_SETTEXT, 0, (LPARAM)data);
	if(type)
	{
		SendMessage(dlgHwnd, WM_SETTEXT, 0, (LPARAM)_T("Add Transition"));
		ShowWindow(swapHwnd, SW_SHOW);
		if(type > TYPE_TRANS)
		{
			EnableWindow(trkHwnd, FALSE);
			EnableWindow(swapHwnd, FALSE);
			if(swap)SendMessage(swapHwnd, BM_SETCHECK, BST_CHECKED, 0);
		}
	}
	ListEffects();
}
TCHAR *StreamParameters::addWidth(TCHAR *dst) const {
  if(m_width != 0) {
    _i64tot(m_width,dst,10);
    dst += _tcsclen(dst);
  }
  return dst;
}
Esempio n. 4
0
std::string Misc::toString(const int64_t value){
  char buf[20];
  TCHAR tbuf[20];
  _i64tot(value, tbuf, 10);
  STRCPY_TtoA(buf,tbuf,20);
  return buf;
}
void DateField::timeToString(const int64_t time, TCHAR* buf) {
    CND_PRECONDITION (buf, "buf == NULL");
    *buf = '\0';
	if (time < 0)
	  _CLTHROWA (CL_ERR_IllegalArgument,"time too early"); //todo: make richer error

	if (time > DATEFIELD_DATE_MAX)
	  _CLTHROWA (CL_ERR_IllegalArgument, "time too late (past DATEFIELD_DATE_MAX"); //todo: make richer error
	
	_i64tot(time, buf, 36);
	int32_t bufLen = _tcslen(buf);
	
	CND_PRECONDITION (bufLen <= DATEFIELD_DATE_LEN, "timeToString length is greater than 9");
	
	/* Supply leading zeroes if necessary. */
	if (bufLen < DATEFIELD_DATE_LEN) {
	  const int32_t nMissingZeroes = DATEFIELD_DATE_LEN - bufLen;
	  /* Move buffer contents forward to make room for leading zeroes. */
	  for (int32_t i = DATEFIELD_DATE_LEN - 1; i >= nMissingZeroes; i--)
	    buf[i] = buf[i - nMissingZeroes];
	  
	  /* Insert leading zeroes. */
	  {// MSVC6 scoping fix
	  for (int32_t i = 0; i < nMissingZeroes; i++)
	    buf[i] = '0';
	  }
	
	  buf[DATEFIELD_DATE_LEN] = 0;
	}
	
	CND_PRECONDITION (_tcslen(buf) == DATEFIELD_DATE_LEN, "timeToString return is not equal to DATEFIELD_DATE_LEN");
}
TCHAR *StreamParameters::addPrecision(TCHAR *dst) const {
  if(m_precision != 0) {
    *(dst++) = _T('.');
    _i64tot(m_precision,dst,10);
    dst += _tcsclen(dst);
  }
  return dst;
}
Esempio n. 7
0
  void StringBuffer::appendInt(const int32_t value) {
  //Func - Appends an integer (after conversion to a character string)
  //Pre  - true 
  //Post - The converted integer value has been appended to the string in buffer
  
      //instantiate a buffer of 30 charactes for the conversion of the integer
      TCHAR buf[30];
      //Convert the integer value to a string buf using the radix 10 (duh)
      _i64tot(value, buf, 10);
	  //Have the converted integer now stored in buf appended to the string in buffer
      append(buf);
  }
Esempio n. 8
0
  void StringBuffer::appendFloat(const float_t value, const int32_t digits){
  //Func - Appends a float_t (after conversion to a character string)
  //Pre  - digits > 0. Indicates the minimum number of characters printed
  //Post - The converted float_t value has been appended to the string in buffer

    //using sprintf("%f" was not reliable on other plaforms... we use a custom float convertor
    //bvk: also, using sprintf and %f seems excessivelly slow
	if(digits>8)
		_CLTHROWA(CL_ERR_IllegalArgument,"Too many digits...");

	  //the maximum number of characters that int64 will hold is 23. so we need 23*2+2
	 TCHAR buf[48]; //the buffer to hold
	 int64_t v = (int64_t)value; //the integer value of the float
	 _i64tot(v,buf,10); //add the whole number

	 size_t len = 99-_tcslen(buf); //how many digits we have to work with?
	 size_t dig = len< (size_t)digits ? len : digits;
	 if ( dig > 0 ){
		_tcscat(buf,_T(".")); //add a decimal point

		int64_t remi=(int64_t)((value-v)*pow((float_t)10,(float_t)(dig+1))); //take the remainder and make a whole number
		if ( remi<0 ) remi*=-1;
		int64_t remadj=remi/10;
		if ( remi-(remadj*10) >=5 )
			remadj++; //adjust remainder

		// add as many zeros as necessary between the decimal point and the
		// significant part of the number. Fixes a bug when trying to print
		// numbers that have zeros right after the decimal point
		if (remadj) {
			int32_t numZeros = dig - (int32_t)log10((float_t)remadj) - 1;
		    while(numZeros-- > 0)
				_tcscat(buf,_T("0")); //add a zero before the decimal point
		}

		_i64tot(remadj,buf+_tcslen(buf),10); //add the remainder
	 }

	 append(buf);
  }
Esempio n. 9
0
void SegmentMerger::createCompoundFile(const QString& filename, QStringList& files)
{
    CompoundFileWriter* cfsWriter = _CLNEW CompoundFileWriter(directory, filename);

    { //msvc6 scope fix
        // Basic files
        for (int32_t i = 0; i < COMPOUND_EXTENSIONS_LENGTH; i++) {
            files.push_back(Misc::qjoin(segment, QLatin1String("."),
                QLatin1String(COMPOUND_EXTENSIONS+(i*4))));
        }
    }

    { //msvc6 scope fix
        // Field norm files
        for (int32_t i = 0; i < fieldInfos->size(); i++) {
            FieldInfo* fi = fieldInfos->fieldInfo(i);
            if (fi->isIndexed && !fi->omitNorms) {
                TCHAR tbuf[10];
                char abuf[10];
                _i64tot(i, tbuf, 10);
                STRCPY_TtoA(abuf, tbuf, 10);

                files.push_back(Misc::qjoin(segment, QLatin1String(".f"),
                    QLatin1String(abuf)));
            }
        }
    }

    // Vector files
    if (fieldInfos->hasVectors()) {
        for (int32_t i = 0; i < VECTOR_EXTENSIONS_LENGTH; i++) {
            files.push_back(Misc::qjoin(segment, QLatin1String("."),
                QLatin1String(VECTOR_EXTENSIONS+(i*4))));
        }
    }

    { //msvc6 scope fix
        // Now merge all added files
        for (size_t i=0;i<files.size();i++) {
            cfsWriter->addFile(files[i]);
        }
    }

    // Perform the merge
    cfsWriter->close();
    _CLDELETE(cfsWriter);
}
Esempio n. 10
0
/*
  Run one indexer and 2 searchers against single index as
  stress test.
 */
void runThreadingTests(CuTest* tc, Directory& directory){

  SimpleAnalyzer ANALYZER;
  IndexWriter writer(&directory, &ANALYZER, true);

  // Establish a base index of 100 docs:
  StringBuffer sb;
  TCHAR buf[10];
  for(int i=0;i<100;i++) {
    Document d;
    _i64tot(i,buf,10);
    d.add(*_CLNEW Field(_T("id"), buf, Field::STORE_YES | Field::INDEX_UNTOKENIZED));

    sb.clear();
    English::IntToEnglish(i, &sb);
    d.add(*_CLNEW Field(_T("contents"), sb.getBuffer(), Field::STORE_NO | Field::INDEX_TOKENIZED));
    writer.addDocument(&d);
  }
  writer.flush();

  //read using multiple threads...
  atomicSearchThreads = _CL_NEWARRAY(_LUCENE_THREADID_TYPE, 4);
  atomicSearchThreads[0] = _LUCENE_THREAD_CREATE(&atomicIndexTest, &writer);
  atomicSearchThreads[1] = _LUCENE_THREAD_CREATE(&atomicIndexTest, &writer);
  atomicSearchThreads[2] = _LUCENE_THREAD_CREATE(&atomicSearchTest, &directory);
  atomicSearchThreads[3] = _LUCENE_THREAD_CREATE(&atomicSearchTest, &directory);

  for ( int i=0;i<4;i++ ){
    _LUCENE_THREAD_JOIN(atomicSearchThreads[i]);
  }
  _CLDELETE_ARRAY(atomicSearchThreads);

  writer.close();

  CuAssert(tc, _T("hit unexpected exception in one of the threads\n"), !atomicSearchFailed);
}