how can I count the total number of records in a Hash table.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • APEJMAN
    New Member
    • Feb 2008
    • 33

    #1

    how can I count the total number of records in a Hash table.

    HI
    I am trying to find out the total number of recoreds in a Hash Table.
    I am trying to write a function to calculate the total number of the recored in the Hash Table
    here is what I figure out, but I am confused now ( my code in incomplete)
    would you please guid me?
    Thanks

    Code:
    template <typename T,typename K>
    int HashTable<T,K>::countRecords(HashTable<T,K> myHash){ //The number of records in the table: countRecords()
    	int num_recored=0;
    	T temp;
    	for(int i=0; i<myHash.table.size(); i++)
    		if(myHash.table[i].size()>1)
    			for(int j=0; j<myHash.table[i][j].size(); j++){
    				
    
    
    			}
    				
    
    				if(myHash.table[i][j]!=myHash.table[i][j+1]){ //check for error
    					num_record++;
    				}
    			
    		num_record++;
    	return num_record;
    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    How are you storing the data inside the has table?
    Usually the data will be stored in single or douly-linked list.
    What i mean is its an arry of single or doubly linked list.
    So to find the number of elements go to each array and from there traverse till you reach end of the list.
    And Usually number of records will be mainttained in the hash

    Raghuram

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Have you considered using accumulates() rather than write a loop?

      Comment

      Working...