void XmlParseMaster::StartElementHandler(void *userData, const XML_Char *name, const XML_Char **atts)
{
	SharedData * sharedData = reinterpret_cast<SharedData*>(userData);
	XmlParseMaster* parseMaster = sharedData->GetXmlParseMaster();

	if (parseMaster)
	{
		//Populate a hashmap with the attributes the Epact gives us
		HashMap<std::string, std::string> attributeHashMap;
		for (std::uint32_t i = 0; atts[i] != '\0'; i += 2)
		{
			bool inserted;
			attributeHashMap.Insert(std::string(atts[i]),std::string(atts[i+1]),inserted);
		}

		sharedData->IncrementDepth();
		for (auto it = parseMaster->mParseHelpers.begin(); it != parseMaster->mParseHelpers.end(); ++it)
		{
			std::string stringName = std::string(name);
			if ((*it)->StartElementHandler(sharedData, stringName, attributeHashMap))
			{
				break;
			}
		}
	}
}
/*
 * Main Contains Menu
 */
int main()
{
    HashMap hash;
    int key, value;
    int choice;
    while(1)
    {
        cout<<"\n----------------------"<<endl;
        cout<<"Operations on Hash Table"<<endl;
        cout<<"\n----------------------"<<endl;
        cout<<"1.Insert element into the table"<<endl;
        cout<<"2.Search element from the key"<<endl;
        cout<<"3.Delete element at a key"<<endl;
        cout<<"4.Exit"<<endl;
        cout<<"Enter your choice: ";
        cin>>choice;
        switch(choice)
        {
        case 1:
            cout<<"Enter element to be inserted: ";
            cin>>value;
            cout<<"Enter key at which element to be inserted: ";
            cin>>key;
            hash.Insert(key, value);
            break;
        case 2:
            cout<<"Enter key of the element to be searched: ";
            cin>>key;
            if(hash.Search(key) == -1)
            {
                cout<<"No element found at key "<<key<<endl;
                continue;
            }
            else
            {
                cout<<"Element at key "<<key<<" : ";
                cout<<hash.Search(key)<<endl;
            }
            break;
        case 3:
            cout<<"Enter key of the element to be deleted: ";
            cin>>key;
            hash.Remove(key);
            break;
        case 4:
            exit(1);
        default:
           cout<<"\nEnter correct option\n";
       }
    }
    return 0;
}
Exemple #3
0
int main()
{
    #ifdef _MSC_VER
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    #endif
    
    printf("Size of String: %d\n", sizeof(String));
    printf("Size of Vector: %d\n", sizeof(Vector<int>));
    printf("Size of List: %d\n", sizeof(List<int>));
    printf("Size of HashMap: %d\n", sizeof(HashMap<int, int>));
    printf("Size of RefCounted: %d\n", sizeof(RefCounted));

    {
        printf("\nTesting AutoPtr assignment\n");
        AutoPtr<Test> ptr1(new Test);
        AutoPtr<Test> ptr2;
        ptr2 = ptr1;
    }

    {
        printf("\nTesting AutoPtr copy construction\n");
        AutoPtr<Test> ptr1(new Test);
        AutoPtr<Test> ptr2(ptr1);
    }

    {
        printf("\nTesting AutoPtr detaching\n");
        AutoPtr<Test> ptr1(new Test);
        // We would now have a memory leak if we don't manually delete the object
        Test* object = ptr1.Detach();
        delete object;
    }

    {
        printf("\nTesting AutoPtr inside a vector\n");
        Vector<AutoPtr<Test> > vec;
        printf("Filling vector\n");
        for (size_t i = 0; i < 4; ++i)
            vec.Push(new Test());
        printf("Clearing vector\n");
        vec.Clear();
    }
    
    {
        printf("\nTesting SharedPtr\n");
        SharedPtr<TestRefCounted> ptr1(new TestRefCounted);
        SharedPtr<TestRefCounted> ptr2(ptr1);
        printf("Number of refs: %d\n", ptr1.Refs());
    }
    
    {
        printf("\nTesting WeakPtr\n");
        TestRefCounted* object = new TestRefCounted;
        WeakPtr<TestRefCounted> ptr1(object);
        WeakPtr<TestRefCounted> ptr2(ptr1);
        printf("Number of weak refs: %d expired: %d\n", ptr1.WeakRefs(), ptr1.IsExpired());
        ptr2.Reset();
        delete object;
        printf("Number of weak refs: %d expired: %d\n", ptr1.WeakRefs(), ptr1.IsExpired());
    }
    
    {
        printf("\nTesting Vector\n");
        HiresTimer t;
        Vector<int> vec;
        SetRandomSeed(0);
        for (size_t i = 0; i < NUM_ITEMS; ++i)
            vec.Push(Rand());
        int sum = 0;
        int count = 0;
        for (auto it = vec.Begin(); it != vec.End(); ++it)
        {
            sum += *it;
            ++count;
        }
        int usec = (int)t.ElapsedUSec();
        printf("Size: %d capacity: %d\n", vec.Size(), vec.Capacity());
        printf("Counted vector items %d, sum: %d\n", count, sum);
        printf("Processing took %d usec\n", usec);
    }

    {
        printf("\nTesting List\n");
        HiresTimer t;
        List<int> list;
        SetRandomSeed(0);
        for (size_t i = 0; i < NUM_ITEMS; ++i)
            list.Push(Rand());
        int sum = 0;
        int count = 0;
        for (auto it = list.Begin(); it != list.End(); ++it)
        {
            sum += *it;
            ++count;
        }
        int usec = (int)t.ElapsedUSec();
        printf("Size: %d\n", list.Size());
        printf("Counted list items %d, sum: %d\n", count, sum);
        printf("Processing took %d usec\n", usec);

        printf("\nTesting List insertion\n");
        List<int> list2;
        List<int> list3;
        for (int i = 0; i < 10; ++i)
            list3.Push(i);
        list2.Insert(list2.End(), list3);
        for (auto it = list2.Begin(); it != list2.End(); ++it)
            printf("%d ", *it);
        printf("\n");
    }
    
    {
        printf("\nTesting String\n");
        HiresTimer t;
        String test;
        for (size_t i = 0; i < NUM_ITEMS/4; ++i)
            test += "Test";
        String test2;
        test2.AppendWithFormat("Size: %d capacity: %d\n", test.Length(), test.Capacity());
        printf(test2.CString());
        test2 = test2.ToUpper();
        printf(test2.CString());
        test2.Replace("SIZE:", "LENGTH:");
        printf(test2.CString());
        int usec = (int)t.ElapsedUSec();
        printf("Processing took %d usec\n", usec);
    }
    
    {
        printf("\nTesting HashSet\n");
        HiresTimer t;
        size_t found = 0;
        unsigned sum = 0;
        HashSet<int> testHashSet;
        srand(0);
        found = 0;
        sum = 0;
        printf("Insert, search and iteration, %d keys\n", NUM_ITEMS);
        for (size_t i = 0; i < NUM_ITEMS; ++i)
        {
            int number = (rand() & 32767);
            testHashSet.Insert(number);
        }
        for (int i = 0; i < 32768; ++i)
        {
            if (testHashSet.Find(i) != testHashSet.End())
                ++found;
        }
        for (auto it = testHashSet.Begin(); it != testHashSet.End(); ++it)
            sum += *it;
        int usec = (int)t.ElapsedUSec();
        printf("Set size and sum: %d %d\n", testHashSet.Size(), sum);
        printf("Processing took %d usec\n", usec);
    }

    {
        printf("\nTesting HashMap\n");
        HashMap<int, int> testHashMap;

        for (int i = 0; i < 10; ++i)
            testHashMap.Insert(MakePair(i, rand() & 32767));

        printf("Keys: ");
        Vector<int> keys = testHashMap.Keys();
        for (size_t i = 0; i < keys.Size(); ++i)
            printf("%d ", keys[i]);
        printf("\n");
        printf("Values: ");
        Vector<int> values = testHashMap.Values();
        for (size_t i = 0; i < values.Size(); ++i)
            printf("%d ", values[i]);
        printf("\n");
    }

    return 0;
}
Exemple #4
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   HashMap hashmap;
   string fname = "/cpp_hashmap_getfirst";
   string hname = fname + "/test";

   const char * key  = "My Key";
   const char * data = "My Data";
   char buffer[50];
   char buffKey[50];
   uint32_t dataLength, keyLength;
   psoObjectDefinition mapDef = { PSO_HASH_MAP, 0, 0, 0 };
   psoKeyFieldDefinition keyDef = { "MyKey", PSO_KEY_VARBINARY, 20 };
   psoFieldDefinition fields[1] = {
      { "Field_1", PSO_VARCHAR, {10} } 
   };

   try {
      if ( argc > 1 ) {
         process.Init( argv[1], argv[0] );
      }
      else {
         process.Init( "10701", argv[0] );
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed in init phase, error = " << exc.Message() << endl;
      cerr << "Is the server running?" << endl;
      return 1;
   }

   try {
      session.Init();
      session.CreateFolder( fname );

      DataDefinition dataDefObj( session, 
                                 "cpp_hashmap_getfirst",
                                 PSO_DEF_PHOTON_ODBC_SIMPLE,
                                 (unsigned char *)fields,
                                 sizeof(psoFieldDefinition) );
      KeyDefinition keyDefObj( session, 
                               "cpp_hashmap_getfirst",
                               PSO_DEF_PHOTON_ODBC_SIMPLE,
                               (unsigned char *)&keyDef,
                               sizeof(psoKeyFieldDefinition) );

      session.CreateMap( hname,
                         mapDef,
                         dataDefObj,
                         keyDefObj );
      hashmap.Open( session, hname );
      hashmap.Insert( key, 6, data, 7 );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   // Invalid arguments to tested function.

   try { 
      hashmap.GetFirst( NULL, 50, buffer, 50, keyLength, dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_POINTER ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try { 
      hashmap.GetFirst( buffKey, 2, buffer, 50, keyLength, dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_INVALID_LENGTH ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try { 
      hashmap.GetFirst( buffKey, 50, NULL, 50, keyLength, dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_POINTER ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try { 
      hashmap.GetFirst( buffKey, 50, buffer, 2, keyLength, dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_INVALID_LENGTH ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   // End of invalid args. This call should succeed.
   try { 
      hashmap.GetFirst( buffKey, 50, buffer, 50, keyLength, dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }
   if ( memcmp( buffer, data, 7 ) != 0 ) {
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   
   return 0;
}
Exemple #5
0
	// Function for uploading data to hashmap 
	int uploadDB(string fileOpen) {


		// Initialization Data in Loop
		ifstream file(fileOpen.c_str()); // Twitter File
		if (!file.is_open()){

			cerr << "Failed to open file. Please try again\n\n" << endl;
			File_valid();

			return (EXIT_FAILURE);
			
		}

		for (string line; (getline(file, line));)
		{
			// User Text From Twitter
			const size_t start_pos_txt = line.find("\"text\":");
			string temp1 = line.substr(start_pos_txt + 8);
			// User Location From Twitter
			const size_t start_pos_loc = line.find("\"location\":");
			string temp2 = line.substr(start_pos_loc + 12);
			// User Number of Status From Twitter
			const size_t start_pos_SC = line.find("\"statuses_count\":");
			string temp3 = line.substr(start_pos_SC + 17);
			// User ID From Twitter 
			const size_t start_pos_Id = line.find("\"user\":{");
			string temp4 = line.substr(start_pos_Id + 8);
			const size_t stop_pos4 = temp4.find("}");
			string t_id = temp4.substr(0, stop_pos4);
			istringstream in(t_id);
			string user_line;
			string t_user_id;
			int t_userID;
			while (getline(in, user_line))
			{
				const size_t find_id = user_line.find("\"id\":");
				string pos_id = user_line.substr(find_id + 5);
				const size_t stop_pos_id2 = pos_id.find(",\"");
				t_user_id = pos_id.substr(0, stop_pos_id2);
				//t_userID = atoi(t_user_id.c_str());
			}

			// Finding Data
			const size_t start_pos_nm = line.find("\"name\":");
			string temp5 = line.substr(start_pos_nm + 8);
			const size_t start_pos_fc = line.find("\"followers_count\":");
			string temp6 = line.substr(start_pos_fc + 18);
			const size_t start_pos_fri_c = line.find("\"friends_count\":");
			string temp7 = line.substr(start_pos_fri_c + 16);

			// Stop Positions
			const size_t stop_pos1 = temp1.find("\"");
			const size_t stop_pos2 = temp2.find("\"");
			const size_t stop_pos3 = temp3.find(",\"");
			const size_t stop_pos5 = temp5.find("\"");
			const size_t stop_pos6 = temp6.find("\"");
			const size_t stop_pos7 = temp7.find("\"");
			string t_text = temp1.substr(0, stop_pos1);
			string t_loc = temp2.substr(0, stop_pos2);
			string t_status_c = temp3.substr(0, stop_pos3);
			int t_status = atoi(t_status_c.c_str());
			string t_name = temp5.substr(0, stop_pos5);
			string t_follow_c = temp6.substr(0, stop_pos6);
			int t_follow = atoi(t_follow_c.c_str());
			string t_frnd_c = temp7.substr(0, stop_pos7);
			int t_frnd = atoi(t_frnd_c.c_str());


			// Inserting Data in hashtable
			access.Tuser_id = t_user_id;
			access.Tuser_name = t_name;
			access.Tuser_txt = t_text;
			access.Tuser_loc = t_loc;
			access.Tuser_frndC = t_frnd;			
			access.Tuser_statusC = t_status;
		

			access.Tuser_followC = t_follow;
			hashMap.Insert(t_user_id, access);
					}

		file.close();
		User_Input();
	}