hashing + SQLite +recursion + problems with memory

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
jach
In need of some credit
In need of some credit
Posts: 5
Joined: Sun Jan 16, 2005 2:43 pm

hashing + SQLite +recursion + problems with memory

Post by jach » Sun Jan 16, 2005 3:03 pm

Hello

I try with wxHashTable.

I have hash with wxString keys (animal number). Their values are bjects of RODZICE class which contein two wxString's 'ojciec'(sire) and 'matka'(dam)

I need get each animal and search their all pedigree.

Program (aplication) seems to work. and i know that algorithm do what I want.
But program hang on after 100 keys or 5000 keys (animals) i dont know what it depend.
(hash h_count contain 11 thousand keys)

if someone got some time. pleas look in code.

jach



here we have declaration of hash classes

WX_DECLARE_HASH_MAP(wxString, RODZICE, wxStringHash, wxStringEqual, BOB );
WX_DECLARE_HASH_MAP(wxString, int, wxStringHash, wxStringEqual, COUNT );

bellow RODZICE class

class RODZICE{
public:
wxString ojciec;
wxString matka;
RODZICE();
~RODZICE();
};


here RODOWOD class

class RODOWOD{
private:
int kolejnosc(wxTextCtrl *text);
int szukaj(OSOBNIK *os,wxTextCtrl *text);
public:
BOB rodowodzik;
COUNT h_count;
int Licz(wxTextCtrl *text);
RODOWOD();
~RODOWOD();
void Read_Rod();
};


subroutine Read_Rod() which got values from sqlite and fill RODOWOD structure.

void RODOWOD::Read_Rod(){
sqlite3 *pdb;
int ret;
const char *db_name = "mateselection.db";
const char *sql_query = "select * from rodowod";
char **result;
int nRow;
int nCol;
int row;
char *errmsg=0;
ret = sqlite3_open(db_name, &pdb);
ret = sqlite3_get_table(pdb, sql_query, &result, &nRow, &nCol, &errmsg );

for (row=1;row<nRow+1;row++){

RODZICE tmp;
tmp.ojciec = result[row*nCol+2];
tmp.matka = result[row*nCol+3];
wxString osobnik = result[row*nCol+1];
rodowodzik[osobnik] = tmp;
if(tmp.matka.Cmp("0") != 0){h_count[tmp.matka]=0;}
if(tmp.ojciec.Cmp("0") != 0){h_count[tmp.ojciec]=0;}
h_count[osobnik]=0;

}

ret = sqlite3_close(pdb);
sqlite3_free_table(result);
sqlite3_free(errmsg);
}

bellow we have three subroutine. Licz() which call kolejnosc(). kolejnosc() foreach keys from h_count and call szukaj() with key as szukaj argument. szukaj fainds sire and dam for animal. if sire or dam is != 0 call recursively szukaj().
kontrola is checking deep of recursion. if diper than 50 'generation' we has error in pedigree.


int RODOWOD::Licz(wxTextCtrl *text){
int c = kolejnosc(text);
return c;
}


int RODOWOD::kolejnosc(wxTextCtrl *text){
COUNT::iterator it;
int kontrola = 0;

for( it = h_count.begin(); it != h_count.end() && !kontrola; ++it )
{

OSOBNIK tmp;
tmp.numer = it->first;
tmp.licznik =0;
kontrola = szukaj(&tmp, text);

}

return kontrola;
}

int RODOWOD::szukaj(OSOBNIK *os,wxTextCtrl *text){
int kontrola =0;
int kontr_m=0;
int kontr_o=0;


if(os->licznik > h_count[os->numer]){h_count[os->numer]=os->licznik;}

wxString ojciec = rodowodzik[os->numer].ojciec;
wxString matka = rodowodzik[os->numer].matka;
if(os->licznik>50){kontrola=1;return kontrola;}

if(ojciec.Cmp("0") != 0){
OSOBNIK tmp_ojciec;
tmp_ojciec.licznik =os->licznik+1;
tmp_ojciec.numer=ojciec;
kontr_o=szukaj(&tmp_ojciec,text);
}

if(matka.Cmp("0") != 0){
OSOBNIK tmp_matka;
tmp_matka.licznik=os->licznik+1;
tmp_matka.numer=matka;
kontr_m=szukaj(&tmp_matka,text);
}




if (!kontr_m && !kontr_o){kontrola=0;}else{kontrola=1;}

return kontrola;
}

jach
In need of some credit
In need of some credit
Posts: 5
Joined: Sun Jan 16, 2005 2:43 pm

Post by jach » Sun Jan 16, 2005 3:11 pm

of coure loop in Read_Rod() looks

'for (row=1;row<nRow+1;row++){'

not ' for (row=1;row'

(i dont know why it was cut)

jach

Post Reply