ResultSet* ResultSet::clone () { ResultSet* ret = new ResultSet(posFactory); delete *ret->begin(); ret->erase(ret->begin()); for (ResultSetIterator it = begin() ; it != end(); it++) ret->insert(ret->begin(), (*it)->duplicate(ret, ret->end())); return ret; }
void RqlOpProcessor::normalise(float weight, ResultSet& rs) { if (weight < 0.0001) return; float sum = 0; foreach(const TrackResult& tr, rs) { sum += tr.weight; } sum /= weight; if (sum < 0.0001) return; for(ResultSet::iterator p = rs.begin(); p != rs.end(); p++) { const_cast<TrackResult*>(&(*p))->weight /= sum; } }
TEST(ResultSetTests, Basic) { ResultSet<int> songs; int& version = ResultSetMutator::getVersion<int>(songs); std::vector<int>& v = ResultSetMutator::getVector<int>(songs); EXPECT_EQ(0, version); EXPECT_TRUE(songs.empty()); EXPECT_EQ(0, songs.size()); version++; for (int i = 0; i < 10; i++) { v.push_back(i); } EXPECT_EQ(1, version); EXPECT_FALSE(songs.empty()); EXPECT_EQ(10, songs.size()); int i = 0; for (auto it = songs.begin(); it != songs.end(); it++) { ASSERT_EQ(i++, *it); } }
void PrintResults() { #if defined(EASTL_BENCHMARK_WRITE_FILE) && EASTL_BENCHMARK_WRITE_FILE FileWriter fileWriter; // This will auto-execute. #endif // Print the results EA::UnitTest::Report("\n"); EA::UnitTest::Report("****************************************************************************************\n"); EA::UnitTest::Report("EASTL Benchmark test results\n"); EA::UnitTest::Report("****************************************************************************************\n"); EA::UnitTest::Report("\n"); EA::UnitTest::Report("EASTL version: %s\n", EASTL_VERSION); EA::UnitTest::Report("Platform: %s\n", gEnvironment.msPlatform.c_str()); EA::UnitTest::Report("Compiler: %s\n", EA_COMPILER_STRING); #if defined(EA_DEBUG) || defined(_DEBUG) EA::UnitTest::Report("Allocator: PPMalloc::GeneralAllocatorDebug. Thread safety enabled.\n"); EA::UnitTest::Report("Build: Debug. Inlining disabled. STL debug features disabled.\n"); #else EA::UnitTest::Report("Allocator: PPMalloc::GeneralAllocator. Thread safety enabled.\n"); EA::UnitTest::Report("Build: Full optimization. Inlining enabled.\n"); #endif EA::UnitTest::Report("\n"); EA::UnitTest::Report("Values are ticks and time to complete tests; smaller values are better.\n"); EA::UnitTest::Report("\n"); EA::UnitTest::Report("%-42s%26s%26s%13s%13s\n", "Test", gEnvironment.msSTLName1.c_str(), gEnvironment.msSTLName2.c_str(), "Ratio", "Difference?"); EA::UnitTest::Report("---------------------------------------------------------------------------------------------------------------------\n"); eastl::string sTestTypeLast; eastl::string sTestTypeTemp; for(ResultSet::iterator it = gResultSet.begin(); it != gResultSet.end(); ++it) { const Result& result = *it; eastl_size_t n = result.msName.find('/'); if(n == eastl::string::npos) n = result.msName.length(); sTestTypeTemp.assign(result.msName, 0, n); if(sTestTypeTemp != sTestTypeLast) // If it looks like we are changing to a new test type... add an empty line to help readability. { if(it != gResultSet.begin()) EA::UnitTest::Report("\n"); sTestTypeLast = sTestTypeTemp; } PrintResultLine(result); } // We will print out a final line that has the sum of the rows printed above. Result resultSum; resultSum.msName = "sum"; for(ResultSet::iterator its = gResultSet.begin(); its != gResultSet.end(); ++its) { const Result& resultTemp = *its; EASTL_ASSERT(resultTemp.mUnits == EA::StdC::Stopwatch::kUnitsCPUCycles); // Our ConvertStopwatchUnits call below assumes that every measured time is CPUCycles. resultSum.mTime1 += resultTemp.mTime1; resultSum.mTime2 += resultTemp.mTime2; } // We do this convert as a final step instead of the loop in order to avoid loss of precision. resultSum.mTime1NS = ConvertStopwatchUnits(EA::StdC::Stopwatch::kUnitsCPUCycles, resultSum.mTime1, EA::StdC::Stopwatch::kUnitsNanoseconds); resultSum.mTime2NS = ConvertStopwatchUnits(EA::StdC::Stopwatch::kUnitsCPUCycles, resultSum.mTime2, EA::StdC::Stopwatch::kUnitsNanoseconds); EA::UnitTest::Report("\n"); PrintResultLine(resultSum); EA::UnitTest::Report("\n"); EA::UnitTest::Report("****************************************************************************************\n"); EA::UnitTest::Report("\n"); // Clear the results gResultSet.clear(); gEnvironment.clear(); }