Click here to Skip to main content
15,911,132 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Question about FindWindow. Pin
Anthony_Yio10-Oct-03 22:25
Anthony_Yio10-Oct-03 22:25 
GeneralRe: Question about FindWindow. Pin
George211-Oct-03 19:43
George211-Oct-03 19:43 
General.NET and assembly Pin
Sirrius10-Oct-03 17:31
Sirrius10-Oct-03 17:31 
GeneralRe: .NET and assembly Pin
ZoogieZork10-Oct-03 18:20
ZoogieZork10-Oct-03 18:20 
GeneralRe: .NET and assembly Pin
Blake Coverett10-Oct-03 21:02
Blake Coverett10-Oct-03 21:02 
GeneralRe: .NET and assembly Pin
Beer2611-Oct-03 7:08
Beer2611-Oct-03 7:08 
GeneralRe: .NET and assembly Pin
Blake Coverett11-Oct-03 10:06
Blake Coverett11-Oct-03 10:06 
Generalhash trouble Pin
Sirrius10-Oct-03 17:27
Sirrius10-Oct-03 17:27 
Here is the whole code: I should of put it out here to begin with on my previous forum. I tends to generate an error c2783 on the find_index() call in the insert funtion. Is it the way I am sending the struct in the main to the insert fucntion? I don't know. Very frustrated with this.
I put void main() on the bottom of this page.
Thanks for the help.


#ifndef TABLE1_H
#define TABLE1_1
#include <cstdlib>
#include <cassert>


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


struct tractor
{
int key;
};




template<class recordType>
class table
{
//MEMBER CONSTANTS
private:



//MEMBER VARIABLES
recordType data[CAPACITY];
size_t used;

//HELPER FUNCTIONS

template<class recordType>
size_t hash(const recordType key) const
{
return (key % CAPACITY);
}

size_t next_index(size_t index) const
{
if((index+1)==CAPACITY)
return ((index + 1) % CAPACITY);

}

template<class recordType>
void find_index(int key, bool &found, std::size_t &index) const
{
size_t count; //number of entries that have been examined
count = 0;

i=hash(key);

while((count<CAPACITY) && (!never_used(i)) && (data[i].key != key))
{
++count;
i = next_index(i);
}
found = (data[i].key == key);


}

bool never_used(size_t index) const;
bool is_vacant(size_t index) const;

public:


//CONSTRUCTOR


table()
{
size_t i;
used = 0;
for(i=0; i<CAPACITY; ++i)
data[i].key = NEVER_USED;

}


//MODIFICATION MEMBER FUNCTIONS

void insert(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);
while(!is_vacant(index))
index = next_index(index);
++used;
}
data[index] = entry;
}

/*template<class recordType>*/
void remove(int key)
{
bool found;
std::size_t index; //SPOT WHERE DATA[INDEX].KEY==KEY

assert(key >= 0);

find_index(key,found,index);
if(found)
{
//THE KEY WAS FOUND SO REMOVE THIS RECORD AND REDUCE USED BY 1
data[index].key = PREVIOUSLY_USED; //INDICATES A SPOT THATS NO LONGER IN USE
--used;
}

}


//CONSTANT MEMBER FUNCTIONS
/*template<class recordType>*/
bool is_present(int key) const
{
bool found;
std::size_t index;
assert(key>=0);
find_index(key,found,index);
return found;

}

/* template<recordType>*/
void find(int key, bool &found, recordType &result) const
{
std::size_t index;
assert(key>=0);
find_index(key,found,index);
if(found)
result = data[index];
}

size_t size() const
{
return used;
}

};


#endif



void main()
{
table<tractor> tr;
tractor t;
t.key=28;
tr.insert(t);


}
GeneralRe: hash trouble Pin
ZoogieZork10-Oct-03 18:11
ZoogieZork10-Oct-03 18:11 
Questionhow to resize and reposition all the controls in a dialog Pin
pampatipraveen10-Oct-03 16:29
pampatipraveen10-Oct-03 16:29 
AnswerRe: how to resize and reposition all the controls in a dialog Pin
Ravi Bhavnani10-Oct-03 16:46
professionalRavi Bhavnani10-Oct-03 16:46 
Generalpassing parameters Pin
Sirrius10-Oct-03 14:00
Sirrius10-Oct-03 14:00 
GeneralRe: passing parameters Pin
Michael Dunn10-Oct-03 14:47
sitebuilderMichael Dunn10-Oct-03 14:47 
GeneralRe: passing parameters Pin
Sirrius10-Oct-03 15:04
Sirrius10-Oct-03 15:04 
GeneralRe: passing parameters Pin
Phil Hamer10-Oct-03 15:34
Phil Hamer10-Oct-03 15:34 
GeneralRe: passing parameters Pin
Sirrius10-Oct-03 15:52
Sirrius10-Oct-03 15:52 
GeneralMFC Application with DTML GUI Pin
blueinred10-Oct-03 13:11
blueinred10-Oct-03 13:11 
GeneralRe: MFC Application with DTML GUI Pin
Scozturk10-Oct-03 22:16
professionalScozturk10-Oct-03 22:16 
GeneralTab Ctrl!! Pin
kannada10-Oct-03 13:02
kannada10-Oct-03 13:02 
QuestionHow to create sounds Pin
Deepak Samuel10-Oct-03 13:02
Deepak Samuel10-Oct-03 13:02 
AnswerRe: How to create sounds Pin
John M. Drescher10-Oct-03 13:38
John M. Drescher10-Oct-03 13:38 
GeneralRe: How to create sounds Pin
Scozturk10-Oct-03 22:12
professionalScozturk10-Oct-03 22:12 
Generallinked list problem Pin
K. Shaffer10-Oct-03 12:09
K. Shaffer10-Oct-03 12:09 
GeneralRe: linked list problem Pin
Phil Hamer10-Oct-03 12:24
Phil Hamer10-Oct-03 12:24 
GeneralRe: linked list problem Pin
John M. Drescher10-Oct-03 13:19
John M. Drescher10-Oct-03 13:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.