Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. in a "mess" table

in a "mess" table

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasedata-structurescryptographytutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sirrius
    wrote on last edited by
    #1

    I have this code here out of a text book that is for a hash table. I understand the concept of a hash table but this code, for me, is somewhat difficult to understand. I am having problems figuring out how to implement the template class in the main.cpp file. I know some of the other code is not complete, but I would at least like to know how to implement the insert function from main. And what exactly does std::size_t do? P.S. I'm about ready to start from scratch and code my own. Can somebody give me a jump start at this. Thanks.

    #include
    #include
    #include

    #include "table1.h"

    using namespace std;

    void main()
    {
    table t;
    t.hash(100);
    }

    TABLE1_H

    #ifndef TABLE1_H
    #define TABLE1_1
    #include
    #include

    const size_t CAPACITY = 811;
    int NEVER_USED = -1;
    int PREVIOUSLY_USED = -2;

    struct tractor
    {
    int key;

    };

    template
    class table
    {
    //MEMBER CONSTANTS
    private:

    //MEMBER VARIABLES
    recordType  data\[CAPACITY\];
    size\_t used;
    
    //HELPER FUNCTIONS
    template
    size\_t hash(int key) const
    {
    	return (key % CAPACITY);
    }
    size\_t next\_index(size\_t index) const
    {
    	if((index+1)==CAPACITY)
    		return ((index + 1) % CAPACITY);
    
    }
    void find\_index(int key, bool &found, size\_t &index) const
    {
    	size\_t count; //number of entries that have been examined
    	count = 0;
    
    	i=hash(key);
    	while((count
     void insert(const recordType &entry)
    {
    	bool already\_present;
    	size\_t index;
    
    	assert(entry.key >= 0);
    
    	//SET INDEX SO THAT DATA\[INDEX\] IS THE SPOT TO PLACE THE NEW ENTRY
    	find\_index(entry.key, already\_present, index);
    
    	//IF THE KEY WASN'T ALREADY THERE, THEN FIND THE LOCATION FOR THE NEW ENTRY.
    	if(!already\_present)
    	{
    		assert(size() < CAPACITY);
    		index = hash(entry.key);
    		while(!is\_vacant(index))
    			index = next\_index(index);
    		++used;
    	}
    	data\[index\] = entry;
    }
    
    template
    void remove(int key)
    {
    	bool found;
    	st
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups