|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Dec 2008
Città: italia
Messaggi: 80
|
[java] metodo da c a java
devo tradurre un metodo da c in java però ho delle difficoltà nella traduzione soprattutto nella parte dove vien calcolato maxref ,dove vi sono i puntatori,ed array qualcuno può aiutarmi in questo? sotto ho postato il codice in C:
Codice:
void FixReferenceSets(ObjDesc *od) { int i,j,maxref=0; ((void) 0); if (od->flag++) return; for (i=0;i<od->kids;i++) { ElmDesc *ed=&(od->elm[i]); ObjDesc *son=&objs[ed->id]; if (!son) continue; if (ed->pd.min>1 && !hasID(son)) { int size; double local_factor=1; for (j=0;j<5;j++) { if (son->att[j].name[0]=='\0') break; maxref=(((maxref)<(objs[son->att[j].ref].set.size)?(objs[son->att[j].ref].set.size):(maxref))); } if (!maxref) break; local_factor=maxref/ed->pd.max; size=(int)(GenRandomNum(&ed->pd)+0.5); size=(int)(((1)<(size*local_factor)?(size*local_factor):(1))); son->set.size+=size; FixDist(&ed->pd,size); } FixReferenceSets(son); } } |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Occorre fare un bel po' di supposizioni sulle parti mancanti, la loro implementazione, ecc.
Con una serie di ipotesi aggiuntive ragionevoli, una prima versione potrebbe essere: Codice:
public void FixReferenceSets(ObjDesc od) { int i,j,maxref=0; if (od.flag++) return; for (i=0;i<od.kids;i++) { ElmDesc ed=od.elm[i]; ObjDesc son=objs[ed.id]; if (!son) continue; if (ed.pd.min>1 !hasID(son)) { int size; double local_factor=1; for (j=0;j<5;j++) { if (son.att[j].name.size() == 0) break; maxref=(((maxref)<(objs[son.att[j].ref].set.size)?(objs[son.att[j].ref].set.size):(maxref))); } if (!maxref) break; local_factor=maxref/ed.pd.max; size=(int)(GenRandomNum(ed.pd)+0.5); size=(int)(((1)<(size*local_factor)?(size*local_factor):(1))); son.set.size+=size; FixDist(ed.pd,size); } FixReferenceSets(son); } } Potresti partire da questa versione ed adattare a seconda degli errori di compilazione
__________________
In God we trust; all others bring data |
![]() |
![]() |
![]() |
#3 |
Member
Iscritto dal: Dec 2008
Città: italia
Messaggi: 80
|
[java] metodo da c a java
vi ringrazio in anticipo per l'aiuto, ti descrivo brevemente il codice:
ElemenDesc, Objdesc sono delle classi con le relative proprietà,come anche ProbDesc pd, HashID(),GenRandomNum(),FixDist() sono metodi che vengono passati nel seguente metodo.Io ho implementato il tutto nel seguente modo, però non sono sicuro che sia corretto: Codice:
public void FixReferenceSets(ObjDesc od) { int i=0,j=0,maxref=0; if (od.flag==od.flag+1) return; for (i=0;i<od.kids;i++) { ElemDesc ed=od.listaElemDesc.get(i); ObjDesc son=listaObjDesc.get(ed.getId()); ProbDesc pd=new ProbDesc(); if (son!=null) continue; if ((ed.getPd().getMax()>1)&& !(hasID(son))) { int size=0; double local_factor=1; for (j=0;j<5;j++) { if (son.att.getName()==0) break; maxref=(((maxref)<set.getSize(objs[son.att.getRef()])?set.getSize(objs[son.att.getRef()]):(maxref))); } if (maxref==0) break; local_factor=maxref/ed.getPd().getMax(); size=(int)(GenRandomNum(ed.getPd())+0.5); size=(int)(((1)<(size*local_factor)?(size*local_factor):(1))); son.set.getSize()+=size; FixDist(ed.getPd(),size); } FixReferenceSets(son); } } |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Nov 2005
Città: Texas
Messaggi: 1722
|
Potrebbe esserlo, ovviamente dipende dal resto del codice.
Ho visto pero' che hai creato un oggetto, i.e. Codice:
ProbDesc pd=new ProbDesc(); ![]()
__________________
In God we trust; all others bring data |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:24.