Exemplo n.º 1
0
void
AliasDB::getAliases (
    const Url& contactIdentity,
    ResultSet& rResultSet ) const
{
    UtlString contactIdentityStr;
    contactIdentity.getIdentity(contactIdentityStr);

    // This should erase the contents of the existing resultset
    rResultSet.clear();

    if ( !contactIdentityStr.isNull() && (m_pFastDB != NULL) )
    {
        // Thread Local Storage
        m_pFastDB->attach();

        // Match a all rows where the contact identity matches
        UtlString queryString = "contact like '%" + contactIdentityStr + "%'";

        dbQuery query;
        query=queryString;

        // Search to see if we have a Credential Row
        dbCursor< AliasRow > cursor;

        if ( cursor.select(query) > 0 )
        {
            do {
                UtlHashMap record;
                UtlString* identityValue =
                    new UtlString ( cursor->identity );
                UtlString* contactValue =
                    new UtlString ( cursor->contact );

                // Memory Leak fixes, make shallow copies of static keys
                UtlString* identityKey = new UtlString( gIdentityKey );
                UtlString* contactKey = new UtlString( gContactKey );

                record.insertKeyAndValue (
                    identityKey, identityValue );
                record.insertKeyAndValue (
                    contactKey, contactValue );

                rResultSet.addValue(record);
            } while ( cursor.next() );
        }
        // Commit the rows to memory - multiprocess workaround
        m_pFastDB->detach(0);
    }
}
Exemplo n.º 2
0
void
AliasDB::getContacts (
    const Url& identity,
    ResultSet& rResultSet ) const
{
    UtlString identityStr;
    identity.getIdentity(identityStr);

    // This should erase the contents from the resultset object
    rResultSet.clear();

    if ( !identityStr.isNull() && (m_pFastDB != NULL) )
    {
        // Thread Local Storage
        m_pFastDB->attach();

        dbQuery query;

        // Primary Key is the urialias's identity
        query="identity=",identityStr;

        // Search to see if we have a Credential Row
        dbCursor< AliasRow > cursor;

        if ( cursor.select(query) > 0 )
        {
            do {
                UtlHashMap record;
                UtlString* identityValue =
                    new UtlString ( cursor->identity );
                UtlString* contactValue =
                    new UtlString ( cursor->contact );

                // Memory Leak fixes, make shallow copies of static keys
                UtlString* identityKey = new UtlString( gIdentityKey );
                UtlString* contactKey = new UtlString( gContactKey );

                record.insertKeyAndValue (
                    identityKey, identityValue );
                record.insertKeyAndValue (
                    contactKey, contactValue );

                rResultSet.addValue(record);
            } while ( cursor.next() );
        }
        // Commit the rows to memory - multiprocess workaround
        m_pFastDB->detach(0);
    }
}
Exemplo n.º 3
0
size_t Language::TypeScavenger::Find(ExecutionContextScope *exe_scope,
                                     const char *key, ResultSet &results,
                                     bool append) {
  if (!exe_scope || !exe_scope->CalculateTarget().get())
    return false;

  if (!key || !key[0])
    return false;

  if (!append)
    results.clear();

  size_t old_size = results.size();

  if (this->Find_Impl(exe_scope, key, results))
    return results.size() - old_size;
  return 0;
}
Exemplo n.º 4
0
void 
UserLocationDB::getLocations (
    const UtlString& identityString,
    ResultSet& rResultSet ) const
{
    // This should erase the contents of the existing resultset
    rResultSet.clear();

    if ( !identityString.isNull() && ( m_pFastDB != NULL) )
    {
        // Thread Local Storage
        m_pFastDB->attach();
        dbQuery query;
        query="identity=",identityString;

        // Search to see if we have a Credential Row
        dbCursor< UserLocationRow > cursor;

        if ( cursor.select(query) > 0 )
        {
            do {
                UtlHashMap record;
                UtlString* identityValue = 
                    new UtlString ( cursor->identity );
                UtlString* locationValue = 
                    new UtlString ( cursor->location );

                // Memory Leak fixes, make shallow copies of static keys
                UtlString* identityKey = new UtlString( gIdentityKey );
                UtlString* locationKey = new UtlString( gLocationKey );

                record.insertKeyAndValue ( 
                    identityKey, identityValue );
                record.insertKeyAndValue ( 
                    locationKey, locationValue );

                rResultSet.addValue(record);
            } while ( cursor.next() );
        }
        // Commit the rows to memory - multiprocess workaround
        m_pFastDB->detach(0);
    }
}
Exemplo n.º 5
0
void
CredentialDB::getAllCredentials (
    const Url& uri,
    ResultSet& rResultSet ) const
{
    UtlString identity;
    uri.getIdentity(identity);

    // This should erase the contents of the existing resultset
    rResultSet.clear();

    if ( !identity.isNull() && (m_pFastDB != NULL) )
    {
        // Thread Local Storage
        m_pFastDB->attach();

        // Search to see if we have a Credential Row
        dbCursor< CredentialRow > cursor;

        dbQuery query;
        query="np_identity=",identity;

        if ( cursor.select( query ) > 0 )
        {
            do {
                UtlHashMap record;
                UtlString* uriValue = 
                    new UtlString ( cursor->uri );
                UtlString* realmValue = 
                    new UtlString ( cursor->realm );
                UtlString* useridValue = 
                    new UtlString ( cursor->userid );
                UtlString* passtokenValue = 
                   new UtlString ( cursor->passtoken );
                UtlString* pintokenValue = 
                   new UtlString ( cursor->pintoken );
                UtlString* authtypeValue = 
                    new UtlString ( cursor->authtype );

                // Memory Leak fixes, make shallow copies of static keys
                UtlString* uriKey = new UtlString( gUriKey );
                UtlString* realmKey = new UtlString( gRealmKey );
                UtlString* useridKey = new UtlString( gUseridKey );
                UtlString* passtokenKey = new UtlString( gPasstokenKey );
                UtlString* pintokenKey = new UtlString( gPintokenKey );
                UtlString* authtypeKey = new UtlString( gAuthtypeKey );

                record.insertKeyAndValue ( uriKey, uriValue );
                record.insertKeyAndValue ( realmKey, realmValue );
                record.insertKeyAndValue ( useridKey, useridValue );
                record.insertKeyAndValue ( passtokenKey, passtokenValue );
                record.insertKeyAndValue ( pintokenKey, pintokenValue );
                record.insertKeyAndValue ( authtypeKey, authtypeValue );

                rResultSet.addValue(record);
            } while ( cursor.next() );
        }
        // Commit the rows to memory - multiprocess workaround
        m_pFastDB->detach(0);
    }
}
Exemplo n.º 6
0
	bool Classifier::processFeatures(const FeatureVector& featureVector, ResultSet &results)
	{
		//K-nearest-neighbour
		const int K = 10;

		Neighbour neighbours[K];
		Neighbour& lastNeighbour = neighbours[K-1];
		for(int i = 0; i < K; ++i){ neighbours[i].symbol = 0; neighbours[i].dist = 0.0f; }

		//Loop through all symbols
		for(unsigned int i = 0; i < database->getSymbolCount(); ++i)
		{
			void* symbolHandle = database->getSymbolHandle(i);

			//Loop through all sample points of this symbol
			for(unsigned int j = 0; j < database->getSymbolFeatureCount(symbolHandle, FeatureTypeVector); ++j)
			{
				float distance = getDistance(featureVector, *(FeatureVector*)database->getSymbolFeature(symbolHandle, FeatureTypeVector, j));

				if( lastNeighbour.symbol == 0 || distance < lastNeighbour.dist )
				{
					//See where it should be in the array
					for(int i = 0; i < K; ++i)
					{
						if( neighbours[i].symbol == 0 ) //If we did not have K neighbours yet
						{
							neighbours[i].symbol = symbolHandle;
							neighbours[i].dist = distance;
							break;
						}
						if( distance < neighbours[i].dist )
						{
							//shift the remaining neighbours
							for(int j = K-1; j > i; --j)
							{
								neighbours[j].symbol = neighbours[j-1].symbol;
								neighbours[j].dist = neighbours[j-1].dist;
							}
							neighbours[i].symbol = symbolHandle;
							neighbours[i].dist = distance;
							break;
						}
					}
				}
			}
		}
		//Now generate the scores
		results.clear();
		for(int i = 0; i < K; ++i)
		{
			if( neighbours[i].symbol == 0 ) break; //no more neighbours
			const char* symbol = database->getSymbolString(neighbours[i].symbol);
			if( symbol == 0 ) continue;
			float score = 1 - 0.2f*neighbours[i].dist;
			if( score <= 0.0f ) break;
			//Check if this symbol was already in the result set
			bool found = false;
			for(unsigned int j = 0; j < results.size(); ++j)
			{
				if( results[j].symbol == symbol )
				{
					results[j].score += 0.5f*score;
					found = true;
					break;
				}
			}
			if( found == false )
			{
				results.push_back(Result(symbol, score));
			}
		}
		//TODO:
		//If there is a single neighbour really close and all other neighbours much further away
		//then the score of this single neighbour should be higher since it may be the only sample of a feature
		bool certain = false;
		for(unsigned int j = 0; j < results.size(); ++j)
		{
			if( results[j].score > 0.6 )
			{
				certain = true;
				break;
			}
		}
#if LDEBUG
		if( neighbours[0].symbol == 0 ) std::cout << "No best symbol found.\n";
		else
		{
			std::cout << "Nearest neighbours:";
			for(int i = 0; i < K; ++i)
			{
				const char* symbol = database->getSymbolString(neighbours[i].symbol);
				if( symbol == 0 ) std::cout << " ERR";
				else std::cout << " " << symbol;
				std::cout << "(" << std::setprecision(3) << neighbours[i].dist << ")";
			}
			std::cout << std::endl;
		}
#endif
		return certain;
	}
Exemplo n.º 7
0
	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();
	}