
Заготовки по С / Динамические структуры / GDSL / Документация
.pdf
4.2 Low-level binary sear h tree manipulation module |
|
27 |
|||||||
ˆ |
gdsl |
_gdsl |
|
post x ( onst _gdsl - |
|||||
|
bstree |
bstree, onst |
gdsl_bstree_map fun _t |
MAP_F, |
void |
||||
|
|
|
|
TA)-bstreelevelwritbinarywritefunsearbstreeh( onstWRITEinmapostgdslF,xed_FILEbstreeorder.bstreeT, onst |
_- |
||||
ˆ gdslUSERParsebstreegdslDAa low |
|
|
|
|
|
||||
ˆ |
void |
|
|
|
|
|
OUTPUT_FILE, |
||
|
|
|
bstreethel ontentDATA)bstreewriteof allwritenodesfun xmlof( onstaWRITElow( onst-level_binaryF,gdslFILEsear h |
e_to aT,le.onst |
|||||
|
_gdslWriteUSERgd |
|
|
|
|
|
|||
ˆ |
void |
|
bstreegdslhe ontentDATA)bstreewritof adumpfunlow-levelt |
|
OUTPUT_FILE, |
||||
|
|
biWRITEary seargdslF,h treFILEbstreetoa letintoT, XMLonst. |
_- |
||||||
|
gdslWriteUSER |
|
|
|
|
|
|||
|
void |
|
|
|
|
|
OUTPUT_FILE, |
||
|
|
|
|
tionsbitaryinternalDATA)Dogdslsearstruumenbintreeh treeturetationofypea.lowgdsl-level_binarybstreeseart h tree to a le. |
|
||||
|
|
|
|
the |
|
|
|
|
|
|
|
|
|
olun |
|
|
|
|
|
4..22..11.1lowDumpTt-ypedeflevfunUSER |
|
|
|
|
|
||||
GDSL |
|
|
|
|
|
|
|
|
|
This |
ype is |
op que. Variables of this kind ould'nt be dire tly used, |
|||||||
De nition |
|
at line 52 of le |
gdsl |
.h. |
|
|
|
||
but by the |
|
this module. |
|
|
|
|
|||
4.2.1.2 |
TREE,typedefbinaryvoidt( _gdsl_bstree_map_fun _t)(_gdsl_bstree_t |
||||||||
|
|
|
|
|
|
|
to thismaptype.fun. tion. |
|
|
Returns:Parameters:GDSLUSERTRlow-levelMAPTheD TAlow-levelThesearUSERuserbinaryh treedatassearDATA)maptohfunpasstreetion |
|
|
|||||||
GDSL_ |
STOP if |
|
m |
st pped. |
|
|
|||
_CONT ifthemapping mustbe ontinued. |
|
|
|||||||
De nition at line 61 of le |
gdsl bstree.h. |
|
|
|
|||||
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |
|
|

28 |
gdsl Module Do umentation |
4.2.1.3 |
gdsltypedefbstreevoid(t TREE,gdsl_bstreeFILE_write_fun _t)(_- |
|
OUTPUT_FILE, void |
|
to thiswriteTREEypefun.. . tion. |
Parameters:GDSLUSEROUTPUTTREElow-levelUSERTheDATAbinarylowFILEDATA)-levelThesearTheuserbinaryh treeledataswheresearwritetohtopassfuntreewritetion |
De nition at line 71 of le _gdsl_bstree.h. |
|||||||
.2.2 Fun tion Do umentation |
|||||||
4.2.2.1 |
|
gdsl |
|
|
gdsl bstree_allo ( onst |
||
Create a newgdslowelbstree- |
sear h tree. |
||||||
|
|
|
|
|
men |
t E) |
|
sets to E and its left andbinaryght sons are set to NULL. |
|||||||
Allo ate a new low-level |
nary sear h tree data stru ture. Its root ontent is |
||||||
Note: |
|
|
|
|
|
|
|
Complexity: O( 1 ) |
|
||||||
re ondition: |
|
|
|
|
|||
nothing. |
|
|
|
|
|||
Parameters: |
|
|
|
|
|||
E The root ontent of the new low-level binary sear h tree to reate. |
|||||||
Returns: |
|
llo ated low-l vel binary sear h tree in ase of su ess. |
|||||
the newly |
|||||||
NULL in ase of insu ient memory. |
|||||||
See also: |
|
|
|
|
|
||
|
gdsl_bstree_free()(p. 28) |
||||||
4.2.2.2 |
|
void _gdsl_ |
free (_gdsl_bstree_t T, onst |
||||
Destroy |
|
gdsl |
free |
funbstreeFREE F) |
|||
|
low-lev |
binary |
h tree. |
||||
FREE |
|
F fun troi |
is used tosear allo ate ea h T's element. Otherwise nothing is |
||||
done with T's elements. |
|
||||||
lush |
and des |
y the low-lev bin ry sear h tree T. If FREE F != NULL, |
|||||
|
|
|
|
|
|
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |

4.2 Low-level binary sear h tree manipulation module |
29 |
||||||
Note: |
|
|
|
|
|
|
|
See |
|
TheO(l funbinaryT)tionsearusedh totreedeallotodesateroyT's. nodes ontents. |
|
||||
Parameters:reFREETnothingComplexity:also:ondition:The .lowF-lev | | |
|
|
|
||||
_gdsl_bstree_allo ()(p. 28) |
y ( onst |
|
|||||
4.2.2.3 |
|
|
_bstree_t |
gdsl bstree |
|
||
opy a low-gdslv |
T, onst gdsl_ opy_fun t COPY_F) |
|
|||||
|
sear |
tree. |
|
|
|||
Create and r turnbinarypy of |
low-level binary sear h tree T using COPY_F |
||||||
on ea h T's element to |
opy them. |
|
|
||||
Note: |
|
|
|
|
|
|
|
Returns:COPYondition:omplexity:ThelowFF!=-levelTheO(NULLbifunT ary.)tionsearusedh toreeopyto T'sopy.nodes ontents. |
|
||||||
Parameters:reCOPYT |
|
| |
| |
|
|
|
|
a op |
of T in ase of su ess. |
|
|
||||
NULL if _gdsl bstree is_empty (T) == TRUE or in ase of insu ient |
|||||||
memory. |
|
|
|
|
|
|
|
See also: |
|
|
allo ()(p. 28) |
|
|
||
|
|
|
free()(p. 28) |
|
|
||
_gdsl_bstree_is empty()(p. 29) |
|
|
|||||
4.2.2.4 |
bool |
|
gdsl |
bstree is empty ( onst _gdsl_bstree_t T) |
|
||
Che k if a low-level binary sear h tree is empty. |
|
|
Note:Complexity: O( 1 )
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

30 |
|
|
|
|
|
|
|
|
|
gdsl Module Do umentation |
|
re ondition: |
|
|
|
|
|
|
|
||||
|
nothing. |
|
|
|
|
|
|
|
|||
Parameters: |
|
|
|
|
|
|
|
||||
|
|
The low-level binary sear h tree to he k. |
|||||||||
Returns: |
|
low- |
el |
|
h |
T is empty. |
|||||
|
TRUE if |
|
|||||||||
|
FALSE ifthe low-levelbinarysear htree T is not empty. |
||||||||||
See also: |
|
|
|
leaf()(p. 30) |
|
|
|
||||
|
|
gdsl_bstree_is_root()(p. 31) |
|
|
|
||||||
4.2.2.5 |
|
bool |
gdsl |
bstree is leaf ( onst _gdsl_bstree_t T) |
|||||||
Che k if a low-level binary sear h tree is redu ed to a leaf. |
|||||||||||
Note: |
|
|
|
|
|
|
|
|
|
|
|
|
Complexity: O( 1 ) |
|
|
|
|
|
|
||||
re ondition: |
|
|
|
|
|
|
|
||||
|
|
|
ust be a non-empty _gdsl_bstree_t. |
||||||||
Parameters: |
|
|
|
|
|
|
|
||||
|
T |
The low-level binary sear h tree to he k. |
|||||||||
Returns: |
|
low- |
el |
|
h |
T is a leaf. |
|||||
|
TRUE if |
|
|||||||||
|
FALSE ifthe low-levelbinarysear htree T is not a leaf. |
||||||||||
See also: |
|
|
|
empty()(p. 29) |
|
|
|||||
|
|
gdsl_bstree_is_root()(p. 31) |
|
|
|
||||||
4.2.2.6 |
|
gdsl |
elemen |
|
gdsl_bstree_get_ ontent ( onst |
||||||
Get the root ontenbstreeof a low-level binary sear h tree. |
|||||||||||
Note: |
|
|
gdsl |
|
|
_t T) |
|
|
|
||
|
|
|
|
|
|
gdsl_bstree_t. |
|||||
|
ComplexitT ust be a non-empty |
||||||||||
Pre ondition:y: O( 1 ) |
|
|
|
|
|
|
|||||
|
|
|
|
|
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |
|

|
4.2 Low-level binary sear h tree manipulation module |
31 |
|||||||
|
Parameters: |
|
|
|
|
|
|
||
|
T The low-lev l binary sear h tree to use. |
|
|||||||
Returns: |
|
|
|
|
|
|
|
||
|
the root's ontent of the low-level binary sear h tree T. |
|
|||||||
|
4.2.2.7 bool |
gdsl bstree is root ( |
nst _gdsl_bstree_t T) |
|
|||||
|
Che k if a low-level binary sear h tree is a root. |
|
|||||||
Note: |
|
|
|
|
|
|
|
|
|
|
re ondition:y: O( 1 ) |
|
|
|
|
|
|||
|
Complexitust be a non-empty _gdsl_bstree_t. |
|
|
||||||
Parameters: |
|
|
|
|
|
|
|||
|
T |
The low-level binary sear h tree to he k. |
|
||||||
Returns: |
|
lowel |
|
h |
T is a root. |
|
|||
|
TRUE if |
|
|
||||||
|
FALSE ifthe low-levelbinarysear htree |
T is not a root. |
|
||||||
See also: |
|
|
empty()(p. 29) |
|
|
||||
|
|
gdsl_bstree_is_leaf()(p. 30) |
|
|
|
||||
4.2.2.8 |
|
|
|
gdsl_bstree_get_parent ( onst |
|
||||
|
|
|
_gdsl_bstree_t T) |
|
|
|
|||
|
Get the paren |
tree of a low-level binary sear h tree. |
|
||||||
Note: |
|
|
|
|
|
|
|
|
|
|
re ondition:y: O( 1 ) |
|
|
|
|
|
|||
|
Complexitust be a non-empty _gdsl_bstree_t. |
|
|
||||||
Parameters: |
|
|
|
|
|
|
|||
|
T |
The low-level binary sear h tree to use. |
|
||||||
Returns: |
|
of the low-level binary sea h tree T if T isn't a root. |
|
||||||
|
the paren |
|
NULL if the low-level binary sear h tree T is a root (ie. T has no parent).
See also:gdsl_bstree_is_root()(p. 31)
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

32 |
|
|
|
gdsl Module Do umentation |
||
|
4.2.2.9 |
|
gdsl_bstree_get_left ( onst |
|
||
|
|
|
_gdsl_bstree_t T) |
|
|
|
|
Get the left sub-tree of a low-level binary sear h tree. |
|||||
Note: |
|
|
|
|
||
|
|
Complexity: O( 1 ) |
|
|
|
|
Pre ondition: |
|
|
|
|||
|
|
T ust be a non-empty _gdsl_bstree_t. |
|
|
||
Parameters: |
|
|
|
|||
|
|
T The low-level binary sear h tree to use. |
||||
Returns: |
|
|
|
|
||
|
|
the left sub-tree of the low-level binary s ar tree T if T has a left sub-tree. |
||||
|
|
NULL if the low-level binary sear h tree T has no left sub-tree. |
||||
See also: |
|
|
|
|
||
|
|
gdsl_bstree_get_right()(p. 32) |
|
|
||
4.2.2.10 |
|
gdsl_bstree_get_right ( onst |
|
_gdsl_bstree_t T) |
|
Get the righ sub-tree of a low-level binary sear h tree. |
||
Note: |
|
|
Complexity: O( 1 ) |
||
Pre ondition: |
|
|
T ust be a non-empty _gdsl_bstree_t. |
||
Parameters: |
|
|
T The low-level binary sear h tree to use. |
||
Returns: |
|
|
the right sub-tree of the low-level binary sear h tree T if T has a right |
||
sub-tree. |
|
|
NULL if the low-level binary sear h tree T has no right sub-tree. |
||
See also: |
|
|
gdsl_bstree_get_left()(p. 32) |
||
|
|
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |

Low-level binary sear h tree manipulation module |
33 |
||
4.2.2.11 ulong |
gdsl_bst ee get_size ( onst _gdsl_bstree_t T) |
|
|
Get the size of a low-level binary sear h tree. |
|
|
|
Note: |
|
|
|
Parameters:retheTnothingComplexity:ondition:Theumber.low-levelofO(elementsbinaryT) searofT h(notedtreeto ompute the size from. |
|
|
|
Returns: |
| | |
|
|
SeeGet4.2.2thealso:.12gdslheightTulongbstree)of a lowgdslget-levelbstreeheight()binary getsear(p.33)|hTheight|tree). . ( onst _gdsl_bstree_t
Compute the height of the low-level binary sear h tree T (noted h(T)). |
|||
Note: |
|
|
|
Parameters:retheTnothingComplexity:ondition:Theheigh.lowbstreeof-levelO(T. binaryT) sear h tree to ompute the height from. |
|||
Returns: |
| | |
|
|
See also: |
_get_size()(p. 33) |
|
|
gdsl_ |
_ |
(_gdsl_bstree_t |
|
4.2.2.13 _gdsl_ |
_gdsl_ |
gdslT, elemenonstbstreegdsl t VALUEomparebstree,infun _insertCOMP_F, onst
GenerateditInsert. an elementon Thu Juninto22a11:15:30low-level2006binaryfor gdslsearbyhDoxygenRESULTtree if it's)not found or return

34 |
h for |
|
r |
lemen |
E equal |
|
gdsl Module Do umentation |
|||
|
|
VALUE into the low-level binary sear h |
|
|||||||
foun , then it's e |
|
. If no element equal to VALUE is found, thenALUEis |
||||||||
Searins rted and its rootreturned. |
|
d it. If an element E eq al to V |
||||||||
tree T, by using COMP F fun tion to |
||||||||||
Note: |
|
|
|
|
|
|
|
|
|
|
|
COMPondition:omplexity:TheVALUEreferenFF!=TheO(toNULLeh(T)ofndomparisontheE&),.lowRESULTwhere-levelfunlog2(binary!=tionTNULLto)searuse=. h(T)tohtreeompareto= useTT's-.1 elements with |
|||||||||
Parameters:reCOMPT |
|
|
|
| |
| < |
< |
| | |
|
||
|
VAL |
|
The value u ed to sear h for the el ment E. |
|
|
|||||
|
RESU T The address where the result ode will be stored. |
|||||||||
Returns: |
on |
E and RESULT = GDSL |
INSERTED if E is inserted. |
|||||||
|
the root |
|||||||||
|
|
ontaining E and RESULT = GDSL ERR DUPLICATE - |
||||||||
|
ENTRY if E is not inserted. |
ERR |
MEM |
ALLOC in ase of failure. |
||||||
|
NULL and RESULT = GDSL |
|||||||||
See also: |
|
|
s ar h()(p. 35) |
|
|
|
|
|||
|
gdsl_bstree_remove()(p. 34) |
|
|
|
|
|||||
4.2.2.14 |
|
|
|
_gdsl_bstree_remove (_gdsl_b ree_t |
Note:equalfound,RemovComplexitto anVALUE,fromisgdslremovedelemenTthey:, O(byelementonstlowfromfromh(T)using-levelgdslaT),COMPlow.binarywheret VALUE-levelomparelog2(searFbinaryfun)htionfuntrees artoThttheomparetrCOMP. stT'sfoundedFelements, onelementst. If E Eis
Parameters:re ThefCOMPTondition:undedTheresultingreferenF.!=NULLTe ofis the.modilowed-levelby binaryexaminating|T|) sear<= h(T)h treethe<leftto=|modifyTsub|-1-tree. from the
Gen rated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

4.2 Low-level binary sear h tree manipulation module |
|
35 |
|||||||||||
COMP F The omp rison |
|
|
to use to ompare T's elements |
|
|||||||||
|
VALUE to nd the |
|
fun etiontoremove. |
|
|
|
|||||||
VALUE The value thatelemenust be used by COMP_F to nd the elemenwithe |
|||||||||||||
Returns:to remov . |
|
|
|
|
|
|
|
|
|
|
|||
the srt founded element equal to VALUE in T. |
|
|
|
||||||||||
NULL if no element equal to VALUE is found or if T is empty. |
|
||||||||||||
See also: |
|
|
insert()(p. 33) |
|
|
|
|
|
|||||
|
gdsl_bstree_sear h()(p. 35) |
|
|
|
|
|
|||||||
4.2.2.15 |
gdsl_bstree |
gdsl bstree_sear h ( onst |
|
|
|||||||||
|
|
T, onst gdsl_ ompare |
fun _t |
|
|||||||||
|
|
COMP F, |
onst gdsl |
|
element |
t VALUE) |
|
|
|||||
|
for a parti ular elemen |
in |
|
a low-level binary sear h tree. |
|
||||||||
Sear h the rst element E equal to VALUE in the low-level binary sear h tree |
|||||||||||||
T, by using COMP |
F fun tion to nd it. |
|
|
|
|
||||||||
Note: |
|
|
|
|
th),esearwhereelemenhfunlog2(treeEtion.toTtouse)use.= h(T)to ompare= TT's-1 |
elements with |
|||||||
Parameters:Pre COMPTCOMPComplexity:ondition:TheVALUElowFF-!=levelTheO(toNULLh(T)binaryndomparison. |
|
|
| | < |
< |
| | |
|
|
||||||
VALUE. |
The value |
at |
ust be used by COMP_F to nd the elemen |
||||||||||
Returns: |
|
|
|
|
|
|
|
|
|
|
|
|
|
the root of the tree ontaining E if it's found. |
|
|
|
||||||||||
NULL if VALUE not found in T. |
|
|
|
|
|||||||||
See also: |
|
|
insert() p. 33) |
|
|
|
|
|
|||||
|
gdsl_bstree_remove()(p. 34) |
|
|
|
|
||||||||
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |
|
|
|

36 |
|
|
|
|
gdsl |
gdsl Module Do umentation |
||||
|
4.2.2.16 |
|
|
|
|
|
sear h |
next |
|
|
|
|
gdsl_bstree |
|
T, onst gdsl |
|
fun( onst |
||||
|
|
COMP F, onst gdsl |
t |
t VALUE) |
|
|||||
|
|
the next elemen |
of |
parti ularelembstreementompareinto low-level binary sear h |
||||||
|
tree, a ording to |
bi ary sear h tree order. |
|
|
|
|||||
|
Sear h for an elementheE in the low-level binary sear h tree T, by using COMP_F |
|||||||||
|
fun tion to nd the rst element E equal to VALUE. |
|
|
|||||||
Note: |
|
|
|
|
|
|
|
|
|
|
|
COMPondition:omplexity:TheVALUElowFF-!=levelTheO(toNULLh(T)binaryndomparison.th),ewhereelemenar hfunlog2(treeEtion.toTtouse)use.= h(T)to ompare= TT's-1 elements with |
|||||||||
Parameters:reCOMPT |
|
|
|
| |
| < |
< |
| | |
|
||
|
VALUE. |
The value |
at |
ust be used by COMP_F to nd the elemen |
||||||
Returns: |
|
|
|
|
|
|
of E if it's f und. |
|||
|
the root of the tree ontaining the |
|
||||||||
|
NULL if VALUE is not found in Tsu ifessorE has no su essor. |
( onst |
||||||||
4.2.2.17 |
_gdsl |
|
|
gdsl bstree_map pre x |
||||||
|
|
bstree_t T, onst |
gdsl_bstree map fun _t |
|||||||
|
ParseComplexity:.MAPx()aIfal(plMAPow.nodesMAP-36)FlevelfunstopsFbinaryO(ofreturtionF,theandvoidisearGDSLlowreturnsalled-hlevelUSERtreeonMAPitsbinaryealastpreDATAhSTOP,examinatednodexedsear)orderthenwithtree.nodethegdslTUSER.inbstreepreDATAxedmaporderrgu-. |
|||||||||
Note:premenThe |
|
|
|
|
|
|
|
|
|
Parameters:reMAPTMAPUSERondition:TheFlowFDA!=-ThelevelNULLAmap|binaTUser's|. )funyseardatastion.hpassedtreetotomapMAP._F.
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen