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

4.9 Heap manipulation module

 

 

97

 

ˆ the default COMP_F always returns 0

 

Note:

 

 

 

 

 

 

 

 

 

Complexity: O( 1 )

 

 

 

 

re ondition:

 

 

 

 

 

 

 

nothing

 

 

 

 

 

 

 

Parameters:

 

 

f the new

to reate

 

 

NAME The name

 

 

COMP_F Fun tion to ompare elements into the heap

 

 

ALLOC

F F

n to allo

 

t when inserting it in

 

 

FREE

 

F F

to free elemheapt when removing it from the heap

 

Returns:

 

 

 

llo ated heap ase of su ess.

 

 

the newly

 

 

 

NULL in ase of insu ient memory.

 

 

See also:

 

 

 

free()(p. 97)

 

 

 

 

gdsl_heap_ ush()(p. 98)

 

 

 

4.9.2.2 void gdsl_heap_free (gdsl_heap_t H)

 

 

stroy heap.

 

 

 

 

 

deallo ated

itself too.

 

 

 

 

De

 

all the elements of the heap H by alling H's FREE F fun tion

pass to gdsl

 

heap

allo ()(p. 96). The name of H is deallo ated and H is

Note:

 

 

 

 

 

 

 

 

 

HComplexity:also:ondition:Theust heapbe O(validtodestroyHgdsl) _heap_t

 

 

 

SeePPrearameters:

 

| |

 

 

 

 

gdsl_heap_alloush()(p.96)8

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

98

 

 

 

gdsl Module Do umentation

 

4.9.2.3

void gdsl_heap_ ush (gdsl_heap_t H)

 

 

Flu h

 

h ap.

 

allo ()(p. 96). H is not deallo ated itself and H's name

 

pass d to gdsl_heap

 

Deallois not

atdi ed.

 

 

 

Note:

 

all the elements of the heap H by alling H's FREE F fun tion

 

 

 

 

 

 

Complexitalso:ondition:Theust heapbey:a validO(to Hushgdsl) _heap_t

SeePPrearameters:HH

|

|

 

gdsl_heap_allofree()()(p(p. .97)96)

Note:Pre4.Getarameters:ost9.2Complexity:theHondition:.ondi4 nameustonstbeof:aavalidO(harheap1)gdsl.gdsl heapheapt_get_name ( onst gdsl_heap_t H)

The ur ed string MUST NOT be freed.

H The heap to get the name from

Returns:

 

the name of the heap H.

See also:

 

gdsl_heap_set_name()(p. 100)

 

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

4.9.2.5 ulong gdsl_heap_get_size ( onst gdsl_heap_t H)

Heap manipulation module

99

Get the size of a heap.

Note:Complexity: O( 1 )

Pre Hondition:ust heapbe valid gdsl_heap_t

arameters:The to get the size from

Returns:Note:4.9.2Get thetheComplexit.6 topumbergdsl)Hof y:aelementofheapO(elements1.)tofgdslH (notedheap|H|get). _top ( onst gdsl_heap_t

re ondition:

valid gdsl_heap_t

 

ust be

Parameters:

 

 

H

The heap to get the op from

Returns:

 

on

at the top position of the heap H if H is not empty.

the el

 

The rementur ed elementained is not removed from H.

NULL if the heap H is empty.

See also:

 

 

 

gdsl_heap_set_top()(p. 100)

4.9.2.7

 

bool gdsl heap_is_empty ( onst gdsl_heap_t H)

Che k if a heap is empty.

 

Note:

 

y: O( 1 )

heap t

ComplexitH ust be a valid gdsl

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

100

 

 

 

gdsl Module Do umentation

 

Parameters:

 

 

 

 

 

H The heap to he k

 

 

Returns:

H is empty.

 

 

 

TRUE if

 

 

 

FALSE iftheheap H is not empty.

 

 

4.9.2.8 gdsl_heap_t gdsl_heap_set_name (gdsl_heap_t H, onst

PNote:ChangeSetarameters:retheHComplexity:ondition:nametheustharpreviousheapbeofavalidO(NEWheap1name)gdsl.NAMEofheapthe heap)t H to a opy of NEW_NAME.

 

 

The

to hange the

e

 

 

 

NEW_NAME The new name of H

 

Returns:

 

 

 

 

 

the modi ed heap ase of su ess.

 

 

 

NULL in ase of insu i

t memory.

 

See gdslalso:_heap_get_name()(p. 98)

4.9.2.9 gdsl_element_t gdsl_heap_set_top (gdsl_heap_t H, void Note:TrySubstitutetoComplexitreplatheVALUEy:theopO(topelementlog) element(ofaofheapheapbyabylesseralesserone.one.

Parameters:reVALUEHondition:Theust heapbethevalidtovalsubstituteGeneratedgdslto|Hsubstitu|heap)the)onttThuopetoelemenJunthe 22top11:15:30 2006 for gdsl by Doxygen

4.9 Heap

module

101

The oldmanipulationtop elemen value n ase VALUE is lesser than all oth r H elements.

Returns:

 

 

NULL in ase of VALUE is greather or equal to all other H elements.

 

See also:

 

 

gdsl_heap_get_top()(p. 99)

 

4.9.2.10

gdsl_element_t gdsl_heap_insert (gdsl_heap_t H, void

Note:InsertAlloelemenheapComplexit.ateanEaelemenisnewthenVALUEy:elemenO(insertedtolog)a E(heapbyinto(PUSH)allingat theH's. goodALLOCpositionF funtotionensureon HVALUEisalways.Thea

Hondition:Theust heapbeThevalidtovaluemodifygdslusedHheap)to) maket the new element to insert into H

Parameters:reVALUE

 

 

|

|

Returns:

 

lement E

ase of su ess.

the

 

 

NULLinsertedase of insu ient memory.

See also:

 

allo

 

(p. 96)

gdsl_heap_get

size()(p. 99)

 

 

 

remov

 

 

 

4.9.2.11

 

 

del te()

 

 

 

gdsl_element_t gdsl_heap_remove_top (gdsl_heap_t

Remov

 

H)

 

 

 

a heap (POP).

he top element from the heap H. The element is removed from H and

is also returned.

 

 

 

 

Note:

 

 

 

 

 

 

GeneratedComplexity:on Thu JunO( log22 11:15:30( |H| ) )2006 for gdsl by Doxygen

102

 

 

 

 

 

 

gdsl Module Do umentation

re ondition:

 

 

 

 

 

Parameters:ust be

valid gdsl_heap_t

 

 

H The heap

modify

 

 

 

Returns:

 

 

 

 

 

 

 

the removed top elemen .

 

 

 

 

NULL if the heap is empty.

 

 

See also:

 

ins rt()(p. 101)

 

 

gdsl_heap_delete

top()(p. 102)

 

4.9.2.12

gdsl

h ap_t gdsl

heap_delete_top (gdsl_heap_t H)

Removthethe top

element from the heap H. The element is removed from H

D lete

top elem from a heap.

 

nd is also deallo ated using H's FREE_F fun tion passed to gdsl heap_-

allo ()(p. 96), then H is returned.

 

Note:

 

 

 

 

 

 

Parameters:retheHComplexitondition:Themodiustheapbeheapy:d validO(heaptomodifyloggdslafter(Hremovalheap)) t of top element.

Returns:

 

|

|

 

 

 

 

NULL if

is empty.

 

 

 

See also:

 

 

(p.

101)(p. 101)

 

 

gdsl_heap_remov

 

map forward ( onst

4.9.2.13

 

elemen _top(

he

ementthenParsegdslawithllelemenapheapgdslUSERUSER.tsmap()heapofinsert()DATADATAtheGeneratedstopsheaH)rgumen,Handgds. onThereturnslTh. MAPmapIf JunMAPits22funFlastfun11:15:30F returnsexaminatedtiont MAP2006isGDSLalledforFelementgdsl,onvoidMAPbyea.Doxygenh H'sSTOPel-

 

4.9 Heap manipulation module

103

 

Note:

 

 

 

HComplexitondition:Theust heapbeFDAy:TheO(validtoAmapHUser'sgdsl)fun heapdatastion._passedt&MAPtoMAPF!=_NULLF

 

Parameters:reUSERMAP

| |

 

Returns:

 

 

the rst elemen for whi h MAP_F returns GDSL_MAP_STOP.

NULL when the parsing is done.

( onst gdsl_heap_t H,

4.9.2.14

gdsl_heap_

 

voidgdsl_write_fun writeWRITE_F, FILE OUTPUT_FILE,

Note:tionWrite.Complexity:AdditionnalallthetheelemenmentstsO(USERUSERof theofaDATAheapDATAHtoargumento) OUTPUTle. t ouldFILE,bepassedusingtoWRITE__FFfun. -

PreParameters:H!=HWRITEOUTPUTondition:NULLTheustbeheapaFvalidtoFILEThewrite|Hgdslwrite| )The.heapfunle tionwheret&.OUTPUTtowrite_H'sFILEelements!=NULL. & WRITE_F

USER_DATA User's datas passed to WRITE_F.

 

See also:

write xml()(p. 103)

 

 

gdsl_heap_dump()(p. 104)

_xml ( onst gdsl_heap_t H,

4.9.2.15

gdsl_heap_

 

void_write_fun writeWRITE_F, FILE

 

OUTPUT_FILE,

 

gdsl

 

 

GeneratedWrite the onThutentJunofUSERa22heap11:15:30DATAto a2006le)intofor gdslXMLby.Doxygen

104

 

 

 

gdsl Module Do umentation

rite the elements of the heap H to

FILE, nto XML

nguage.

 

If WRITE

 

!=

NULL, then uses

WRITE F to write H's lements

OUTPUT

FILE. Additionnal USER_OUTPUTDA A argument ould be

passed to

WRITE F.

 

 

 

 

 

Note:

 

 

 

 

 

 

HComplexitondition:Theust heapbey:FvalidO(toFILEThewriteHgdslwrite)The.heapfunle tionwheret &. OUTPUTtowriteH'sFILEelements!=NULL.

 

 

Parameters:reOUTPUTWRITE

| |

 

 

 

USER_DATA User's datas passed to WRITE_F.

 

 

See also:

 

 

write()(p. 103)

 

 

 

gdsl_heap_dump()(p. 104)

 

 

 

4.9.2.16

 

gdsl_heap_dump ( onst gdsl_heap_t H,

 

 

voidgdsl_write_fun _t WRITE_F, FILE OUTPUT_FILE, Note:DumpUSERthenComplexity:usestheDAWRITEstruinternalAargumentureO(USERstruofFheoturewriteheapouldDATAof beHa 'sheaptopassed)elementsOUTPUTtotoaWRITEleto. OUTPUTFILE.FIf. WRITEFILE. FAdditionnal!=NULL,

Parameters:re OUTPUTWRITEHondition:Theust heapbeFvalidtoFILEThewrite|Hgdslwrite| )Theheapfunle tionwheret & OUTPUTtowriteH'sFILEelements!=NULL USER_DATA User's datas passed to WRITE_F

See gdslalso:_heap_write()(pxml(). 103)(p. 103)

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

.10 Doubly-linked list manipulation module

105

4.10 Doubly-linked list manipulation module

 

Typedefs

 

 

 

ur ortypelist. _t

 

ˆ typedef _gdsl_list gdsl

 

GDSLlistdoublyt gdsl-linkedlistlist ursorallogdsltype( listo. st_ ursorhar _t

 

Funˆ gdsltions

 

 

funvoidCrDestrFlushgdslateharoyALLOCalistalistnew..listfreeF,ush. gdsl(gdsl(gdsl__freelistlist___funttL)L)_t FREENAME,F) gdsl_allo _-

GetChegdslgdslthek ifnamesizealistgdsllistofofisaisaemptylistgetlistempty. ..sizeget (nameonst gdsl( onstlistgdsltt_L)list_t L)

ulongboolonst

 

 

 

head ( onst gdsl_list_t L)

 

 

head of a list.

 

element t gdsl_list_get_tail ( onst gdsl_list_t L)

Get the

 

of a list.

 

ˆ gdsl

list_tail

gdsl list_set_name (gdsl_list_t L, onst

ˆ gdslNEWSet elementheNAME)nameelementof a listgdsl. _list_insert_head (gdsl_list_t L,

GeneratedVALUE)Inserton ThuanJun 22 11:15:30at the head2006 offoragdsllist.by Doxygen

har void

106

gdsl Modu e Do umentation

ˆ gdsl_elemen _

gdsl_list_insert_tail (gdsl list t L, void

 

ˆ gdslVALUE)InsertRemoveemoveel anmentheelementartiheadailularofgdslofatgdslalithelist.listtail.listofremovearemovelist. headtail(gdsl(gdsl(gdsllistlistlistt t L,tL)L) gdsl_-

ˆ gdslomparDeleteR listtheafuntptailheadgdslgdslofof__COMPlistelement.. deletedeleteF,fromonst(tailheadgdsllistvoid(.gdsl(gdsllistVALUE)listlistL,t gdsltL)L)_ ompare_-

ˆ

ˆˆ

ˆ

ˆ

ˆ

funompargdsl eCOMPamenparfunti artielementularF,gdslularCOMPelementonst voidlistfromF, searVALUE)onstlisthvoid. ( onst gdsl_list_t L, gdsl_-

gdsllistSeSearSeartelementelementL,omparehhh forforforulongaanthp_grPOS)funatestgdslgdslelementbyelementlistitsCOMPpositionofsearintosearF)listinhhlist.a.maxbylistVALUE). position( onst gdsl( onstlistgdslt _L,-

 

element_ gdsl_list

of

 

h_min ( onst gdsl_list_t L,

Sear h for th

lowest

 

list.

gdsl

 

_fun

COMP_F)

 

t gdsl list_sort

(gdsl_list_t L, gdsl_ ompare_-

fun

listCOMP

F)

 

 

 

 

Sort list.

 

 

 

 

 

 

element_ gdsl_list_map_forward ( onst gdsl_list_t L,

gdslParsemaplistfunfromGeneratedheadMAPto tailonF,.ThuvoidJun USER22 11:15:30DATA)2006 for gdsl by Doxygen