f_unit_t CFontStyle::operator[](const char *s) { int unicode = municode(s); { StBenaphore lock(&fLock); int i = unicode % fEscapementsCount, j = i - 1; if (j < 0) j+= fEscapementsCount; ASSERT(j >= 0); ASSERT(j < fEscapementsCount); while (true) { ASSERT(i >= 0); ASSERT(i < fEscapementsCount); if (fEscapements[i].unicode == unicode) return fEscapements[i].escapement; if (fEscapements[i].unicode == 0) { float w[1]; char buf[10]; int cl = mcharlen(s); strncpy(buf, s, cl); buf[cl] = 0; fFont.GetEscapements(buf, 1, w); w[0] *= fFont.Size(); fEscapements[i].unicode = unicode; fEscapements[i].escapement = w[0]; fCharCount++; if (fCharCount > fEscapementsCount / 2) ReHash(); return fEscapements[i].escapement; } if (i == j) { break; } i = (i + 1) % fEscapementsCount; } ReHash(); // printf("recursion for %d\n", unicode); } return operator[](s); } /* CFontStyle::operator[] */
//----------------------------------------------------------------------------- bool CLocalisationHash::AddElement(CLocalisation * _pLoc) { if (iFill >= iSize * 0.75) { ReHash(); } if (!(_pLoc && _pLoc->lpszUSection)) return false; int iKey = GetKey(_pLoc->lpszUSection); int iH1 = FuncH1(iKey); int iH2 = FuncH2(iKey); unsigned long iNbSolution = 0; while (iNbSolution < iSize) { iH1 &= iMask; if (pTab[iH1] == NULL) { pTab[iH1] = _pLoc; iFill ++; return true; } iNbCollisions ++; iH1 += iH2; iNbSolution ++; } iNbNoInsert ++; return false; }
void ListRep(struct WordList *wl, const TEXT From, const TEXT To) { ULONG i; FORWL(i, *wl) strrep(wl->Stack.Data[i], From, To); ReHash(wl); }
void MakeLower(struct WordList *wl) { ULONG i; FORWL(i, *wl) strlwr(wl->Stack.Data[i]); ReHash(wl); }
//-------------------------------- void MemoryCommand(std::string in) { std::string arg1, arg2; arg1 = in; GetFirstArg(arg2, &arg1, &arg2); int size_MB = atoi(arg1.c_str()); ReHash(size_MB); }
//-------------------------------- void SetOptionCommand(std::string in) { std::string arg1, arg2; GetFirstArg(in, &arg1, &arg2); if(arg1 != "name") return; GetFirstArg(arg2, &arg1, &arg2); if(arg1 == "Hash" || arg1 == "hash") { GetFirstArg(arg2, &arg1, &arg2); if(arg1 != "value") return; GetFirstArg(arg2, &arg1, &arg2); int size_MB = atoi(arg1.c_str()); ReHash(size_MB); } }
/* newdataをhashtableに追加する */ void AddDataToMap(HASHTABLE *hashtable, WORDSET *newdata) { unsigned int hashval; /* 英単語を元にハッシュ値を生成 */ hashval = MakeHash2(newdata->english, hashtable->size); /* もしもhashの位置がすでに埋まっていたら,再ハッシュを行う */ if(hashtable->data[hashval] != NULL) { hashval = ReHash(hashtable, hashval); /* 再ハッシュ結果が-1であれば,空き位置が見つからなかった (マップが満杯) */ if(hashval==-1) { printf("%sをマップに挿入しようと試みましたが," "空き位置がありませんでした。\n" , newdata->english); return; } } /* hashvalの位置にnewdataへのポインタを格納 */ hashtable->data[hashval] = newdata; }
void Worker::ProcessIterations(PPM* engine) { u_int64_t photonPerIteration = engine->photonsFirstIteration; uint iterationCount; resetRayBuffer(); UpdateBBox(); LookupSetHitPoints(hitPointsStaticInfo_iterationCopy, hitPoints_iterationCopy); uint iter = 0; double previousIterTime = WallClockTime(); fprintf(stdout, "iteration, photons_iter, photons_total, photons_sec, total_time, radius, device\n"); while (iter < config->max_iters) { ++iter; double start = WallClockTime(); iterationCount = engine->IncIteration(); if (engine->GetIterationNumber() > MAX_ITERATIONS) { break; } photonPerIteration = engine->photonsFirstIteration; #if defined USE_SPPMPA || defined USE_SPPM BuildHitPoints(iterationCount); UpdateBBox(); #endif #if defined USE_SPPM || defined USE_PPM if (iterationCount == 1) InitRadius(iterationCount); #else InitRadius(iterationCount); #endif updateDeviceHitPoints(); ReHash(currentPhotonRadius2);//argument ignored in non-PA updateDeviceLookupAcc(); photonPerIteration = AdvancePhotonPath(photonPerIteration); getDeviceHitpoints(); #if defined USE_PPM AccumulateFluxPPM(iterationCount, photonPerIteration); #endif #if defined USE_SPPM AccumulateFluxSPPM(iterationCount, photonPerIteration); #endif #if defined USE_SPPMPA AccumulateFluxSPPMPA(iterationCount, photonPerIteration); #endif #if defined USE_PPMPA AccumulateFluxPPMPA(iterationCount, photonPerIteration); #endif UpdateSampleFrameBuffer(photonPerIteration); /** * iteration lock required in PhotonTracedTotal */ engine->incPhotonTracedTotal(photonPerIteration); //PushHitPoints(); profiler->additeratingTime(WallClockTime() - start); profiler->addIteration(1); if (profiler->iterationCount % 100 == 0) profiler->printStats(deviceID); // if (iterationCount % 50 == 0) // engine->SaveImpl(to_string<uint> (iterationCount, std::dec) + engine->fileName); #if defined USE_SPPM || defined USE_PPM const float radius = hitPoints_iterationCopy[0].accumPhotonRadius2; #else const float radius = currentPhotonRadius2; #endif const double time = WallClockTime(); const double totalTime = time - engine->startTime; const double iterTime = time - previousIterTime; // const float itsec = engine->GetIterationNumber() / totalTime; const uint photonTotal = engine->getPhotonTracedTotal(); const float photonSec = photonTotal / (totalTime * 1000.f); fprintf(stdout, "%d, %lu, %u, %f, %f, %f, %f, %d\n", iterationCount, photonPerIteration, photonTotal, photonSec, iterTime, totalTime, radius, getDeviceID()); previousIterTime = time; } }
void Worker::ProcessIterations(PPM* engine) { u_int64_t photonPerIteration = engine->photonsFirstIteration; uint iterationCount; resetRayBuffer(); UpdateBBox(); while (!boost::this_thread::interruption_requested()) { double start = WallClockTime(); if (engine->GetIterationNumber() > config->max_iters) { break; } iterationCount = engine->IncIteration(); photonPerIteration = engine->photonsFirstIteration; // #if defined USE_SPPMPA || defined USE_SPPM BuildHitPoints(iterationCount); UpdateBBox(); // #endif // #if defined USE_SPPM || defined USE_PPM // if (iterationCount == 1) // InitRadius(iterationCount); // #else InitRadius(iterationCount); // #endif updateDeviceHitPoints(); #ifndef REBUILD_HASH if (iterationCount == 1) #endif ReHash(currentPhotonRadius2);//argument ignored in non-PA #ifndef REBUILD_HASH if (iterationCount == 1) #endif updateDeviceLookupAcc(); photonPerIteration = AdvancePhotonPath(photonPerIteration); // #if defined USE_PPM // getDeviceHitpoints(); // AccumulateFluxPPM(iterationCount, photonPerIteration); // #endif // #if defined USE_SPPM // AccumulateFluxSPPM(iterationCount, photonPerIteration); // #endif // #if defined USE_SPPMPA AccumulateFluxSPPMPA(iterationCount, photonPerIteration); // #endif // #if defined USE_PPMPA // AccumulateFluxPPMPA(iterationCount, photonPerIteration); // getDeviceHitpoints(); // #endif UpdateSampleFrameBuffer(photonPerIteration); /** * iteration lock required in PhotonTracedTotal */ engine->incPhotonTracedTotal(photonPerIteration); profiler->additeratingTime(WallClockTime() - start); profiler->addIteration(1); //if (profiler->iterationCount % 20 == 0) // profiler->printStats(deviceID); //if (iterationCount % 100 == 0) // engine->SaveImpl(to_string<uint> (iterationCount, std::dec) + engine->fileName); printf("iteration %d finished\n", iterationCount); } //profiler->printStats(deviceID); }
void ListRep(struct WordList *wl, const char From, const char To) { unsigned long i; FORWL(i, *wl) strrep(wl->Stack.Data[i], From, To); ReHash(wl); }
void MakeLower(struct WordList *wl) { unsigned long i; FORWL(i, *wl) strlwr(wl->Stack.Data[i]); ReHash(wl); }