meta,
C++
6 Methoden:
/* private: */ uint Btree_ut :: trans_REL
|
/* public: */ Btree * Btree_ut :: to_tree
/* public: */ uint Btree_ut :: create_transitive_Closure
#define static
#include btree_ut.h : cpp
#undef BB
#undef BBStr
#undef bb
#undef bbStr
#define BB
#define BBStr( x,y,z ) ;
#define bb
#define bbStr( x,y,z ) ;
#ifndef procNestOn
#undef LB_
#undef LE_
#undef LE_ret
#undef ret
#undef ret_
#undef __
#undef ___
#define LB_( x ) {
#define LE_ }
#define ret_ return ;
#define LE_ret( x ) return( x ); }
#define ret( x ) return( x );
#define __
#define ___
#endif
/* public: */ Btree * Btree_ut :: to_tree ( char * from
/* -----------------------------------------------------------------------------
Read Btree from file 'from containing lines of the form \n~key~value~
-----------------------------------------------------------------------------
*/ )
LB_("Btree_ut.to_tree")
if not_is_file( from ) ret( 0 )
rBuffer B( from, "\n" );
Btree * tree = new Btree ;
while ( B.find( 0, "\n~", 0 ) )
{
char * k = B.z + B.a + 2 ;
char * c = k ; to_( c, '~' ) *c++ = 0 ;
char * e = c ; to_( e, '~' ) *e++ = 0 ;
tree -> StrIns( 'e', k, c );
B.a = e - B.z ;
}
LE_ret( tree )
/* public: */ uint Btree_ut :: create_transitive_Closure
/* -----------------------------------------------------------------------------
Create the transitive closure >> of a binary relation >
given by records >f1=f2 in Btree REL
Return the cardinality of >> and << ( << the invers of >> ).
-----------------------------------------------------------------------------
*/ (
Btree & REL
, Btree * RELnN // is to contain the transitive closure << of <
, Btree * RELNn // is to contain the transitive closure >> of >
)
LB_("Btree_ut.create_transitive_Closure")
char10 pre ;
char100 fNam ;
char800 fAt ;
KVStore st ; Surr s = REL.GetFirst( st ); uint anz = 0 ;
while ( s )
{
if ( *st.k == '=' )
{
int fNr = decNr( st.k+1 );
char * x = st.k + 1 ; to_( x, '=' ) *x = 0 ;
s_( pre, ">%s=", st.k+1 ); *x = '=' ;
Btree done ;
char10 sNr ; s_( sNr, "%i", fNr );
anz += trans_REL( pre, 1, sNr, done, REL, RELnN, RELNn );
}
s = REL.GetNext( st );
}
LE_ret( anz )
/* private: */ uint Btree_ut :: trans_REL
// -----------------------------------------------------------------------------
(
char * pre
, uint deep
, char * sNr
, Btree & done
, Btree & REL
, Btree * RELnN
, Btree * RELNn
)
LB_("Btree_ut.trans_REL")
KVStore st ; Surr s = REL.Getmin_GE( st, pre ); uint anz = 0 ;
while ( s )
{
if not_At( st.k, pre ) break ;
char * x = st.k + 1 ; to_( x, '=' )
if ( ! done.contains( x+1 ) )
{
done.StrIns( 'e', x+1 );
char20 pre1 ; s_( pre1, "=%s=", x+1 );
KVStore nn ; if ( ! REL.Getmin_GE( nn, pre1 ) ) fErr
char * n = nn.k+1 ; to_( n, '=' ) *n = 0 ;
if ( ! done.contains( n+1 ) )
{
anz++ ;
/*
Semantics of REL:
>fNr1=fNr2 means: f1 > f2
=fNr1=fNam means: fNam is the name of f1
---------------------------------------------------------------
Semantics of trREL
<fNr2=fNr1 means: f2 << f1
>fNr1=fNr2 means: f1 >> f2
here << the transitive closore of REL( < )
here >> the transitive closore of REL( > ), > the Invers of <
*/
char20 xx ;
if ( RELnN )
{
s_( xx, "<%s=%s", sNr, nn.k+1 ); RELnN -> StrIns( 'e', xx );
}
if ( RELNn )
{
s_( xx, ">%s=%s", nn.k+1, sNr ); RELNn -> StrIns( 'e', xx );
}
// ---------------------------------------------------------------
done.StrIns( 'e', n+1 );
}
*n = '=' ;
*pre1 = '>' ;
anz += trans_REL( pre1, deep + 1, sNr, done, REL, RELnN, RELNn );
}
s = REL.GetNext( st );
}
LE_ret( anz )
#undef static
#endif