Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
20
Добавлен:
15.06.2014
Размер:
652.77 Кб
Скачать

4.6 2D-Arrays manipulation module

 

 

 

67

re ondition:

 

 

 

 

 

 

ust be a valid gdsl_2darray_t & OUTPUT_FILE != NULL

 

Parameters:

 

 

 

 

 

 

 

A The 2D-array to write

 

 

 

 

WRITE

 

F The write fun tion

 

 

 

 

OUTPUT FILE The le where to write A's elements

 

USER

DATA User's datas passed to WRITE

F

 

 

See also:

 

write()(p. 66)

 

 

 

 

gdsl_2darray_dump()(p. 67)

 

 

 

 

4.6.2.12

 

gdsl_2darray_dump ( onst gdsl_2darray_t A, onst

void_write_fun _t WRITE_F, FILE

 

OUTPUT_FILE,

gdsl

 

 

 

 

DumpComplexitAountheargumenA'sFinternalstruoy:writtureO(ouldUSERstruRtoA'sxbetureOUTPUTCelemenpassed),DATAofwhereats2Dtoto)FILEWRITEarrayOUTPUTisA's.IftorowsWRITEaF.leFILE.ount,F.Additionnaland!=NULL,CisA'sthenUSERolumnsuses-

Note:WRITEA

 

 

 

 

 

 

 

re ondition:

 

 

 

 

 

 

ust be a valid gdsl_2darray_t & OUTPUT_FILE != NULL

 

Parameters:

 

 

 

 

 

 

 

A The 2D-array to dump

 

 

 

 

WRITE

 

F The write fun tion

 

 

 

 

OUTPUT FILE The le where to write A's elements

 

USER

DATA User's datas passed to WRITE

F

 

 

See also:

 

 

()(p.

 

 

 

 

gdsl_2darray_write

 

 

 

 

xml(66)(p. 66)

 

 

 

 

Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

 

 

 

68

gdsl Module Do umentation

4.7 Binary sear h tree manipulation module

 

T

 

 

Funypedefsˆˆ gdslttionsGDSLbstreegdslbinarybstreetseargdslh gdsltreebstreetypbstree. allot

( onst har

alloompvoidCrDestrFlushgdslaharfunteoyabinarybstreefunnewbinaryt binaryALLseartsearbstreeCOMPfreehushsearh (gdsl(F,.hgdsl.F)gdsl.bstreebstreefree( onstfunT)T) _t FREENAME,F gdsl_-

ˆ T)gdslboolonstCheGetgdslelementhekifrootnamebstreegdslbinaryofofa abinarysegdslbinaryis hemptyseartrbstreesegetarishhempty(settrnameonst.get. . gdslrootbstreegdsl( onst__bstreegdslT) __bstreetT) _t

 

ulong gdslsize of a

size ( onst gdsl_bstree

T)

T)

ˆ

getsearheighh .( onst gdsl_bstree

 

gdsl bstreebstreegdsl

bstree

name (gdsl_bstree_t T, onst

 

Get the height of binarybinary sear h tr e.

 

 

 

 

ˆ

elementhe nameelementNAME)of a binarygdsl_bstreesear h tr_insert.

(gdsl_bstree_t T, void

 

gdslharSetNEW

 

 

 

 

 

ˆ

 

remoh tr veif it's(gdslnot_foundbstreeor_returnT, itvoid.

 

gdslVALUE,Insertelemenanin RESULT)Generatedgdslinto bina y sear

 

 

 

 

 

VALUE)

on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

 

 

 

 

 

 

 

4.7 Binary sear h tree

manipulationfrom binary searmoduleh tr .

69

 

Remove an

 

ˆ

gdsl bstree_elementgdsl

bstree

delete

(gdsl_bstree_t T, void

 

gdslVALUE)Deleteelemenompareanelementfungdslfrom

elementabstreeCOMPinary sesearF, hvoidtreeh . ( onst gdsl_bstree_t T,

ˆ

 

 

 

 

 

 

ˆgdslgdslT, Seareleh forap arfunigdslulart_MAPbstreeF,intomapvoidbinarypreVALUE)searx (h onsttree. gdsl_bstree_t

ˆgdslgdslT, Parseelemenbinaryapt__funseart gdslh ttreMAPin prF,xevmaporderUSERin. x_(DATA)onst gdsl_bstree_t

ˆgdslt T,Parsegdsl_bin try__seartfungdslwriteh trbstreeMAPin in xedF,mapvoidorderUSERpost. xDATA)( onst gdsl_bstree_-

ˆvoidfunParseritegdslWRITEa binbstreeary searF, FILEh tr in( onstpt xegdslorderbstreeUSER. _bstreeDATA)T, gdsl_write_-

ˆvoidwriteW gdslfunthe_bselementontentreeWRITEof a hF,nodeOUTPUTxmlFILEof a( bionstaryFILE,gdslsearvoidh USERto a tle.DATA)T, gdsl

ˆDATA)voidfunWritegdslWRITEthebstreeF,ofdumpFILEa binary( onstsear hgdsltreeOUTPUTtobstreea le intoFILE,XMLT, voidgdsl. writeUSER__--

4..77..11.1 DumpTtypedefthe internalstruDot struumentationgdslturebstreeOUTPUTof a binary_FILE,sear h voide USERa le. _DATA)

GDSLThisDebutGeneratednitionbyypebinarytheonisatfunvoluntaryThulineseartionsJun53h oftree22opaquethis11:15:30leypegdslmodule. Variables2006bstree.for.hgdsl.ofgdslthisby Doxygenkindbstreeould'ntt be dire tly used,

70

 

 

 

 

 

 

 

 

 

 

 

 

 

 

gdsl Module Do umentation

.7.2 Fun tion Do umentation

 

 

 

 

 

 

 

 

tion,seartogdslsearfunNULLallpthogdslintetreeh, omparetreefreeto.sALLOCusebstreeALLOCdataandthestrufunomparesdefaultalloFF,t, FREEgdslt (COMPones:elwhionstmentsfreehF nameandharFinfun)COMPtheisNAMEsettreet to.FaThese,ouldopy

 

 

 

 

funallobstreesettivelyaryF

 

 

 

 

 

 

 

 

 

 

 

be

 

 

 

 

 

 

 

 

 

 

 

 

4.7NAMEused.2ate.1atoanew.FREEgdsluldnewTherespbinary

 

 

 

 

 

 

 

 

pointersbeofAlloCreate

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ALLOC

 

F simply returns its argument

ˆ the default

FREE

 

F does nothing

 

 

 

COMP_F always returns 0

Note:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Complexity: O( 1 )

 

 

 

 

 

 

 

 

re ondition:

 

 

 

 

 

 

 

 

 

 

 

 

 

nothing

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Parameters:

 

 

 

 

 

 

 

f the new

 

ree to reate

NAME The name

 

 

FREE F F

 

 

 

 

to free elembinarye when removing it from a binary tree

COMP_F Fun tion to ompare el ments into the binary tree

ALLOC

 

F F

 

 

 

n to allo m

t when inserting it in a

the newly

 

llo ated binary sear h tree in ase of su ess.

Returns:

 

 

ase of insu ient memory.

 

 

 

NULL in

 

 

 

See also:

 

 

 

 

 

 

free()

 

 

 

 

 

 

 

bstree ush()(p70).

 

 

 

 

 

free

 

fun

t(p. 191)

 

 

 

 

 

allo

 

 

 

 

t(p.

1)

 

 

 

gdsl_ ompare fun _t(p. 192)

 

 

 

4.7.2.2

void gdsl_

 

 

 

 

_free (gdsl_bstree_t T)

stroy

binary sear bstreeh .

 

 

 

 

 

Deallo ate

 

the lements

f the binary sear h tree T by alling T's FREE F

and T is deallo ated itselfbstreeoo.

_allo ()(p. 70). The name of T is deallo ated

fun tion passed to gdsl

 

 

 

 

 

 

 

 

 

 

 

 

Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

 

 

4.7 Binary sear h tree manipulation module

 

71

 

Note:

 

 

 

 

 

 

 

 

 

 

 

 

 

bstreebinarybey:validO(searalloTgdslh)()tree(pbstree.7to0)deallo ate

 

 

 

 

TComplexitalso:ondition:Theust

 

 

 

 

 

 

 

 

gdsl

 

 

 

 

 

 

 

 

Parameters:re

 

 

| |

 

 

 

 

See

 

 

 

 

 

 

 

 

 

4.7.2.3

 

 

 

 

ush

 

1

 

 

 

void gdsl

 

_ ush (gdsl_bstree_t T)

 

Flush

bin ry s ar h bstree.

 

 

by lling T's FREE_F

 

Deallo ate

the elements of the b nary sear h tree

 

not deallo ated itself and its name is not modi ed.

The binary sear h tree T is

 

fun tion pass

 

to gdsl

rbtree allo ()(p. 165).

Note:

 

bstreebinarybevalidO(searalloTgdslh)()tree(pbstree.70)to usht

 

 

 

 

TComplexity:also:ondition:Theust

 

 

 

 

 

 

 

gdsl

 

 

 

 

 

 

 

 

Parameters:re

 

 

| |

 

 

 

 

See

 

 

 

 

 

 

 

 

 

free()(p. 70)

ostre7.2TheComplexittheondition:.ondi4 nameustTonst)beofy::a avalidO(harstringbinary1)gdsldslsearbstreebstreeh t._get_name ( onst gdsl_bstree_t

PNote:Get4.

 

 

Generated

ur ed

MUST NOT be freed.

Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

72

 

 

 

 

 

 

 

gdsl Module Do umentation

 

Parameters:

 

 

 

 

 

 

 

 

T The binary sear h tree to get the name from

Returns:

 

 

 

 

 

 

 

 

 

the name of the binary sear h tree T.

 

 

See also:

 

 

 

 

 

 

 

 

 

gdsl_bstree_set_name(p. 73) ()

 

 

 

4.7.2.5 bool gdsl_

 

is empty ( onst gdsl_bstree_t T)

 

Che k if a binary sear bstreeh

is empty.

 

 

Note:

 

 

 

 

 

 

 

 

 

 

Complexity: O( 1 )

 

 

 

 

 

 

re ondition:

valid gdsl_bstree_t

 

 

Parameters:ust be

 

 

 

 

T

The binary sear h tree to he k

 

 

Returns:

 

 

 

h

T is empty.

 

 

TRUE if

 

 

 

 

FALSE ifthebinarysear htree

T is not empty.

4.7.2.6

 

element

t gdsl_bstree_get_root ( onst

 

 

 

 

gdsl_bstree

t T)

 

 

 

 

Get the root of a binary sear h tree.

 

 

 

Note:

 

 

 

 

 

 

 

 

 

 

Complexity: O( 1 )

 

 

 

 

 

 

re ondition:

valid gdsl_bstree_t

 

 

Parameters:ust be

 

 

 

 

T

The binary sear h tree to get the root element from

Returns:

 

 

 

 

 

 

 

 

 

the element at the root of the binary sear h tree T.

 

 

 

 

 

Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

 

Binary sear h tree manipulation module

73

4.7.2.7 ulong gdsl_bst ee_get_size ( onst gdsl_bstree_t T)

 

Get the size of a binary sear h tree.

 

 

Note:

 

 

 

re ondition:y: O( 1 )

 

 

Complexitust be

valid gdsl_bstree_t

 

 

T The binary sear h tree to get the size from

 

Parameters:

 

 

 

Returns:

heighssearar ht()hgettreetree(p..T73)height(noted( Tonst). gdsl_bstree_t

 

SeeGet4.7.2Complexitthegdslthealso:.8heighsizeulongbstreeof ofthegdslabinarybinarygetbstree

| |

T)

Note:

 

 

 

Parameters:re theTondition:Theheighustbstreebinarybey:ofvalidO(thesearTbinarygdslh) treebstreeseartohomputetree T the(notedheighth(T))from.

 

Returns:

| |

 

 

See also:

_get_size()(p. 73)

 

 

gdsl_

 

 

4.7.2.9 gdsl_bstree_t gdsl_bstree_set_name (gdsl_bstree_t T,

SetChangeNAMEGeneratedthe.nametheononstpreviousThof aJunharbinary22name11:15:30NEWsearof hthe2006treeNAMEbinary.for gdsl)searby Doxygenh tree T to a opy of NEW_-

74

 

gdsl Module Do umentation

 

Note:

 

 

re ondition:y: O( 1 )

 

 

 

Complexitust be valid gdsl_bstree_t

 

 

 

T The binary sear tr to hange the name

Parameters:

 

 

 

NEW NAME The new name of T

 

Returns:

 

 

 

the modi ed binary sear h tree in ase of su ess.

 

 

NULL in ase of insu ient memory.

 

See also:

 

 

 

gdsl_bstree_get_name()(p. 71)

_insert (gdsl_bstree_t T,

 

4.7.2.10 gdsl_element_t gdsl_

Note:thenInsertusingSearbyfouusingd,rehT'santforurnedhenT'selemenALLOCthevoidit's. returnedMPstintoVALUEFelemenfunFafunbinary.tionIf,tionEEintpassedequisn'tsearlssedRESULThtofound,bstreetoVALUEtogdslgdslifthenit's)bstreeinatootnefoundthewalloelemenallobinaryorandtoreturnissearEndinsertedisithallo..treeIfatedEanT,is

Parameters:reRESVALTComplexitondition:TheustULTEbinarybeThey:ThevalidO(searvalueaddressh(T)gdslhutree),edwherebstreewheretomaklog2(theodifyt&theresult|RESULTT|new)<=odeelh(T)ment!=wisllNULL<beto=stored|insertT|-1 .into T

Returns:the elementRESULand RESULT = GDSL_OKERRif_EDUPLICATEinserted intoENTRinsu. Y ienf E isNULLalreadyandpresent inT =T.GDSL_ERR MEM_ALLOC ase of t memory.

See gdslalso:_bstree_remove()delete()(p(p. 75). 75)

Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

4.7 Binary sear h tree manipulation module 75

.2.11 gdsl_element gdsl bstree_remove (gdsl_bstree_t T, Note:alloRemoveto VALUE,Complexity:()(panfrom.70)voidelementby.theIfO(usingEVALUEbinaryisfromh(T)found,T'sa),searbinary)whereCOMPitish removedseartreelog2(FhTfuntreethefromtion.Trstpassedandfoundedthentoreturnedelementgdsl .bstrE equale -

re VALUETfTheondition:undedTheustresultingbinarybeEThe.validsearvalueTelemenisgdslhmodiusedtreebstreetoedmodifyndbyt theexaminatingTelement) = h(T)totheremoveleft=Tsub-1-tree from the

Parameters:

| | <

<

| |

Returns:

 

t

in T ase is found.

the rst founded

NULL in ase no

t equal to VALUE is fouind in T.

See also:

ins rt() . 4)

 

 

gdsl_bstree_dele

(p.75)

 

 

4.7.2.12

gdsl_bstree_

gdsl_bstree_delete (gdsl_bstree_t T,

efound,moveleteusingComplexity:antofromitT'sgdslelementisvoidCOMPtheremovedbstreebinaryO(fromVALUEh(T)Ffromsearfunte()allobinary),Twheretionhtree()d(psearpassedealloEthe.log2(70),ish rsttreethenfoundedgdsl. atedTis breturnedelemstreing T's.alloEFREEequal()(ptoF.70)VfunALUE,.tionIf

Note:passisbyRD

 

 

 

 

Parameters:re thefTondition:undedTheustresultingbinarybeE.validTsearisgdslhmoditreebstreeedto removebyt examinating|Tan|) element<= h(T)thefrom<left=|Tsub|-1-tree from the

Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

76

 

gdsl

Do umentation

 

VALUE The value used to nd the element toModuleremov

 

Returns:

 

 

 

the modi ed binary sear h tree after removal of E if E was found.

 

NULL if no elemen equal to VALUE was found.

 

See also:

insert() p. 74)

 

 

gdsl_bstree_remove()(p. 75)

 

4.7.2.13

gdsl_element_t gdsl_bs ree_sear h ( nst gdsl_bstree_t

Note:COMPfunSeartionComplexity:h theforFpassedaTfunrstparti, gdsltielemenoO(ulargdsltoh(T)tompareelementEndbstreeequal),itwhere.intotoIffunalloCOMPVALUElog2(abinaryt()COMP(pinF.70)searthe==isbinaryhNULL,usedFtree, v..oseaidthentreeVALUEtheT,COMPby) usingF

Tondition:TheustCOMPVALUEbinarybeF ThvalidF)toseargdslomparisonndh treethebstreetoelemenusefunt. tionET to)( ruse=NULLh(T)to ompareto=useT -T's1theelemendefaultwithT's

Parameters:re COMP

| | <

<

| |

VALUE The value that

ust be used by COMP_F to nd the elemen E

Returns:

 

 

 

 

the rst founded element E equal to VALUE.

 

 

NULL if VALUE is not found in T.

 

 

See also:

ins rt()

. 74)

 

 

gdsl_bstree_delete()(p. 75)

 

 

4.7.2.14

remove()(p. 75)

 

 

element_t gdsl_bstree_map_pre x ( onst

 

gdslsearbstreehDATAtreeGeneratedint)Tpre, gdslonxedThuordermapJun.22fun11:15:30t MAP2006 for_gdslF, voidby Doxygen

Parse a binaryUSER