2010-04-05 03:31:12 +01:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * *
* * T h e Y a p T a b / Y a p O r / O P T Y a p s y s t e m s * *
* * * *
* * Y a p T a b e x t e n d s t h e Y a p P r o l o g e n g i n e to s u p p o r t s e q u e n t i a l t a b l i n g * *
* * Y a p O r e x t e n d s t h e Y a p P r o l o g e n g i n e to s u p p o r t o r - p a r a l l e l i s m * *
* * O P T Y a p e x t e n d s t h e Y a p P r o l o g e n g i n e to s u p p o r t o r - p a r a l l e l t a b l i n g * *
* * * *
* * * *
* * Y a p P r o l o g w a s d e v e l o p e d at U n i v e r s i t y of P o r t o , P o r t u g a l * *
* * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/* * * * * * * * * * * * * * * * * * * * *
* * M a c r o s * *
* * * * * * * * * * * * * * * * * * * * * /
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ E N T R Y
# define I N C R E M E N T _ G L O B A L _ T R I E _ R E F E R E N C E ( ENTRY ) \
{ r e g i s t e r g t _ n o d e _ p t r e n t r y _ n o d e = ( g t _ n o d e _ p t r ) ( E N T R Y ) ; \
2014-01-19 21:15:05 +00:00
T r N o d e _ c h i l d ( e n t r y _ n o d e ) = ( g t _ n o d e _ p t r ) ( ( U I n t ) T r N o d e _ c h i l d ( e n t r y _ n o d e ) + 1 ) ; \
2010-04-15 01:09:59 +01:00
}
2010-04-05 03:31:12 +01:00
# define N E W _ S U B G O A L _ T R I E _ N O D E ( N O D E , ENTRY , C H I L D , PARENT , NEXT ) \
I N C R E M E N T _ G L O B A L _ T R I E _ R E F E R E N C E ( ENTRY ) ; \
n e w _ s u b g o a l _ t r i e _ n o d e ( N O D E , ENTRY , C H I L D , PARENT , NEXT )
# define N E W _ A N S W E R _ T R I E _ N O D E ( N O D E , I N S T R , ENTRY , C H I L D , PARENT , NEXT ) \
I N C R E M E N T _ G L O B A L _ T R I E _ R E F E R E N C E ( ENTRY ) ; \
n e w _ a n s w e r _ t r i e _ n o d e ( N O D E , I N S T R , ENTRY , C H I L D , PARENT , NEXT )
# define N E W _ G L O B A L _ T R I E _ N O D E ( N O D E , ENTRY , C H I L D , PARENT , NEXT ) \
I N C R E M E N T _ G L O B A L _ T R I E _ R E F E R E N C E ( ENTRY ) ; \
n e w _ g l o b a l _ t r i e _ n o d e ( N O D E , ENTRY , C H I L D , PARENT , NEXT )
# else
# define N E W _ S U B G O A L _ T R I E _ N O D E ( N O D E , ENTRY , C H I L D , PARENT , NEXT ) \
n e w _ s u b g o a l _ t r i e _ n o d e ( N O D E , ENTRY , C H I L D , PARENT , NEXT )
# define N E W _ A N S W E R _ T R I E _ N O D E ( N O D E , I N S T R , ENTRY , C H I L D , PARENT , NEXT ) \
n e w _ a n s w e r _ t r i e _ n o d e ( N O D E , I N S T R , ENTRY , C H I L D , PARENT , NEXT )
# define N E W _ G L O B A L _ T R I E _ N O D E ( N O D E , ENTRY , C H I L D , PARENT , NEXT ) \
n e w _ g l o b a l _ t r i e _ n o d e ( N O D E , ENTRY , C H I L D , PARENT , NEXT )
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ E N T R Y */
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
2012-05-14 19:11:58 +01:00
# define S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( T A B _ E N T , N O D E , ENTRY ) \
N O D E = g l o b a l _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( N O D E , ENTRY P A S S _ R E G S )
# define A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( S G _ F R , N O D E , ENTRY , I N S T R ) \
N O D E = g l o b a l _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( N O D E , ENTRY P A S S _ R E G S )
2010-04-15 01:09:59 +01:00
# else
2012-05-14 19:11:58 +01:00
# define S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( T A B _ E N T , N O D E , ENTRY ) \
N O D E = s u b g o a l _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( T A B _ E N T , N O D E , ENTRY P A S S _ R E G S )
2013-12-19 10:56:52 +00:00
# define A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( S G _ F R , N O D E , ENTRY , I N S T R ) \
2012-05-14 19:11:58 +01:00
N O D E = a n s w e r _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( S G _ F R , N O D E , ENTRY , I N S T R P A S S _ R E G S )
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
2010-04-05 03:31:12 +01:00
2012-06-04 19:27:31 +01:00
# i f def I N C L U D E _ A N S W E R _ S E A R C H _ M O D E _ D I R E C T E D
# define A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( N O D E , ENTRY , I N S T R ) \
{ a n s _ n o d e _ p t r n e w _ n o d e ; \
N E W _ A N S W E R _ T R I E _ N O D E ( n e w _ n o d e , I N S T R , ENTRY , NULL , N O D E , NULL ) ; \
2013-12-19 10:56:52 +00:00
T r N o d e _ c h i l d ( N O D E ) = n e w _ n o d e ; \
2012-06-04 19:27:31 +01:00
N O D E = n e w _ n o d e ; \
2013-12-19 10:56:52 +00:00
}
2012-06-04 19:27:31 +01:00
# i f def T H R E A D S
# define I N V A L I D A T E _ A N S W E R _ T R I E _ N O D E ( N O D E , S G _ F R ) \
T r N o d e _ n e x t ( N O D E ) = S g F r _ i n v a l i d _ c h a i n ( S G _ F R ) ; \
S g F r _ i n v a l i d _ c h a i n ( S G _ F R ) = N O D E
# else
# define I N V A L I D A T E _ A N S W E R _ T R I E _ N O D E ( N O D E , S G _ F R ) \
F R E E _ A N S W E R _ T R I E _ N O D E ( N O D E )
# e n d i f /* T H R E A D S */
# define I N V A L I D A T E _ A N S W E R _ T R I E _ L E A F _ N O D E ( N O D E , S G _ F R ) \
T A G _ A S _ A N S W E R _ I N V A L I D _ N O D E ( N O D E ) ; \
T r N o d e _ n e x t ( N O D E ) = S g F r _ i n v a l i d _ c h a i n ( S G _ F R ) ; \
S g F r _ i n v a l i d _ c h a i n ( S G _ F R ) = N O D E
# e n d i f /* I N C L U D E _ A N S W E R _ S E A R C H _ M O D E _ D I R E C T E D */
2010-04-05 03:31:12 +01:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2010-04-15 01:09:59 +01:00
* * s u b g o a l _ t r i e _ c h e c k _ i n s e r t _ ( gt ) _ e n t r y * *
2010-04-05 03:31:12 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def I N C L U D E _ S U B G O A L _ T R I E _ C H E C K _ I N S E R T
2011-11-15 16:57:51 +00:00
# i f n def S U B G O A L _ T R I E _ L O C K _ A T _ W R I T E _ L E V E L /* S U B G O A L _ T R I E _ L O C K _ A T _ E N T R Y _ L E V E L | | S U B G O A L _ T R I E _ L O C K _ A T _ N O D E _ L E V E L | | ! Y A P O R */
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ E N T R Y
2012-05-14 19:11:58 +01:00
static i n l i n e s g _ n o d e _ p t r s u b g o a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( t a b _ e n t _ p t r t a b _ e n t , s g _ n o d e _ p t r p a r e n t _ n o d e , Term t U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e s g _ n o d e _ p t r s u b g o a l _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( t a b _ e n t _ p t r t a b _ e n t , s g _ n o d e _ p t r p a r e n t _ n o d e , Term t U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ E N T R Y */
s g _ n o d e _ p t r c h i l d _ n o d e ;
2011-11-15 16:57:51 +00:00
L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-15 01:09:59 +01:00
c h i l d _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( c h i l d _ n o d e = = NULL ) {
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , NULL ) ;
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
2011-11-15 16:57:51 +00:00
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-15 01:09:59 +01:00
return c h i l d _ n o d e ;
}
if ( ! I S _ S U B G O A L _ T R I E _ H A S H ( c h i l d _ n o d e ) ) {
int c o u n t _ n o d e s = 0 ;
do {
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-15 01:09:59 +01:00
return c h i l d _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
} while ( c h i l d _ n o d e ) ;
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ T R I E _ L E V E L ) {
/* a l l o c a n e w h a s h */
s g _ h a s h _ p t r h a s h ;
s g _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * b u c k e t ;
n e w _ s u b g o a l _ t r i e _ h a s h ( h a s h , c o u n t _ n o d e s , t a b _ e n t ) ;
c h a i n _ n o d e = c h i l d _ n o d e ;
do {
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , B A S E _ H A S H _ B U C K E T S ) ;
2010-04-15 01:09:59 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = ( s g _ n o d e _ p t r ) h a s h ;
} else {
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
}
2011-11-15 16:57:51 +00:00
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-15 01:09:59 +01:00
return c h i l d _ n o d e ;
}
{ / * t r i e n o d e s w i t h h a s h i n g * /
s g _ h a s h _ p t r h a s h ;
s g _ n o d e _ p t r * b u c k e t ;
int c o u n t _ n o d e s = 0 ;
h a s h = ( s g _ h a s h _ p t r ) c h i l d _ n o d e ;
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( t , H a s h _ n u m _ b u c k e t s ( h a s h ) ) ;
2010-04-15 01:09:59 +01:00
c h i l d _ n o d e = * b u c k e t ;
while ( c h i l d _ n o d e ) {
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-15 01:09:59 +01:00
return c h i l d _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
}
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , * b u c k e t ) ;
* b u c k e t = c h i l d _ n o d e ;
H a s h _ n u m _ n o d e s ( h a s h ) + + ;
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ B U C K E T && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* e x p a n d c u r r e n t h a s h */
2011-12-14 10:33:18 +00:00
s g _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * o l d _ b u c k e t , * o l d _ h a s h _ b u c k e t s , * n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
int n u m _ b u c k e t s ;
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) * 2 ;
2011-12-22 16:50:20 +00:00
A L L O C _ B U C K E T S ( n e w _ h a s h _ b u c k e t s , n u m _ b u c k e t s ) ;
2011-12-14 10:33:18 +00:00
o l d _ h a s h _ b u c k e t s = H a s h _ b u c k e t s ( h a s h ) ;
o l d _ b u c k e t = o l d _ h a s h _ b u c k e t s + H a s h _ n u m _ b u c k e t s ( h a s h ) ;
2010-04-15 01:09:59 +01:00
do {
if ( * - - o l d _ b u c k e t ) {
c h a i n _ n o d e = * o l d _ b u c k e t ;
do {
2011-12-14 10:33:18 +00:00
b u c k e t = n e w _ h a s h _ b u c k e t s + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , n u m _ b u c k e t s ) ;
2010-04-15 01:09:59 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
}
2011-12-14 10:33:18 +00:00
} while ( o l d _ b u c k e t ! = o l d _ h a s h _ b u c k e t s ) ;
H a s h _ b u c k e t s ( h a s h ) = n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
H a s h _ n u m _ b u c k e t s ( h a s h ) = n u m _ b u c k e t s ;
2011-12-22 16:50:20 +00:00
F R E E _ B U C K E T S ( o l d _ h a s h _ b u c k e t s ) ;
2010-04-15 01:09:59 +01:00
}
2011-11-15 16:57:51 +00:00
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-15 01:09:59 +01:00
return c h i l d _ n o d e ;
}
}
2011-11-15 16:57:51 +00:00
# else /* S U B G O A L _ T R I E _ L O C K _ A T _ W R I T E _ L E V E L */
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ E N T R Y
2012-05-14 19:11:58 +01:00
static i n l i n e s g _ n o d e _ p t r s u b g o a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( t a b _ e n t _ p t r t a b _ e n t , s g _ n o d e _ p t r p a r e n t _ n o d e , Term t U S E S _ R E G S ) {
2010-04-05 03:31:12 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e s g _ n o d e _ p t r s u b g o a l _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( t a b _ e n t _ p t r t a b _ e n t , s g _ n o d e _ p t r p a r e n t _ n o d e , Term t U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ E N T R Y */
2010-04-05 03:31:12 +01:00
s g _ n o d e _ p t r c h i l d _ n o d e ;
s g _ h a s h _ p t r h a s h ;
c h i l d _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( c h i l d _ n o d e = = NULL ) {
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , NULL ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
if ( T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) {
s g _ n o d e _ p t r c h a i n _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( I S _ S U B G O A L _ T R I E _ H A S H ( c h a i n _ n o d e ) ) {
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
h a s h = ( s g _ h a s h _ p t r ) c h a i n _ n o d e ;
g o t o s u b g o a l _ t r i e _ h a s h ;
}
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h a i n _ n o d e ;
}
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
T r N o d e _ n e x t ( c h i l d _ n o d e ) = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
# else
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
} else {
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , NULL ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
2010-04-05 03:31:12 +01:00
}
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
2011-11-15 16:57:51 +00:00
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
if ( ! I S _ S U B G O A L _ T R I E _ H A S H ( c h i l d _ n o d e ) ) {
s g _ n o d e _ p t r f i r s t _ n o d e = c h i l d _ n o d e ;
int c o u n t _ n o d e s = 0 ;
do {
2011-11-15 16:57:51 +00:00
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t )
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
} while ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
if ( f i r s t _ n o d e ! = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) {
s g _ n o d e _ p t r c h a i n _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( I S _ S U B G O A L _ T R I E _ H A S H ( c h a i n _ n o d e ) ) {
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
h a s h = ( s g _ h a s h _ p t r ) c h a i n _ n o d e ;
g o t o s u b g o a l _ t r i e _ h a s h ;
}
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h a i n _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ! = f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
T r N o d e _ n e x t ( c h i l d _ n o d e ) = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
# else
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
} else {
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
2010-04-05 03:31:12 +01:00
}
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ T R I E _ L E V E L ) {
/* a l l o c a n e w h a s h */
s g _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * b u c k e t ;
n e w _ s u b g o a l _ t r i e _ h a s h ( h a s h , c o u n t _ n o d e s , t a b _ e n t ) ;
c h a i n _ n o d e = c h i l d _ n o d e ;
do {
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , B A S E _ H A S H _ B U C K E T S ) ;
2010-04-05 03:31:12 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = ( s g _ n o d e _ p t r ) h a s h ;
} else {
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
}
2011-11-15 16:57:51 +00:00
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
h a s h = ( s g _ h a s h _ p t r ) c h i l d _ n o d e ;
s u b g o a l _ t r i e _ h a s h :
{ / * t r i e n o d e s w i t h h a s h i n g * /
s g _ n o d e _ p t r * b u c k e t , f i r s t _ n o d e ;
2011-12-12 17:24:58 +00:00
int n u m _ b u c k e t s , c o u n t _ n o d e s = 0 ;
2010-04-05 03:31:12 +01:00
2011-12-14 10:33:18 +00:00
do {
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) ;
// __sync_synchronize();
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( t , n u m _ b u c k e t s ) ;
f i r s t _ n o d e = c h i l d _ n o d e = * b u c k e t ;
} while ( n u m _ b u c k e t s ! = H a s h _ n u m _ b u c k e t s ( h a s h ) ) ;
2010-04-05 03:31:12 +01:00
while ( c h i l d _ n o d e ) {
2011-11-15 16:57:51 +00:00
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t )
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
}
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2011-12-12 17:24:58 +00:00
if ( n u m _ b u c k e t s ! = H a s h _ n u m _ b u c k e t s ( h a s h ) ) {
2010-04-05 03:31:12 +01:00
/* t h e h a s h h a s b e e n e x p a n d e d */
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
g o t o s u b g o a l _ t r i e _ h a s h ;
}
if ( f i r s t _ n o d e ! = * b u c k e t ) {
s g _ n o d e _ p t r c h a i n _ n o d e = * b u c k e t ;
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h a i n _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ! = f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# i f def S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
T r N o d e _ n e x t ( c h i l d _ n o d e ) = * b u c k e t ;
# else
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , * b u c k e t ) ;
} else {
N E W _ S U B G O A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
2010-04-05 03:31:12 +01:00
}
* b u c k e t = c h i l d _ n o d e ;
H a s h _ n u m _ n o d e s ( h a s h ) + + ;
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ B U C K E T && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* e x p a n d c u r r e n t h a s h */
2011-12-14 10:33:18 +00:00
s g _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * o l d _ b u c k e t , * o l d _ h a s h _ b u c k e t s , * n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) * 2 ;
2011-12-22 16:50:20 +00:00
A L L O C _ B U C K E T S ( n e w _ h a s h _ b u c k e t s , n u m _ b u c k e t s ) ;
2011-12-14 10:33:18 +00:00
o l d _ h a s h _ b u c k e t s = H a s h _ b u c k e t s ( h a s h ) ;
o l d _ b u c k e t = o l d _ h a s h _ b u c k e t s + H a s h _ n u m _ b u c k e t s ( h a s h ) ;
2010-04-05 03:31:12 +01:00
do {
if ( * - - o l d _ b u c k e t ) {
c h a i n _ n o d e = * o l d _ b u c k e t ;
do {
2011-12-14 10:33:18 +00:00
b u c k e t = n e w _ h a s h _ b u c k e t s + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , n u m _ b u c k e t s ) ;
2010-04-05 03:31:12 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
}
2011-12-14 10:33:18 +00:00
} while ( o l d _ b u c k e t ! = o l d _ h a s h _ b u c k e t s ) ;
H a s h _ b u c k e t s ( h a s h ) = n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
H a s h _ n u m _ b u c k e t s ( h a s h ) = n u m _ b u c k e t s ;
2011-12-22 16:50:20 +00:00
F R E E _ B U C K E T S ( o l d _ h a s h _ b u c k e t s ) ;
2010-04-05 03:31:12 +01:00
}
2011-11-15 16:57:51 +00:00
U N L O C K _ S U B G O A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
}
2011-11-15 16:57:51 +00:00
# e n d i f /* S U B G O A L _ T R I E _ L O C K _ L E V E L */
2010-04-15 01:09:59 +01:00
# e n d i f /* I N C L U D E _ S U B G O A L _ T R I E _ C H E C K _ I N S E R T */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * a n s w e r _ t r i e _ c h e c k _ i n s e r t _ ( gt ) _ e n t r y * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def I N C L U D E _ A N S W E R _ T R I E _ C H E C K _ I N S E R T
2011-11-15 16:57:51 +00:00
# i f n def A N S W E R _ T R I E _ L O C K _ A T _ W R I T E _ L E V E L /* A N S W E R _ T R I E _ L O C K _ A T _ E N T R Y _ L E V E L | | A N S W E R _ T R I E _ L O C K _ A T _ N O D E _ L E V E L | | ! Y A P O R */
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ E N T R Y
2012-05-14 19:11:58 +01:00
static i n l i n e a n s _ n o d e _ p t r a n s w e r _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( s g _ f r _ p t r s g _ f r , a n s _ n o d e _ p t r p a r e n t _ n o d e , Term t , int i n s t r U S E S _ R E G S ) {
2010-04-05 03:31:12 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e a n s _ n o d e _ p t r a n s w e r _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( s g _ f r _ p t r s g _ f r , a n s _ n o d e _ p t r p a r e n t _ n o d e , Term t , int i n s t r U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ E N T R Y */
a n s _ n o d e _ p t r c h i l d _ n o d e ;
2010-04-18 04:59:11 +01:00
T A B L I N G _ E R R O R _ C H E C K I N G ( a n s w e r _ t r i e _ c h e c k _ i n s e r t _ ( gt ) _ e n t r y , I S _ A N S W E R _ L E A F _ N O D E ( p a r e n t _ n o d e ) ) ;
2011-11-15 16:57:51 +00:00
L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
c h i l d _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( c h i l d _ n o d e = = NULL ) {
2010-04-15 01:09:59 +01:00
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , NULL ) ;
2010-04-05 03:31:12 +01:00
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
2011-11-15 16:57:51 +00:00
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
2010-04-15 01:09:59 +01:00
if ( ! I S _ A N S W E R _ T R I E _ H A S H ( c h i l d _ n o d e ) ) {
2010-04-05 03:31:12 +01:00
int c o u n t _ n o d e s = 0 ;
do {
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
} while ( c h i l d _ n o d e ) ;
2010-04-15 01:09:59 +01:00
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
2010-04-05 03:31:12 +01:00
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ T R I E _ L E V E L ) {
/* a l l o c a n e w h a s h */
2010-04-15 01:09:59 +01:00
a n s _ h a s h _ p t r h a s h ;
a n s _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * b u c k e t ;
n e w _ a n s w e r _ t r i e _ h a s h ( h a s h , c o u n t _ n o d e s , s g _ f r ) ;
2010-04-05 03:31:12 +01:00
c h a i n _ n o d e = c h i l d _ n o d e ;
do {
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , B A S E _ H A S H _ B U C K E T S ) ;
2010-04-05 03:31:12 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
2010-04-15 01:09:59 +01:00
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = ( a n s _ n o d e _ p t r ) h a s h ;
2010-04-05 03:31:12 +01:00
} else {
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
}
2011-11-15 16:57:51 +00:00
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
{ / * t r i e n o d e s w i t h h a s h i n g * /
2010-04-15 01:09:59 +01:00
a n s _ h a s h _ p t r h a s h ;
a n s _ n o d e _ p t r * b u c k e t ;
2010-04-05 03:31:12 +01:00
int c o u n t _ n o d e s = 0 ;
2010-04-15 01:09:59 +01:00
h a s h = ( a n s _ h a s h _ p t r ) c h i l d _ n o d e ;
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( t , H a s h _ n u m _ b u c k e t s ( h a s h ) ) ;
2010-04-05 03:31:12 +01:00
c h i l d _ n o d e = * b u c k e t ;
while ( c h i l d _ n o d e ) {
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
}
2010-04-15 01:09:59 +01:00
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , * b u c k e t ) ;
2010-04-05 03:31:12 +01:00
* b u c k e t = c h i l d _ n o d e ;
H a s h _ n u m _ n o d e s ( h a s h ) + + ;
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ B U C K E T && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
2010-04-15 01:09:59 +01:00
/* e x p a n d c u r r e n t h a s h */
2011-12-14 10:33:18 +00:00
a n s _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * o l d _ b u c k e t , * o l d _ h a s h _ b u c k e t s , * n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
int n u m _ b u c k e t s ;
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) * 2 ;
2011-12-22 16:50:20 +00:00
A L L O C _ B U C K E T S ( n e w _ h a s h _ b u c k e t s , n u m _ b u c k e t s ) ;
2011-12-14 10:33:18 +00:00
o l d _ h a s h _ b u c k e t s = H a s h _ b u c k e t s ( h a s h ) ;
o l d _ b u c k e t = o l d _ h a s h _ b u c k e t s + H a s h _ n u m _ b u c k e t s ( h a s h ) ;
2010-04-05 03:31:12 +01:00
do {
if ( * - - o l d _ b u c k e t ) {
c h a i n _ n o d e = * o l d _ b u c k e t ;
do {
2011-12-14 10:33:18 +00:00
b u c k e t = n e w _ h a s h _ b u c k e t s + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , n u m _ b u c k e t s ) ;
2010-04-05 03:31:12 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
}
2011-12-14 10:33:18 +00:00
} while ( o l d _ b u c k e t ! = o l d _ h a s h _ b u c k e t s ) ;
H a s h _ b u c k e t s ( h a s h ) = n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
H a s h _ n u m _ b u c k e t s ( h a s h ) = n u m _ b u c k e t s ;
2011-12-22 16:50:20 +00:00
F R E E _ B U C K E T S ( o l d _ h a s h _ b u c k e t s ) ;
2010-04-05 03:31:12 +01:00
}
2011-11-15 16:57:51 +00:00
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
}
2011-11-15 16:57:51 +00:00
# else /* A N S W E R _ T R I E _ L O C K _ A T _ W R I T E _ L E V E L */
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ E N T R Y
2012-05-14 19:11:58 +01:00
static i n l i n e a n s _ n o d e _ p t r a n s w e r _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( s g _ f r _ p t r s g _ f r , a n s _ n o d e _ p t r p a r e n t _ n o d e , Term t , int i n s t r U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e a n s _ n o d e _ p t r a n s w e r _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( s g _ f r _ p t r s g _ f r , a n s _ n o d e _ p t r p a r e n t _ n o d e , Term t , int i n s t r U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ E N T R Y */
2010-04-05 03:31:12 +01:00
a n s _ n o d e _ p t r c h i l d _ n o d e ;
a n s _ h a s h _ p t r h a s h ;
2010-04-18 04:59:11 +01:00
T A B L I N G _ E R R O R _ C H E C K I N G ( a n s w e r _ t r i e _ c h e c k _ i n s e r t _ ( gt ) _ e n t r y , I S _ A N S W E R _ L E A F _ N O D E ( p a r e n t _ n o d e ) ) ;
2010-04-05 03:31:12 +01:00
c h i l d _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( c h i l d _ n o d e = = NULL ) {
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , NULL ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
if ( T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) {
a n s _ n o d e _ p t r c h a i n _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( I S _ A N S W E R _ T R I E _ H A S H ( c h a i n _ n o d e ) ) {
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
h a s h = ( a n s _ h a s h _ p t r ) c h a i n _ n o d e ;
g o t o a n s w e r _ t r i e _ h a s h ;
}
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h a i n _ n o d e ;
}
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
T r N o d e _ n e x t ( c h i l d _ n o d e ) = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
# else
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
} else {
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , NULL ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
2010-04-05 03:31:12 +01:00
}
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
2011-11-15 16:57:51 +00:00
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
if ( ! I S _ A N S W E R _ T R I E _ H A S H ( c h i l d _ n o d e ) ) {
a n s _ n o d e _ p t r f i r s t _ n o d e = c h i l d _ n o d e ;
int c o u n t _ n o d e s = 0 ;
do {
2011-11-15 16:57:51 +00:00
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t )
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
} while ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
if ( f i r s t _ n o d e ! = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) {
a n s _ n o d e _ p t r c h a i n _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( I S _ A N S W E R _ T R I E _ H A S H ( c h a i n _ n o d e ) ) {
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
h a s h = ( a n s _ h a s h _ p t r ) c h a i n _ n o d e ;
g o t o a n s w e r _ t r i e _ h a s h ;
}
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h a i n _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ! = f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
T r N o d e _ n e x t ( c h i l d _ n o d e ) = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
# else
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
} else {
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
2010-04-05 03:31:12 +01:00
}
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ T R I E _ L E V E L ) {
/* a l l o c a n e w h a s h */
a n s _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * b u c k e t ;
n e w _ a n s w e r _ t r i e _ h a s h ( h a s h , c o u n t _ n o d e s , s g _ f r ) ;
c h a i n _ n o d e = c h i l d _ n o d e ;
do {
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , B A S E _ H A S H _ B U C K E T S ) ;
2010-04-05 03:31:12 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = ( a n s _ n o d e _ p t r ) h a s h ;
} else {
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
}
2011-11-15 16:57:51 +00:00
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
h a s h = ( a n s _ h a s h _ p t r ) c h i l d _ n o d e ;
a n s w e r _ t r i e _ h a s h :
{ / * t r i e n o d e s w i t h h a s h i n g * /
a n s _ n o d e _ p t r * b u c k e t , f i r s t _ n o d e ;
2011-12-12 17:24:58 +00:00
int n u m _ b u c k e t s , c o u n t _ n o d e s = 0 ;
2010-04-05 03:31:12 +01:00
2011-12-14 10:33:18 +00:00
do {
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) ;
// __sync_synchronize();
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( t , n u m _ b u c k e t s ) ;
f i r s t _ n o d e = c h i l d _ n o d e = * b u c k e t ;
} while ( n u m _ b u c k e t s ! = H a s h _ n u m _ b u c k e t s ( h a s h ) ) ;
2010-04-05 03:31:12 +01:00
while ( c h i l d _ n o d e ) {
2011-11-15 16:57:51 +00:00
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t )
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
}
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2011-12-12 17:24:58 +00:00
if ( n u m _ b u c k e t s ! = H a s h _ n u m _ b u c k e t s ( h a s h ) ) {
2010-04-05 03:31:12 +01:00
/* t h e h a s h h a s b e e n e x p a n d e d */
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
g o t o a n s w e r _ t r i e _ h a s h ;
}
if ( f i r s t _ n o d e ! = * b u c k e t ) {
a n s _ n o d e _ p t r c h a i n _ n o d e = * b u c k e t ;
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
F R E E _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h a i n _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ! = f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# i f def A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K
2010-04-05 03:31:12 +01:00
T r N o d e _ n e x t ( c h i l d _ n o d e ) = * b u c k e t ;
# else
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , * b u c k e t ) ;
} else {
N E W _ A N S W E R _ T R I E _ N O D E ( c h i l d _ n o d e , i n s t r , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
2010-04-05 03:31:12 +01:00
}
* b u c k e t = c h i l d _ n o d e ;
H a s h _ n u m _ n o d e s ( h a s h ) + + ;
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ B U C K E T && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
2011-12-12 17:24:58 +00:00
/* e x p a n d c u r r e n t h a s h */
2011-12-14 10:33:18 +00:00
a n s _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * o l d _ b u c k e t , * o l d _ h a s h _ b u c k e t s , * n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) * 2 ;
2011-12-22 16:50:20 +00:00
A L L O C _ B U C K E T S ( n e w _ h a s h _ b u c k e t s , n u m _ b u c k e t s ) ;
2011-12-14 10:33:18 +00:00
o l d _ h a s h _ b u c k e t s = H a s h _ b u c k e t s ( h a s h ) ;
o l d _ b u c k e t = o l d _ h a s h _ b u c k e t s + H a s h _ n u m _ b u c k e t s ( h a s h ) ;
2010-04-05 03:31:12 +01:00
do {
if ( * - - o l d _ b u c k e t ) {
c h a i n _ n o d e = * o l d _ b u c k e t ;
do {
2011-12-14 10:33:18 +00:00
b u c k e t = n e w _ h a s h _ b u c k e t s + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , n u m _ b u c k e t s ) ;
2010-04-05 03:31:12 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
}
2011-12-14 10:33:18 +00:00
} while ( o l d _ b u c k e t ! = o l d _ h a s h _ b u c k e t s ) ;
H a s h _ b u c k e t s ( h a s h ) = n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
H a s h _ n u m _ b u c k e t s ( h a s h ) = n u m _ b u c k e t s ;
2011-12-22 16:50:20 +00:00
F R E E _ B U C K E T S ( o l d _ h a s h _ b u c k e t s ) ;
2010-04-05 03:31:12 +01:00
}
2011-11-15 16:57:51 +00:00
U N L O C K _ A N S W E R _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
}
2011-11-15 16:57:51 +00:00
# e n d i f /* A N S W E R _ T R I E _ L O C K _ L E V E L */
2010-04-05 03:31:12 +01:00
# e n d i f /* I N C L U D E _ A N S W E R _ T R I E _ C H E C K _ I N S E R T */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2010-04-15 01:09:59 +01:00
* * g l o b a l _ t r i e _ c h e c k _ i n s e r t _ ( gt ) _ e n t r y * *
2010-04-05 03:31:12 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def I N C L U D E _ G L O B A L _ T R I E _ C H E C K _ I N S E R T
2011-11-15 16:57:51 +00:00
# i f n def G L O B A L _ T R I E _ L O C K _ A T _ W R I T E _ L E V E L /* G L O B A L _ T R I E _ L O C K _ A T _ N O D E _ L E V E L | | ! Y A P O R */
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ E N T R Y
2012-05-14 19:11:58 +01:00
static i n l i n e g t _ n o d e _ p t r g l o b a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( g t _ n o d e _ p t r p a r e n t _ n o d e , Term t U S E S _ R E G S ) {
2010-04-05 03:31:12 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e g t _ n o d e _ p t r g l o b a l _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( g t _ n o d e _ p t r p a r e n t _ n o d e , Term t U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ E N T R Y */
2010-04-05 03:31:12 +01:00
g t _ n o d e _ p t r c h i l d _ n o d e ;
2011-11-15 16:57:51 +00:00
L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
c h i l d _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( c h i l d _ n o d e = = NULL ) {
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , NULL ) ;
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
2011-11-15 16:57:51 +00:00
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
if ( ! I S _ G L O B A L _ T R I E _ H A S H ( c h i l d _ n o d e ) ) {
int c o u n t _ n o d e s = 0 ;
do {
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
} while ( c h i l d _ n o d e ) ;
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ T R I E _ L E V E L ) {
/* a l l o c a n e w h a s h */
g t _ h a s h _ p t r h a s h ;
g t _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * b u c k e t ;
n e w _ g l o b a l _ t r i e _ h a s h ( h a s h , c o u n t _ n o d e s ) ;
c h a i n _ n o d e = c h i l d _ n o d e ;
do {
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , B A S E _ H A S H _ B U C K E T S ) ;
2010-04-05 03:31:12 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = ( g t _ n o d e _ p t r ) h a s h ;
} else {
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
}
2011-11-15 16:57:51 +00:00
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
{ / * t r i e n o d e s w i t h h a s h i n g * /
g t _ h a s h _ p t r h a s h ;
g t _ n o d e _ p t r * b u c k e t ;
int c o u n t _ n o d e s = 0 ;
h a s h = ( g t _ h a s h _ p t r ) c h i l d _ n o d e ;
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( t , H a s h _ n u m _ b u c k e t s ( h a s h ) ) ;
2010-04-05 03:31:12 +01:00
c h i l d _ n o d e = * b u c k e t ;
while ( c h i l d _ n o d e ) {
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t ) {
2011-11-15 16:57:51 +00:00
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
}
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , * b u c k e t ) ;
* b u c k e t = c h i l d _ n o d e ;
H a s h _ n u m _ n o d e s ( h a s h ) + + ;
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ B U C K E T && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* e x p a n d c u r r e n t h a s h */
2011-12-14 10:33:18 +00:00
g t _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * o l d _ b u c k e t , * o l d _ h a s h _ b u c k e t s , * n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
int n u m _ b u c k e t s ;
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) * 2 ;
2011-12-22 16:50:20 +00:00
A L L O C _ B U C K E T S ( n e w _ h a s h _ b u c k e t s , n u m _ b u c k e t s ) ;
2011-12-14 10:33:18 +00:00
o l d _ h a s h _ b u c k e t s = H a s h _ b u c k e t s ( h a s h ) ;
o l d _ b u c k e t = o l d _ h a s h _ b u c k e t s + H a s h _ n u m _ b u c k e t s ( h a s h ) ;
2010-04-05 03:31:12 +01:00
do {
if ( * - - o l d _ b u c k e t ) {
c h a i n _ n o d e = * o l d _ b u c k e t ;
do {
2011-12-14 10:33:18 +00:00
b u c k e t = n e w _ h a s h _ b u c k e t s + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , n u m _ b u c k e t s ) ;
2010-04-05 03:31:12 +01:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
}
2011-12-14 10:33:18 +00:00
} while ( o l d _ b u c k e t ! = o l d _ h a s h _ b u c k e t s ) ;
H a s h _ b u c k e t s ( h a s h ) = n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
H a s h _ n u m _ b u c k e t s ( h a s h ) = n u m _ b u c k e t s ;
2011-12-22 16:50:20 +00:00
F R E E _ B U C K E T S ( o l d _ h a s h _ b u c k e t s ) ;
2010-04-05 03:31:12 +01:00
}
2011-11-15 16:57:51 +00:00
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
2010-04-05 03:31:12 +01:00
return c h i l d _ n o d e ;
}
}
2011-11-15 16:57:51 +00:00
# else /* G L O B A L _ T R I E _ L O C K _ A T _ W R I T E _ L E V E L */
# i f def M O D E _ G L O B A L _ T R I E _ E N T R Y
2012-05-14 19:11:58 +01:00
static i n l i n e g t _ n o d e _ p t r g l o b a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( g t _ n o d e _ p t r p a r e n t _ n o d e , Term t U S E S _ R E G S ) {
2011-11-15 16:57:51 +00:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e g t _ n o d e _ p t r g l o b a l _ t r i e _ c h e c k _ i n s e r t _ e n t r y ( g t _ n o d e _ p t r p a r e n t _ n o d e , Term t U S E S _ R E G S ) {
2011-11-15 16:57:51 +00:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ E N T R Y */
g t _ n o d e _ p t r c h i l d _ n o d e ;
g t _ h a s h _ p t r h a s h ;
c h i l d _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( c h i l d _ n o d e = = NULL ) {
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , NULL ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
if ( T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) {
g t _ n o d e _ p t r c h a i n _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( I S _ G L O B A L _ T R I E _ H A S H ( c h a i n _ n o d e ) ) {
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
F R E E _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
h a s h = ( g t _ h a s h _ p t r ) c h a i n _ n o d e ;
g o t o g l o b a l _ t r i e _ h a s h ;
}
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
F R E E _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
return c h a i n _ n o d e ;
}
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ) ;
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
T r N o d e _ n e x t ( c h i l d _ n o d e ) = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
# else
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
} else {
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , NULL ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
}
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
return c h i l d _ n o d e ;
}
if ( ! I S _ G L O B A L _ T R I E _ H A S H ( c h i l d _ n o d e ) ) {
g t _ n o d e _ p t r f i r s t _ n o d e = c h i l d _ n o d e ;
int c o u n t _ n o d e s = 0 ;
do {
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t )
return c h i l d _ n o d e ;
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
} while ( c h i l d _ n o d e ) ;
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
if ( f i r s t _ n o d e ! = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) {
g t _ n o d e _ p t r c h a i n _ n o d e = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
if ( I S _ G L O B A L _ T R I E _ H A S H ( c h a i n _ n o d e ) ) {
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
F R E E _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
h a s h = ( g t _ h a s h _ p t r ) c h a i n _ n o d e ;
g o t o g l o b a l _ t r i e _ h a s h ;
}
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
F R E E _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
return c h a i n _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ! = f i r s t _ n o d e ) ;
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
T r N o d e _ n e x t ( c h i l d _ n o d e ) = T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ;
# else
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , T r N o d e _ c h i l d ( p a r e n t _ n o d e ) ) ;
} else {
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
}
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ T R I E _ L E V E L ) {
/* a l l o c a n e w h a s h */
g t _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * b u c k e t ;
2011-12-12 17:24:58 +00:00
n e w _ g l o b a l _ t r i e _ h a s h ( h a s h , c o u n t _ n o d e s ) ;
2011-11-15 16:57:51 +00:00
c h a i n _ n o d e = c h i l d _ n o d e ;
do {
2011-12-12 17:24:58 +00:00
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , B A S E _ H A S H _ B U C K E T S ) ;
2011-11-15 16:57:51 +00:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = ( g t _ n o d e _ p t r ) h a s h ;
} else {
T r N o d e _ c h i l d ( p a r e n t _ n o d e ) = c h i l d _ n o d e ;
}
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
return c h i l d _ n o d e ;
}
h a s h = ( g t _ h a s h _ p t r ) c h i l d _ n o d e ;
g l o b a l _ t r i e _ h a s h :
{ / * t r i e n o d e s w i t h h a s h i n g * /
g t _ n o d e _ p t r * b u c k e t , f i r s t _ n o d e ;
2011-12-12 17:24:58 +00:00
int n u m _ b u c k e t s , c o u n t _ n o d e s = 0 ;
2011-11-15 16:57:51 +00:00
2011-12-14 10:33:18 +00:00
do {
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) ;
// __sync_synchronize();
b u c k e t = H a s h _ b u c k e t s ( h a s h ) + H A S H _ E N T R Y ( t , n u m _ b u c k e t s ) ;
f i r s t _ n o d e = c h i l d _ n o d e = * b u c k e t ;
} while ( n u m _ b u c k e t s ! = H a s h _ n u m _ b u c k e t s ( h a s h ) ) ;
2011-11-15 16:57:51 +00:00
while ( c h i l d _ n o d e ) {
if ( T r N o d e _ e n t r y ( c h i l d _ n o d e ) = = t )
return c h i l d _ n o d e ;
c o u n t _ n o d e s + + ;
c h i l d _ n o d e = T r N o d e _ n e x t ( c h i l d _ n o d e ) ;
}
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
2011-12-12 17:24:58 +00:00
if ( n u m _ b u c k e t s ! = H a s h _ n u m _ b u c k e t s ( h a s h ) ) {
2011-11-15 16:57:51 +00:00
/* t h e h a s h h a s b e e n e x p a n d e d */
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
F R E E _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
g o t o g l o b a l _ t r i e _ h a s h ;
}
if ( f i r s t _ n o d e ! = * b u c k e t ) {
g t _ n o d e _ p t r c h a i n _ n o d e = * b u c k e t ;
do {
if ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) = = t ) {
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
F R E E _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
return c h a i n _ n o d e ;
}
c o u n t _ n o d e s + + ;
c h a i n _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
} while ( c h a i n _ n o d e ! = f i r s t _ n o d e ) ;
# i f def G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K
T r N o d e _ n e x t ( c h i l d _ n o d e ) = * b u c k e t ;
# else
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , * b u c k e t ) ;
} else {
N E W _ G L O B A L _ T R I E _ N O D E ( c h i l d _ n o d e , t , NULL , p a r e n t _ n o d e , f i r s t _ n o d e ) ;
# e n d i f /* G L O B A L _ T R I E _ A L L O C _ B E F O R E _ C H E C K */
}
* b u c k e t = c h i l d _ n o d e ;
H a s h _ n u m _ n o d e s ( h a s h ) + + ;
c o u n t _ n o d e s + + ;
if ( c o u n t _ n o d e s > = M A X _ N O D E S _ P E R _ B U C K E T && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* e x p a n d c u r r e n t h a s h */
2011-12-14 10:33:18 +00:00
g t _ n o d e _ p t r c h a i n _ n o d e , n e x t _ n o d e , * o l d _ b u c k e t , * o l d _ h a s h _ b u c k e t s , * n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
n u m _ b u c k e t s = H a s h _ n u m _ b u c k e t s ( h a s h ) * 2 ;
2011-12-22 16:50:20 +00:00
A L L O C _ B U C K E T S ( n e w _ h a s h _ b u c k e t s , n u m _ b u c k e t s ) ;
2011-12-14 10:33:18 +00:00
o l d _ h a s h _ b u c k e t s = H a s h _ b u c k e t s ( h a s h ) ;
o l d _ b u c k e t = o l d _ h a s h _ b u c k e t s + H a s h _ n u m _ b u c k e t s ( h a s h ) ;
2011-11-15 16:57:51 +00:00
do {
if ( * - - o l d _ b u c k e t ) {
c h a i n _ n o d e = * o l d _ b u c k e t ;
do {
2011-12-14 10:33:18 +00:00
b u c k e t = n e w _ h a s h _ b u c k e t s + H A S H _ E N T R Y ( T r N o d e _ e n t r y ( c h a i n _ n o d e ) , n u m _ b u c k e t s ) ;
2011-11-15 16:57:51 +00:00
n e x t _ n o d e = T r N o d e _ n e x t ( c h a i n _ n o d e ) ;
T r N o d e _ n e x t ( c h a i n _ n o d e ) = * b u c k e t ;
* b u c k e t = c h a i n _ n o d e ;
c h a i n _ n o d e = n e x t _ n o d e ;
} while ( c h a i n _ n o d e ) ;
}
2011-12-14 10:33:18 +00:00
} while ( o l d _ b u c k e t ! = o l d _ h a s h _ b u c k e t s ) ;
H a s h _ b u c k e t s ( h a s h ) = n e w _ h a s h _ b u c k e t s ;
2011-12-12 17:24:58 +00:00
H a s h _ n u m _ b u c k e t s ( h a s h ) = n u m _ b u c k e t s ;
2011-12-22 16:50:20 +00:00
F R E E _ B U C K E T S ( o l d _ h a s h _ b u c k e t s ) ;
2011-11-15 16:57:51 +00:00
}
U N L O C K _ G L O B A L _ N O D E ( p a r e n t _ n o d e ) ;
return c h i l d _ n o d e ;
}
}
# e n d i f /* G L O B A L _ T R I E _ L O C K _ L E V E L */
2010-04-05 03:31:12 +01:00
# e n d i f /* I N C L U D E _ G L O B A L _ T R I E _ C H E C K _ I N S E R T */
2010-04-15 01:09:59 +01:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2010-04-23 04:22:10 +01:00
* * s u b g o a l _ s e a r c h ( _ g l o b a l _ t r i e ) ( _ t e r m s ) _ l o o p * *
2010-04-15 01:09:59 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def I N C L U D E _ S U B G O A L _ S E A R C H _ L O O P
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
2010-04-23 04:22:10 +01:00
# i f def G L O B A L _ T R I E _ F O R _ S U B T E R M S
2012-05-14 19:11:58 +01:00
static i n l i n e g t _ n o d e _ p t r s u b g o a l _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( Term t , int * s u b s _ a r i t y _ p t r , C E L L * * s t a c k _ v a r s _ p t r , C E L L * s t a c k _ t e r m s U S E S _ R E G S ) {
2010-04-23 04:22:10 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e g t _ n o d e _ p t r s u b g o a l _ s e a r c h _ g l o b a l _ t r i e _ l o o p ( Term t , int * s u b s _ a r i t y _ p t r , C E L L * * s t a c k _ v a r s _ p t r U S E S _ R E G S ) {
2010-04-23 04:22:10 +01:00
# e n d i f /* G L O B A L _ T R I E _ F O R _ S U B T E R M S */
# else
# i f def M O D E _ T E R M S _ L O O P
2012-05-14 19:11:58 +01:00
static i n l i n e s g _ n o d e _ p t r s u b g o a l _ s e a r c h _ t e r m s _ l o o p ( t a b _ e n t _ p t r t a b _ e n t , s g _ n o d e _ p t r c u r r e n t _ n o d e , Term t , int * s u b s _ a r i t y _ p t r , C E L L * * s t a c k _ v a r s _ p t r U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e s g _ n o d e _ p t r s u b g o a l _ s e a r c h _ l o o p ( t a b _ e n t _ p t r t a b _ e n t , s g _ n o d e _ p t r c u r r e n t _ n o d e , Term t , int * s u b s _ a r i t y _ p t r , C E L L * * s t a c k _ v a r s _ p t r U S E S _ R E G S ) {
2010-04-23 04:22:10 +01:00
# e n d i f /* M O D E _ T E R M S _ L O O P */
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2011-05-25 18:50:54 +01:00
= = = = = = = = = = =
| |
| . . . |
| |
- - - - - - - - - - -
| V A R _ N | < - - s t a c k _ v a r s
- - - - - - - - - - - *
| . . . | / | \
- - - - - - - - - - - | s u b s _ a r i t y ( N + 1 )
| V A R _ 0 | \ | /
- - - - - - - - - - - *
Y E N V - - > | |
- - - - - - - - - - -
| |
| . . . |
| |
= = = = = = = = = = =
| |
| . . . |
| |
- - - - - - - - - - -
T R - - > | | < - - s t a c k _ t e r m s _ l i m i t
- - - - - - - - - - -
| |
| . . . |
| |
- - - - - - - - - - |
| T E R M _ N | < - - s t a c k _ t e r m s
- - - - - - - - - - | *
| . . . | / | \
- - - - - - - - - - | |
| T E R M _ 1 | |
- - - - - - - - - - | |
| NULL | \ | /
= = = = = = = = = = = *
2011-05-23 16:19:47 +01:00
L O C A L _ T r a i l T o p - - > | |
2011-05-25 18:50:54 +01:00
- - - - - - - - - - -
2010-04-15 01:09:59 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
2011-05-10 11:47:18 +01:00
g t _ n o d e _ p t r c u r r e n t _ n o d e = G L O B A L _ r o o t _ g t ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
int s u b s _ a r i t y = * s u b s _ a r i t y _ p t r ;
C E L L * s t a c k _ v a r s = * s t a c k _ v a r s _ p t r ;
2010-04-23 04:22:10 +01:00
# if ! defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) | | ! defined ( G L O B A L _ T R I E _ F O R _ S U B T E R M S )
2011-05-23 16:19:47 +01:00
C E L L * s t a c k _ t e r m s = ( C E L L * ) L O C A L _ T r a i l T o p ;
2010-04-15 01:09:59 +01:00
# e n d i f /* ! M O D E _ G L O B A L _ T R I E _ L O O P | | ! G L O B A L _ T R I E _ F O R _ S U B T E R M S */
C E L L * s t a c k _ t e r m s _ l i m i t = ( C E L L * ) T R ;
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 1 ) ; /* + 1 b e c a u s e i n i t i a l l y w e s t i i l h a v e n ' t d o n e a n y S T A C K _ P O P _ D O W N */
S T A C K _ P U S H _ U P ( NULL , s t a c k _ t e r m s ) ;
2010-04-23 04:22:10 +01:00
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P )
/* f o r t h e g l o b a l t r i e , i t i s s a f e t o s k i p t h e I s V a r T e r m ( ) a n d I s A t o m O r I n t T e r m ( ) t e s t s i n t h e f i r s t i t e r a t i o n */
g o t o s u b g o a l _ s e a r c h _ l o o p _ n o n _ a t o m i c ;
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
/* N e e d e d s t r u c t u r e s , v a r i a b l e s t o s u p p o r t r a t i o n a l t e r m s */
t e r m _ a r r a y T s ;
void * C y c l i c T e r m ;
t e r m _ a r r a y _ i n i t ( &Ts, 10);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
do {
if ( I s V a r T e r m ( t ) ) {
if ( I s T a b l e V a r T e r m ( t ) ) {
2013-12-19 10:56:52 +00:00
t = M a k e T a b l e V a r T e r m ( V a r I n d e x O f T e r m ( t ) ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , t ) ;
2010-04-15 01:09:59 +01:00
} else {
2013-12-19 10:56:52 +00:00
if ( s u b s _ a r i t y = = M A X _ T A B L E _ V A R S )
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , T e r m N i l , "subgoal_search_loop: MAX_TABLE_VARS exceeded" ) ;
S T A C K _ P U S H _ U P ( t , s t a c k _ v a r s ) ;
* ( ( C E L L * ) t ) = G L O B A L _ t a b l e _ v a r _ e n u m e r a t o r ( s u b s _ a r i t y ) ;
t = M a k e T a b l e V a r T e r m ( s u b s _ a r i t y ) ;
s u b s _ a r i t y = s u b s _ a r i t y + 1 ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , t ) ;
2010-04-15 01:09:59 +01:00
}
} else if ( I s A t o m O r I n t T e r m ( t ) ) {
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , t ) ;
2010-04-23 04:22:10 +01:00
# i f def M O D E _ T E R M S _ L O O P
2010-04-15 01:09:59 +01:00
} else {
g t _ n o d e _ p t r e n t r y _ n o d e ;
2010-04-23 04:22:10 +01:00
# i f def G L O B A L _ T R I E _ F O R _ S U B T E R M S
2012-05-14 19:11:58 +01:00
e n t r y _ n o d e = s u b g o a l _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( t , &subs_arity, &stack_vars, stack_terms PASS_REGS);
2010-04-23 04:22:10 +01:00
# else
2012-05-14 19:11:58 +01:00
e n t r y _ n o d e = s u b g o a l _ s e a r c h _ g l o b a l _ t r i e _ l o o p ( t , &subs_arity, &stack_vars PASS_REGS);
2010-04-23 04:22:10 +01:00
# e n d i f /* G L O B A L _ T R I E _ F O R _ S U B T E R M S */
2012-05-14 19:11:58 +01:00
c u r r e n t _ n o d e = s u b g o a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( t a b _ e n t , c u r r e n t _ n o d e , ( Term ) e n t r y _ n o d e P A S S _ R E G S ) ;
2010-04-23 04:22:10 +01:00
# else /* ! M O D E _ T E R M S _ L O O P */
} else
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s R a t i o n a l T e r m ( t ) ) {
t = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , t ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-23 04:22:10 +01:00
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P )
/* f o r t h e g l o b a l t r i e , i t i s s a f e t o s t a r t h e r e i n t h e f i r s t i t e r a t i o n */
s u b g o a l _ s e a r c h _ l o o p _ n o n _ a t o m i c :
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
2010-04-15 01:09:59 +01:00
# i f def T R I E _ C O M P A C T _ P A I R S
2010-04-23 04:22:10 +01:00
if ( I s P a i r T e r m ( t ) ) {
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = NULL ;
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
C E L L * a u x _ p a i r = R e p P a i r ( t ) ;
if ( a u x _ p a i r = = P a i r T e r m M a r k ) {
2013-12-19 10:56:52 +00:00
t = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s P a i r T e r m ( t ) && ! IsRationalTerm(t)) {
t e r m _ a r r a y _ p u s h ( &Ts, (void *) t, (void *) current_node);
# else
if ( I s P a i r T e r m ( t ) ) {
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
a u x _ p a i r = R e p P a i r ( t ) ;
t = D e r e f ( a u x _ p a i r [ 1 ] ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s V a r T e r m ( a u x _ p a i r [ 1 ] ) | | I s P a i r T e r m ( a u x _ p a i r [ 1 ] ) ) {
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) t ) ;
}
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( A b s P a i r ( P a i r T e r m M a r k ) , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
if ( t = = T e r m N i l ) {
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , C o m p a c t P a i r E n d L i s t ) ;
} else {
/* A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 2 ) ; */
/* A U X _ S T A C K _ C H E C K _ E X P A N D i s n o t n e c e s s a r y h e r e b e c a u s e t h e s i t u a t i o n o f p u s h i n g * *
* * up 3 t e r m s h a s a l r e a d y i n i t i a l l y checked for t h e C o m p a c t P a i r I n i t term * /
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( A b s P a i r ( P a i r T e r m M a r k ) , s t a c k _ t e r m s ) ;
}
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = NULL ;
if ( I s V a r T e r m ( a u x _ p a i r [ 0 ] ) | | I s P a i r T e r m ( a u x _ p a i r [ 0 ] ) )
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) D e r e f ( a u x _ p a i r [ 0 ] ) ) ;
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ p a i r [ 0 ] ) , s t a c k _ t e r m s ) ;
} else {
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , C o m p a c t P a i r E n d T e r m ) ;
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
}
2010-04-15 01:09:59 +01:00
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) && defined(GLOBAL_TRIE_FOR_SUBTERMS)
2011-05-10 11:47:18 +01:00
} else if ( c u r r e n t _ n o d e ! = G L O B A L _ r o o t _ g t ) {
2013-12-19 10:56:52 +00:00
g t _ n o d e _ p t r e n t r y _ n o d e = s u b g o a l _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( t , &subs_arity, &stack_vars, stack_terms PASS_REGS);
c u r r e n t _ n o d e = g l o b a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( c u r r e n t _ n o d e , ( Term ) e n t r y _ n o d e P A S S _ R E G S ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P & & G L O B A L _ T R I E _ F O R _ S U B T E R M S */
} else {
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y _ p u s h ( &Ts, (void *) t, (void *) current_node);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , C o m p a c t P a i r I n i t ) ;
t = D e r e f ( a u x _ p a i r [ 1 ] ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s V a r T e r m ( a u x _ p a i r [ 1 ] ) | | I s P a i r T e r m ( a u x _ p a i r [ 1 ] ) ) {
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) t ) ;
}
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( A b s P a i r ( P a i r T e r m M a r k ) , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
if ( t = = T e r m N i l ) {
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , C o m p a c t P a i r E n d L i s t ) ;
} else {
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 2 ) ;
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( A b s P a i r ( P a i r T e r m M a r k ) , s t a c k _ t e r m s ) ;
}
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = NULL ;
if ( I s V a r T e r m ( a u x _ p a i r [ 0 ] ) | | I s P a i r T e r m ( a u x _ p a i r [ 0 ] ) )
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) D e r e f ( a u x _ p a i r [ 0 ] ) ) ;
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ p a i r [ 0 ] ) , s t a c k _ t e r m s ) ;
2010-04-15 01:09:59 +01:00
}
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) && defined(GLOBAL_TRIE_FOR_SUBTERMS)
2011-05-10 11:47:18 +01:00
} else if ( c u r r e n t _ n o d e ! = G L O B A L _ r o o t _ g t ) {
2012-05-14 19:11:58 +01:00
g t _ n o d e _ p t r e n t r y _ n o d e = s u b g o a l _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( t , &subs_arity, &stack_vars, stack_terms PASS_REGS);
c u r r e n t _ n o d e = g l o b a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( c u r r e n t _ n o d e , ( Term ) e n t r y _ n o d e P A S S _ R E G S ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P & & G L O B A L _ T R I E _ F O R _ S U B T E R M S */
2010-04-23 04:22:10 +01:00
# else /* ! T R I E _ C O M P A C T _ P A I R S */
2010-04-15 01:09:59 +01:00
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) && defined(GLOBAL_TRIE_FOR_SUBTERMS)
2011-05-10 11:47:18 +01:00
if ( c u r r e n t _ n o d e ! = G L O B A L _ r o o t _ g t ) {
2012-05-14 19:11:58 +01:00
g t _ n o d e _ p t r e n t r y _ n o d e = s u b g o a l _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( t , &subs_arity, &stack_vars, stack_terms PASS_REGS);
c u r r e n t _ n o d e = g l o b a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( c u r r e n t _ n o d e , ( Term ) e n t r y _ n o d e P A S S _ R E G S ) ;
2010-04-23 04:22:10 +01:00
} else
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P & & G L O B A L _ T R I E _ F O R _ S U B T E R M S */
2010-04-23 04:22:10 +01:00
if ( I s P a i r T e r m ( t ) ) {
2010-04-15 01:09:59 +01:00
C E L L * a u x _ p a i r = R e p P a i r ( t ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , A b s P a i r ( NULL ) ) ;
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 1 ) ;
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ p a i r [ 1 ] ) , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ p a i r [ 0 ] ) , s t a c k _ t e r m s ) ;
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
} else if ( I s A p p l T e r m ( t ) ) {
F u n c t o r f = F u n c t o r O f T e r m ( t ) ;
if ( f = = F u n c t o r D o u b l e ) {
2013-12-19 10:56:52 +00:00
union {
Term t _ d b l [ s i z e o f ( Float ) / s i z e o f ( Term ) ] ;
Float d b l ;
} u ;
u . d b l = F l o a t O f T e r m ( t ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) ) ;
2010-04-15 01:09:59 +01:00
# if S I Z E O F _ D O U B L E = = 2 * S I Z E O F _ I N T _ P
2013-12-19 10:56:52 +00:00
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , u . t _ d b l [ 1 ] ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* S I Z E O F _ D O U B L E x S I Z E O F _ I N T _ P */
2013-12-19 10:56:52 +00:00
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , u . t _ d b l [ 0 ] ) ;
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
2013-12-19 10:56:52 +00:00
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
} else if ( f = = F u n c t o r L o n g I n t ) {
2013-12-19 10:56:52 +00:00
Int l i = L o n g I n t O f T e r m ( t ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , l i ) ;
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
2013-12-19 10:56:52 +00:00
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
2014-01-17 09:39:29 +00:00
} else if ( f = = F u n c t o r B i g I n t | | f = = F u n c t o r S t r i n g ) {
C E L L * new = Y a p _ H e a p S t o r e O p a q u e T e r m ( t ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , ( C E L L ) new ) ;
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) ) ;
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
2010-04-15 01:09:59 +01:00
} else if ( f = = F u n c t o r D B R e f ) {
2010-04-23 04:22:10 +01:00
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , T e r m N i l , "subgoal_search_loop: unsupported type tag FunctorDBRef" ) ;
2010-04-15 01:09:59 +01:00
} else {
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y _ p u s h ( &Ts, (void *) t, (void *) current_node);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
int i ;
C E L L * a u x _ a p p l = R e p A p p l ( t ) ;
S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y ( t a b _ e n t , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) ) ;
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + A r i t y O f F u n c t o r ( f ) - 1 ) ;
for ( i = A r i t y O f F u n c t o r ( f ) ; i > = 1 ; i - - ) {
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = NULL ;
if ( I s V a r T e r m ( a u x _ a p p l [ i ] ) | | I s A p p l T e r m ( a u x _ a p p l [ i ] ) )
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) D e r e f ( a u x _ a p p l [ i ] ) ) ;
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ a p p l [ i ] ) , s t a c k _ t e r m s ) ;
}
2010-04-15 01:09:59 +01:00
}
} else {
2010-04-23 04:22:10 +01:00
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , T e r m N i l , "subgoal_search_loop: unknown type tag" ) ;
# e n d i f /* M O D E _ T E R M S _ L O O P */
2010-04-15 01:09:59 +01:00
}
t = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
} while ( t ) ;
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y _ f r e e ( &Ts);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
* s u b s _ a r i t y _ p t r = s u b s _ a r i t y ;
* s t a c k _ v a r s _ p t r = s t a c k _ v a r s ;
return c u r r e n t _ n o d e ;
}
# e n d i f /* I N C L U D E _ S U B G O A L _ S E A R C H _ L O O P */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2010-04-23 04:22:10 +01:00
* * a n s w e r _ s e a r c h ( _ g l o b a l _ t r i e ) ( _ t e r m s ) _ l o o p * *
2010-04-15 01:09:59 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def I N C L U D E _ A N S W E R _ S E A R C H _ L O O P
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
2010-04-23 04:22:10 +01:00
# i f def G L O B A L _ T R I E _ F O R _ S U B T E R M S
2012-05-14 19:11:58 +01:00
static i n l i n e g t _ n o d e _ p t r a n s w e r _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( Term t , int * v a r s _ a r i t y _ p t r , C E L L * s t a c k _ t e r m s U S E S _ R E G S ) {
2010-04-23 04:22:10 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e g t _ n o d e _ p t r a n s w e r _ s e a r c h _ g l o b a l _ t r i e _ l o o p ( Term t , int * v a r s _ a r i t y _ p t r U S E S _ R E G S ) {
2010-04-23 04:22:10 +01:00
# e n d i f /* G L O B A L _ T R I E _ F O R _ S U B T E R M S */
# else
# i f def M O D E _ T E R M S _ L O O P
2012-05-14 19:11:58 +01:00
static i n l i n e a n s _ n o d e _ p t r a n s w e r _ s e a r c h _ t e r m s _ l o o p ( s g _ f r _ p t r s g _ f r , a n s _ n o d e _ p t r c u r r e n t _ n o d e , Term t , int * v a r s _ a r i t y _ p t r U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e a n s _ n o d e _ p t r a n s w e r _ s e a r c h _ l o o p ( s g _ f r _ p t r s g _ f r , a n s _ n o d e _ p t r c u r r e n t _ n o d e , Term t , int * v a r s _ a r i t y _ p t r U S E S _ R E G S ) {
2010-04-23 04:22:10 +01:00
# e n d i f /* M O D E _ T E R M S _ L O O P */
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2011-05-25 18:50:54 +01:00
= = = = = = = = = = =
| |
| . . . |
| |
- - - - - - - - - - -
T R - - > | V A R _ 0 | < - - s t a c k _ v a r s _ b a s e
- - - - - - - - - - - *
| . . . | / | \
- - - - - - - - - - - | v a r s _ a r i t y ( N + 1 )
| V A R _ N | \ | /
- - - - - - - - - - - *
| | < - - s t a c k _ t e r m s _ l i m i t
- - - - - - - - - - -
| |
| . . . |
| |
- - - - - - - - - - |
| T E R M _ N | < - - s t a c k _ t e r m s
- - - - - - - - - - | *
| . . . | / | \
- - - - - - - - - - | |
| T E R M _ 1 | |
- - - - - - - - - - | |
| NULL | \ | /
= = = = = = = = = = = *
2011-05-23 16:19:47 +01:00
L O C A L _ T r a i l T o p - - > | |
2011-05-25 18:50:54 +01:00
- - - - - - - - - - -
2010-04-15 01:09:59 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
2011-05-10 11:47:18 +01:00
g t _ n o d e _ p t r c u r r e n t _ n o d e = G L O B A L _ r o o t _ g t ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
int v a r s _ a r i t y = * v a r s _ a r i t y _ p t r ;
2010-04-23 04:22:10 +01:00
# if ! defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) | | ! defined ( G L O B A L _ T R I E _ F O R _ S U B T E R M S )
2011-05-23 16:19:47 +01:00
C E L L * s t a c k _ t e r m s = ( C E L L * ) L O C A L _ T r a i l T o p ;
2010-04-15 01:09:59 +01:00
# e n d i f /* ! M O D E _ G L O B A L _ T R I E _ L O O P | | ! G L O B A L _ T R I E _ F O R _ S U B T E R M S */
C E L L * s t a c k _ v a r s _ b a s e = ( C E L L * ) T R ;
# define s t a c k _ t e r m s _ l i m i t ( s t a c k _ v a r s _ b a s e + v a r s _ a r i t y )
# i f def T R I E _ C O M P A C T _ P A I R S
int i n _ p a i r = 0 ;
# else
# define i n _ p a i r 0
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 1 ) ; /* + 1 b e c a u s e i n i t i a l l y w e s t i i l h a v e n ' t d o n e a n y S T A C K _ P O P _ D O W N */
S T A C K _ P U S H _ U P ( NULL , s t a c k _ t e r m s ) ;
2010-04-23 04:22:10 +01:00
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P )
/* f o r t h e g l o b a l t r i e , i t i s s a f e t o s k i p t h e I s V a r T e r m ( ) a n d I s A t o m O r I n t T e r m ( ) t e s t s i n t h e f i r s t i t e r a t i o n */
g o t o a n s w e r _ s e a r c h _ l o o p _ n o n _ a t o m i c ;
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y T s ;
void * C y c l i c T e r m ;
t e r m _ a r r a y _ i n i t ( &Ts, 10);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
do {
if ( I s V a r T e r m ( t ) ) {
t = D e r e f ( t ) ;
if ( I s T a b l e V a r T e r m ( t ) ) {
2013-12-19 10:56:52 +00:00
t = M a k e T a b l e V a r T e r m ( V a r I n d e x O f T e r m ( t ) ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , t , _ t r i e _ r e t r y _ v a l + i n _ p a i r ) ;
2010-04-15 01:09:59 +01:00
} else {
2013-12-19 10:56:52 +00:00
if ( v a r s _ a r i t y = = M A X _ T A B L E _ V A R S )
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , T e r m N i l , "answer_search_loop: MAX_TABLE_VARS exceeded" ) ;
s t a c k _ v a r s _ b a s e [ v a r s _ a r i t y ] = t ;
* ( ( C E L L * ) t ) = G L O B A L _ t a b l e _ v a r _ e n u m e r a t o r ( v a r s _ a r i t y ) ;
t = M a k e T a b l e V a r T e r m ( v a r s _ a r i t y ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , t , _ t r i e _ r e t r y _ v a r + i n _ p a i r ) ;
v a r s _ a r i t y = v a r s _ a r i t y + 1 ;
2010-04-15 01:09:59 +01:00
}
# i f def T R I E _ C O M P A C T _ P A I R S
i n _ p a i r = 0 ;
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
} else if ( I s A t o m O r I n t T e r m ( t ) ) {
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , t , _ t r i e _ r e t r y _ a t o m + i n _ p a i r ) ;
2010-04-23 04:22:10 +01:00
# i f def T R I E _ C O M P A C T _ P A I R S
i n _ p a i r = 0 ;
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
# i f def M O D E _ T E R M S _ L O O P
2010-04-15 01:09:59 +01:00
} else {
g t _ n o d e _ p t r e n t r y _ n o d e ;
2010-04-23 04:22:10 +01:00
# i f def G L O B A L _ T R I E _ F O R _ S U B T E R M S
2012-05-14 19:11:58 +01:00
e n t r y _ n o d e = a n s w e r _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( t , &vars_arity, stack_terms PASS_REGS);
2010-04-23 04:22:10 +01:00
# else
2012-05-14 19:11:58 +01:00
e n t r y _ n o d e = a n s w e r _ s e a r c h _ g l o b a l _ t r i e _ l o o p ( t , &vars_arity PASS_REGS);
2010-04-23 04:22:10 +01:00
# e n d i f /* G L O B A L _ T R I E _ F O R _ S U B T E R M S */
2012-05-14 19:11:58 +01:00
c u r r e n t _ n o d e = a n s w e r _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( s g _ f r , c u r r e n t _ n o d e , ( Term ) e n t r y _ n o d e , _ t r i e _ r e t r y _ g t e r m + i n _ p a i r P A S S _ R E G S ) ;
2010-04-23 04:22:10 +01:00
# else /* ! M O D E _ T E R M S _ L O O P */
2013-12-19 10:56:52 +00:00
} else
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s R a t i o n a l T e r m ( t ) ) {
t = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , t , _ t r i e _ r e t r y _ v a r + i n _ p a i r ) ; //TODO create _trie_.._rational
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-23 04:22:10 +01:00
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P )
/* f o r t h e g l o b a l t r i e , i t i s s a f e t o s t a r t h e r e i n t h e f i r s t i t e r a t i o n */
a n s w e r _ s e a r c h _ l o o p _ n o n _ a t o m i c :
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
2010-04-15 01:09:59 +01:00
# i f def T R I E _ C O M P A C T _ P A I R S
2010-04-23 04:22:10 +01:00
if ( I s P a i r T e r m ( t ) ) {
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = NULL ;
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
C E L L * a u x _ p a i r = R e p P a i r ( t ) ;
if ( a u x _ p a i r = = P a i r T e r m M a r k ) {
2013-12-19 10:56:52 +00:00
t = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s P a i r T e r m ( t ) && ! IsRationalTerm(t)) {
t e r m _ a r r a y _ p u s h ( &Ts, (void *) t, (void *) current_node);
# else
if ( I s P a i r T e r m ( t ) ) {
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
a u x _ p a i r = R e p P a i r ( t ) ;
t = D e r e f ( a u x _ p a i r [ 1 ] ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s V a r T e r m ( a u x _ p a i r [ 1 ] ) | | I s P a i r T e r m ( a u x _ p a i r [ 1 ] ) ) {
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) t ) ;
}
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ; // CyclicTerm
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( A b s P a i r ( P a i r T e r m M a r k ) , s t a c k _ t e r m s ) ;
i n _ p a i r = 4 ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
if ( t = = T e r m N i l ) {
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , C o m p a c t P a i r E n d L i s t , _ t r i e _ r e t r y _ p a i r ) ;
} else {
/* A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 2 ) ; */
/* A U X _ S T A C K _ C H E C K _ E X P A N D i s n o t n e c e s s a r y h e r e b e c a u s e t h e s i t u a t i o n o f p u s h i n g * *
* * up 3 t e r m s h a s a l r e a d y i n i t i a l l y checked for t h e C o m p a c t P a i r I n i t term * /
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( A b s P a i r ( P a i r T e r m M a r k ) , s t a c k _ t e r m s ) ;
i n _ p a i r = 4 ;
}
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = NULL ;
if ( I s V a r T e r m ( a u x _ p a i r [ 0 ] ) | | I s P a i r T e r m ( a u x _ p a i r [ 0 ] ) )
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) D e r e f ( a u x _ p a i r [ 0 ] ) ) ;
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ p a i r [ 0 ] ) , s t a c k _ t e r m s ) ;
} else {
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , C o m p a c t P a i r E n d T e r m , _ t r i e _ r e t r y _ n u l l ) ;
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
}
2010-04-15 01:09:59 +01:00
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) && defined(GLOBAL_TRIE_FOR_SUBTERMS)
2011-05-10 11:47:18 +01:00
} else if ( c u r r e n t _ n o d e ! = G L O B A L _ r o o t _ g t ) {
2013-12-19 10:56:52 +00:00
g t _ n o d e _ p t r e n t r y _ n o d e = a n s w e r _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( t , &vars_arity, stack_terms PASS_REGS);
c u r r e n t _ n o d e = g l o b a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( c u r r e n t _ n o d e , ( Term ) e n t r y _ n o d e P A S S _ R E G S ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P & & G L O B A L _ T R I E _ F O R _ S U B T E R M S */
} else {
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y _ p u s h ( &Ts, (void *) t, (void *) current_node);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , C o m p a c t P a i r I n i t , _ t r i e _ r e t r y _ n u l l + i n _ p a i r ) ;
t = D e r e f ( a u x _ p a i r [ 1 ] ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s V a r T e r m ( a u x _ p a i r [ 1 ] ) | | I s P a i r T e r m ( a u x _ p a i r [ 1 ] ) ) {
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) t ) ;
}
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( A b s P a i r ( P a i r T e r m M a r k ) , s t a c k _ t e r m s ) ;
i n _ p a i r = 4 ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
if ( t = = T e r m N i l ) {
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , C o m p a c t P a i r E n d L i s t , _ t r i e _ r e t r y _ p a i r ) ;
i n _ p a i r = 0 ;
} else {
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 2 ) ;
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( A b s P a i r ( P a i r T e r m M a r k ) , s t a c k _ t e r m s ) ;
i n _ p a i r = 4 ;
}
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = NULL ;
if ( I s V a r T e r m ( a u x _ p a i r [ 0 ] ) | | I s P a i r T e r m ( a u x _ p a i r [ 0 ] ) )
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) D e r e f ( a u x _ p a i r [ 0 ] ) ) ;
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ p a i r [ 0 ] ) , s t a c k _ t e r m s ) ;
2010-04-15 01:09:59 +01:00
}
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) && defined(GLOBAL_TRIE_FOR_SUBTERMS)
2011-05-10 11:47:18 +01:00
} else if ( c u r r e n t _ n o d e ! = G L O B A L _ r o o t _ g t ) {
2012-05-14 19:11:58 +01:00
g t _ n o d e _ p t r e n t r y _ n o d e = a n s w e r _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( t , &vars_arity, stack_terms PASS_REGS);
c u r r e n t _ n o d e = g l o b a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( c u r r e n t _ n o d e , ( Term ) e n t r y _ n o d e P A S S _ R E G S ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P & & G L O B A L _ T R I E _ F O R _ S U B T E R M S */
2010-04-23 04:22:10 +01:00
# else /* ! T R I E _ C O M P A C T _ P A I R S */
2010-04-15 01:09:59 +01:00
# if defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) && defined(GLOBAL_TRIE_FOR_SUBTERMS)
2011-05-10 11:47:18 +01:00
if ( c u r r e n t _ n o d e ! = G L O B A L _ r o o t _ g t ) {
2012-05-14 19:11:58 +01:00
g t _ n o d e _ p t r e n t r y _ n o d e = a n s w e r _ s e a r c h _ g l o b a l _ t r i e _ t e r m s _ l o o p ( t , &vars_arity, stack_terms PASS_REGS);
c u r r e n t _ n o d e = g l o b a l _ t r i e _ c h e c k _ i n s e r t _ g t _ e n t r y ( c u r r e n t _ n o d e , ( Term ) e n t r y _ n o d e P A S S _ R E G S ) ;
2010-04-23 04:22:10 +01:00
} else
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P & & G L O B A L _ T R I E _ F O R _ S U B T E R M S */
2010-04-23 04:22:10 +01:00
if ( I s P a i r T e r m ( t ) ) {
2010-04-15 01:09:59 +01:00
C E L L * a u x _ p a i r = R e p P a i r ( t ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , A b s P a i r ( NULL ) , _ t r i e _ r e t r y _ p a i r ) ;
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 1 ) ;
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ p a i r [ 1 ] ) , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ p a i r [ 0 ] ) , s t a c k _ t e r m s ) ;
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
} else if ( I s A p p l T e r m ( t ) ) {
F u n c t o r f = F u n c t o r O f T e r m ( t ) ;
if ( f = = F u n c t o r D o u b l e ) {
2013-12-19 10:56:52 +00:00
union {
Term t _ d b l [ s i z e o f ( Float ) / s i z e o f ( Term ) ] ;
Float d b l ;
} u ;
u . d b l = F l o a t O f T e r m ( t ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l + i n _ p a i r ) ;
2010-04-15 01:09:59 +01:00
# if S I Z E O F _ D O U B L E = = 2 * S I Z E O F _ I N T _ P
2013-12-19 10:56:52 +00:00
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , u . t _ d b l [ 1 ] , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* S I Z E O F _ D O U B L E x S I Z E O F _ I N T _ P */
2013-12-19 10:56:52 +00:00
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , u . t _ d b l [ 0 ] , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ d o u b l e ) ;
2010-04-15 01:09:59 +01:00
} else if ( f = = F u n c t o r L o n g I n t ) {
Int l i = L o n g I n t O f T e r m ( t ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l + i n _ p a i r ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , l i , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ l o n g i n t ) ;
2014-01-17 09:39:29 +00:00
} else if ( f = = F u n c t o r B i g I n t | | F u n c t o r S t r i n g ) {
C E L L * o p q = Y a p _ H e a p S t o r e O p a q u e T e r m ( t ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l + i n _ p a i r ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , ( C E L L ) o p q , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ b i g i n t ) ;
2010-04-15 01:09:59 +01:00
} else if ( f = = F u n c t o r D B R e f ) {
2010-04-23 04:22:10 +01:00
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , T e r m N i l , "answer_search_loop: unsupported type tag FunctorDBRef" ) ;
2010-04-15 01:09:59 +01:00
} else {
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y _ p u s h ( &Ts, (void *) t, (void *) current_node);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
int i ;
C E L L * a u x _ a p p l = R e p A p p l ( t ) ;
A N S W E R _ C H E C K _ I N S E R T _ E N T R Y ( s g _ f r , c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ a p p l + i n _ p a i r ) ;
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + A r i t y O f F u n c t o r ( f ) - 1 ) ;
for ( i = A r i t y O f F u n c t o r ( f ) ; i > = 1 ; i - - ) {
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = NULL ;
if ( I s V a r T e r m ( a u x _ a p p l [ i ] ) | | I s A p p l T e r m ( a u x _ a p p l [ i ] ) )
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) D e r e f ( a u x _ a p p l [ i ] ) ) ;
if ( C y c l i c T e r m ! = NULL ) {
S T A C K _ P U S H _ U P ( ( Term ) C y c l i c T e r m , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S T A C K _ P U S H _ U P ( D e r e f ( a u x _ a p p l [ i ] ) , s t a c k _ t e r m s ) ;
}
2010-04-15 01:09:59 +01:00
}
# i f def T R I E _ C O M P A C T _ P A I R S
i n _ p a i r = 0 ;
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
} else {
2010-04-23 04:22:10 +01:00
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , T e r m N i l , "answer_search_loop: unknown type tag" ) ;
# e n d i f /* M O D E _ T E R M S _ L O O P */
2010-04-15 01:09:59 +01:00
}
t = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
} while ( t ) ;
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y _ f r e e ( &Ts);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
* v a r s _ a r i t y _ p t r = v a r s _ a r i t y ;
return c u r r e n t _ n o d e ;
# u n def s t a c k _ t e r m s _ l i m i t
# i f n def T R I E _ C O M P A C T _ P A I R S
# u n def i n _ p a i r
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
}
2011-11-15 16:57:51 +00:00
# e n d i f /* I N C L U D E _ A N S W E R _ S E A R C H _ L O O P */
2011-11-09 11:00:31 +00:00
2011-11-15 16:57:51 +00:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * a n s w e r _ s e a r c h _ m i n _ m a x * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2011-11-09 11:00:31 +00:00
2011-11-15 16:57:51 +00:00
# i f def I N C L U D E _ A N S W E R _ S E A R C H _ M O D E _ D I R E C T E D
2012-05-14 19:11:58 +01:00
static i n l i n e a n s _ n o d e _ p t r a n s w e r _ s e a r c h _ m i n _ m a x ( s g _ f r _ p t r s g _ f r , a n s _ n o d e _ p t r c u r r e n t _ n o d e , Term t , int m o d e U S E S _ R E G S ) {
2011-11-09 11:00:31 +00:00
a n s _ n o d e _ p t r c h i l d _ n o d e ;
Term c h i l d _ t e r m ;
2014-01-17 09:39:29 +00:00
Term t r i e _ v a l u e = 0 , t e r m _ v a l u e = t ;
int c m p ;
2011-11-09 11:00:31 +00:00
/* s t a r t b y c o m p u t i n g t h e c u r r e n t v a l u e o n t h e t r i e ( t r i e _ v a l u e ) */
c h i l d _ n o d e = T r N o d e _ c h i l d ( c u r r e n t _ n o d e ) ;
c h i l d _ t e r m = T r N o d e _ e n t r y ( c h i l d _ n o d e ) ;
if ( I s I n t T e r m ( c h i l d _ t e r m ) ) {
2014-01-17 09:39:29 +00:00
t r i e _ v a l u e = c h i l d _ t e r m ;
2011-11-09 11:00:31 +00:00
} else if ( I s A p p l T e r m ( c h i l d _ t e r m ) ) {
2011-11-09 12:03:09 +00:00
F u n c t o r f = ( F u n c t o r ) R e p A p p l ( c h i l d _ t e r m ) ;
2011-11-09 11:00:31 +00:00
c h i l d _ n o d e = T r N o d e _ c h i l d ( c h i l d _ n o d e ) ;
if ( f = = F u n c t o r L o n g I n t ) {
2014-01-17 09:39:29 +00:00
t r i e _ v a l u e = M k L o n g I n t T e r m ( ( Int ) T r N o d e _ e n t r y ( c h i l d _ n o d e ) ) ;
2011-11-09 11:00:31 +00:00
} else if ( f = = F u n c t o r D o u b l e ) {
union {
2013-12-19 10:56:52 +00:00
Term t _ d b l [ s i z e o f ( Float ) / s i z e o f ( Term ) ] ;
Float d b l ;
2011-11-09 11:00:31 +00:00
} u ;
u . t _ d b l [ 0 ] = T r N o d e _ e n t r y ( c h i l d _ n o d e ) ;
# if S I Z E O F _ D O U B L E = = 2 * S I Z E O F _ I N T _ P
c h i l d _ n o d e = T r N o d e _ c h i l d ( c h i l d _ n o d e ) ;
u . t _ d b l [ 1 ] = T r N o d e _ e n t r y ( c h i l d _ n o d e ) ;
# e n d i f /* S I Z E O F _ D O U B L E x S I Z E O F _ I N T _ P */
2014-01-17 09:39:29 +00:00
t r i e _ v a l u e = M k F l o a t T e r m ( u . d b l ) ;
} else if ( f = = F u n c t o r B i g I n t ) {
t r i e _ v a l u e = A b s A p p l ( ( C E L L * ) T r N o d e _ e n t r y ( c h i l d _ n o d e ) ) ;
2011-11-09 11:00:31 +00:00
} else
2011-11-15 16:57:51 +00:00
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , T e r m N i l , "answer_search_min_max: invalid arithmetic value" ) ;
2011-11-09 11:00:31 +00:00
c h i l d _ n o d e = T r N o d e _ c h i l d ( c h i l d _ n o d e ) ;
}
2014-01-17 09:39:29 +00:00
c m p = Y a p _ a c m p ( t e r m _ v a l u e , t r i e _ v a l u e P A S S _ R E G S ) ;
2011-11-09 11:00:31 +00:00
/* w o r s e a n s w e r */
2014-01-17 09:39:29 +00:00
if ( ( m o d e = = M O D E _ D I R E C T E D _ M I N && cmp > 0) || (mode == MODE_DIRECTED_MAX && cmp < 0))
2011-11-09 11:00:31 +00:00
return NULL ;
/* e q u a l a n s w e r */
2014-01-17 09:39:29 +00:00
if ( c m p = = 0 )
2011-11-09 11:00:31 +00:00
return c h i l d _ n o d e ;
/* b e t t e r a n s w e r */
if ( I s A t o m O r I n t T e r m ( t ) ) {
2011-11-11 18:05:24 +00:00
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , t , _ t r i e _ r e t r y _ a t o m ) ;
2011-11-09 11:00:31 +00:00
} else if ( I s A p p l T e r m ( t ) ) {
F u n c t o r f = F u n c t o r O f T e r m ( t ) ;
if ( f = = F u n c t o r D o u b l e ) {
union {
2013-12-19 10:56:52 +00:00
Term t _ d b l [ s i z e o f ( Float ) / s i z e o f ( Term ) ] ;
Float d b l ;
2011-11-09 11:00:31 +00:00
} u ;
u . d b l = F l o a t O f T e r m ( t ) ;
2011-11-11 18:05:24 +00:00
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l ) ;
2011-11-09 11:00:31 +00:00
# if S I Z E O F _ D O U B L E = = 2 * S I Z E O F _ I N T _ P
2011-11-11 18:05:24 +00:00
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , u . t _ d b l [ 1 ] , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
2011-11-09 11:00:31 +00:00
# e n d i f /* S I Z E O F _ D O U B L E x S I Z E O F _ I N T _ P */
2011-11-11 18:05:24 +00:00
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , u . t _ d b l [ 0 ] , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ d o u b l e ) ;
2011-11-09 11:00:31 +00:00
} else if ( f = = F u n c t o r L o n g I n t ) {
Int l i = L o n g I n t O f T e r m ( t ) ;
2011-11-11 18:05:24 +00:00
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , l i , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ l o n g i n t ) ;
2014-01-17 09:39:29 +00:00
} else if ( f = = F u n c t o r B i g I n t ) {
C E L L * l i = Y a p _ H e a p S t o r e O p a q u e T e r m ( t ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , ( C E L L ) l i , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ b i g i n t ) ;
2011-11-09 11:00:31 +00:00
}
}
return c u r r e n t _ n o d e ;
}
2011-11-15 16:57:51 +00:00
# e n d i f /* I N C L U D E _ A N S W E R _ S E A R C H _ M O D E _ D I R E C T E D */
2011-11-09 11:00:31 +00:00
2012-06-04 19:27:31 +01:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * a n s w e r _ s e a r c h _ s u m * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def I N C L U D E _ A N S W E R _ S E A R C H _ M O D E _ D I R E C T E D
static i n l i n e a n s _ n o d e _ p t r a n s w e r _ s e a r c h _ s u m ( s g _ f r _ p t r s g _ f r , a n s _ n o d e _ p t r c u r r e n t _ n o d e , Term t U S E S _ R E G S ) {
a n s _ n o d e _ p t r c h i l d _ n o d e ;
Term c h i l d _ t e r m ;
2014-01-17 09:39:29 +00:00
Term t r i e _ v a l u e = 0 , t e r m _ v a l u e = t , s u m _ v a l u e = 0 ;
2012-06-04 19:27:31 +01:00
/* s t a r t b y c o m p u t i n g t h e c u r r e n t v a l u e o n t h e t r i e ( t r i e _ v a l u e ) */
c h i l d _ n o d e = T r N o d e _ c h i l d ( c u r r e n t _ n o d e ) ;
c h i l d _ t e r m = T r N o d e _ e n t r y ( c h i l d _ n o d e ) ;
if ( I s I n t T e r m ( c h i l d _ t e r m ) ) {
2014-01-17 09:39:29 +00:00
t r i e _ v a l u e = c h i l d _ t e r m ;
2012-06-04 19:27:31 +01:00
} else if ( I s A p p l T e r m ( c h i l d _ t e r m ) ) {
F u n c t o r f = ( F u n c t o r ) R e p A p p l ( c h i l d _ t e r m ) ;
c h i l d _ n o d e = T r N o d e _ c h i l d ( c h i l d _ n o d e ) ;
if ( f = = F u n c t o r L o n g I n t ) {
2014-01-17 09:39:29 +00:00
t r i e _ v a l u e = M k L o n g I n t T e r m ( ( Int ) T r N o d e _ e n t r y ( c h i l d _ n o d e ) ) ;
2012-06-04 19:27:31 +01:00
} else if ( f = = F u n c t o r D o u b l e ) {
union {
2013-12-19 10:56:52 +00:00
Term t _ d b l [ s i z e o f ( Float ) / s i z e o f ( Term ) ] ;
Float d b l ;
2012-06-04 19:27:31 +01:00
} u ;
u . t _ d b l [ 0 ] = T r N o d e _ e n t r y ( c h i l d _ n o d e ) ;
# if S I Z E O F _ D O U B L E = = 2 * S I Z E O F _ I N T _ P
c h i l d _ n o d e = T r N o d e _ c h i l d ( c h i l d _ n o d e ) ;
u . t _ d b l [ 1 ] = T r N o d e _ e n t r y ( c h i l d _ n o d e ) ;
# e n d i f /* S I Z E O F _ D O U B L E x S I Z E O F _ I N T _ P */
2014-01-17 09:39:29 +00:00
t r i e _ v a l u e = M k F l o a t T e r m ( u . d b l ) ;
} else if ( f = = F u n c t o r B i g I n t ) {
t r i e _ v a l u e = A b s A p p l ( ( C E L L * ) T r N o d e _ e n t r y ( c h i l d _ n o d e ) ) ;
2012-06-04 19:27:31 +01:00
} else
2014-01-17 09:39:29 +00:00
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , T e r m N i l , "answer_search_min_max: invalid arithmetic value" ) ;
2012-06-04 19:27:31 +01:00
c h i l d _ n o d e = T r N o d e _ c h i l d ( c h i l d _ n o d e ) ;
}
2014-01-17 09:39:29 +00:00
s u m _ v a l u e = p _ p l u s ( t r i e _ v a l u e , t e r m _ v a l u e P A S S _ R E G S ) ;
if ( I s A t o m O r I n t T e r m ( s u m _ v a l u e ) ) {
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , s u m _ v a l u e , _ t r i e _ r e t r y _ a t o m ) ;
} else if ( I s A p p l T e r m ( s u m _ v a l u e ) ) {
F u n c t o r f = F u n c t o r O f T e r m ( s u m _ v a l u e ) ;
if ( f = = F u n c t o r D o u b l e ) {
union {
Term t _ d b l [ s i z e o f ( Float ) / s i z e o f ( Term ) ] ;
Float d b l ;
} u ;
u . d b l = F l o a t O f T e r m ( s u m _ v a l u e ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l ) ;
2012-06-04 19:27:31 +01:00
# if S I Z E O F _ D O U B L E = = 2 * S I Z E O F _ I N T _ P
2014-01-17 09:39:29 +00:00
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , u . t _ d b l [ 1 ] , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
2012-06-04 19:27:31 +01:00
# e n d i f /* S I Z E O F _ D O U B L E x S I Z E O F _ I N T _ P */
2014-01-17 09:39:29 +00:00
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , u . t _ d b l [ 0 ] , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ d o u b l e ) ;
} else if ( f = = F u n c t o r L o n g I n t ) {
Int l i = L o n g I n t O f T e r m ( s u m _ v a l u e ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , l i , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ l o n g i n t ) ;
} else if ( f = = F u n c t o r B i g I n t ) {
C E L L * l i = Y a p _ H e a p S t o r e O p a q u e T e r m ( s u m _ v a l u e ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ n u l l ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , ( C E L L ) l i , _ t r i e _ r e t r y _ e x t e n s i o n ) ;
A N S W E R _ S A F E _ I N S E R T _ E N T R Y ( c u r r e n t _ n o d e , A b s A p p l ( ( Term * ) f ) , _ t r i e _ r e t r y _ b i g i n t ) ;
}
}
2012-06-04 19:27:31 +01:00
return c u r r e n t _ n o d e ;
}
# e n d i f /* I N C L U D E _ A N S W E R _ S E A R C H _ M O D E _ D I R E C T E D */
2011-11-09 11:00:31 +00:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * i n v a l i d a t e _ a n s w e r _ t r i e * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2011-11-15 16:57:51 +00:00
# i f def I N C L U D E _ A N S W E R _ S E A R C H _ M O D E _ D I R E C T E D
2012-05-14 19:11:58 +01:00
static void i n v a l i d a t e _ a n s w e r _ t r i e ( a n s _ n o d e _ p t r c u r r e n t _ n o d e , s g _ f r _ p t r s g _ f r , int position U S E S _ R E G S ) {
2011-11-09 11:00:31 +00:00
if ( I S _ A N S W E R _ T R I E _ H A S H ( c u r r e n t _ n o d e ) ) {
a n s _ h a s h _ p t r h a s h ;
a n s _ n o d e _ p t r * b u c k e t , * l a s t _ b u c k e t ;
h a s h = ( a n s _ h a s h _ p t r ) c u r r e n t _ n o d e ;
b u c k e t = H a s h _ b u c k e t s ( h a s h ) ;
l a s t _ b u c k e t = b u c k e t + H a s h _ n u m _ b u c k e t s ( h a s h ) ;
do {
c u r r e n t _ n o d e = * b u c k e t ;
if ( c u r r e n t _ n o d e ) {
2013-12-19 10:56:52 +00:00
a n s _ n o d e _ p t r n e x t _ n o d e = T r N o d e _ n e x t ( c u r r e n t _ n o d e ) ;
if ( I S _ A N S W E R _ L E A F _ N O D E ( c u r r e n t _ n o d e ) ) {
I N V A L I D A T E _ A N S W E R _ T R I E _ L E A F _ N O D E ( c u r r e n t _ n o d e , s g _ f r ) ;
} else {
i n v a l i d a t e _ a n s w e r _ t r i e ( T r N o d e _ c h i l d ( c u r r e n t _ n o d e ) , s g _ f r , T R A V E R S E _ P O S I T I O N _ F I R S T P A S S _ R E G S ) ;
I N V A L I D A T E _ A N S W E R _ T R I E _ N O D E ( c u r r e n t _ n o d e , s g _ f r ) ;
}
while ( n e x t _ n o d e ) {
c u r r e n t _ n o d e = n e x t _ n o d e ;
n e x t _ n o d e = T r N o d e _ n e x t ( c u r r e n t _ n o d e ) ;
i n v a l i d a t e _ a n s w e r _ t r i e ( c u r r e n t _ n o d e , s g _ f r , T R A V E R S E _ P O S I T I O N _ N E X T P A S S _ R E G S ) ;
}
2011-11-09 11:00:31 +00:00
}
} while ( + + b u c k e t ! = l a s t _ b u c k e t ) ;
if ( H a s h _ n e x t ( h a s h ) )
H a s h _ p r e v i o u s ( H a s h _ n e x t ( h a s h ) ) = H a s h _ p r e v i o u s ( h a s h ) ;
if ( H a s h _ p r e v i o u s ( h a s h ) )
H a s h _ n e x t ( H a s h _ p r e v i o u s ( h a s h ) ) = H a s h _ n e x t ( h a s h ) ;
else
S g F r _ h a s h _ c h a i n ( s g _ f r ) = H a s h _ n e x t ( h a s h ) ;
2011-12-22 16:50:20 +00:00
F R E E _ B U C K E T S ( H a s h _ b u c k e t s ( h a s h ) ) ;
2011-11-09 11:00:31 +00:00
F R E E _ A N S W E R _ T R I E _ H A S H ( h a s h ) ;
} else {
if ( position = = T R A V E R S E _ P O S I T I O N _ F I R S T ) {
a n s _ n o d e _ p t r n e x t _ n o d e = T r N o d e _ n e x t ( c u r r e n t _ n o d e ) ;
2011-11-16 12:47:43 +00:00
if ( I S _ A N S W E R _ L E A F _ N O D E ( c u r r e n t _ n o d e ) ) {
2013-12-19 10:56:52 +00:00
I N V A L I D A T E _ A N S W E R _ T R I E _ L E A F _ N O D E ( c u r r e n t _ n o d e , s g _ f r ) ;
2011-11-09 11:00:31 +00:00
} else {
2013-12-19 10:56:52 +00:00
i n v a l i d a t e _ a n s w e r _ t r i e ( T r N o d e _ c h i l d ( c u r r e n t _ n o d e ) , s g _ f r , T R A V E R S E _ P O S I T I O N _ F I R S T P A S S _ R E G S ) ;
I N V A L I D A T E _ A N S W E R _ T R I E _ N O D E ( c u r r e n t _ n o d e , s g _ f r ) ;
2011-11-09 11:00:31 +00:00
}
while ( n e x t _ n o d e ) {
2013-12-19 10:56:52 +00:00
c u r r e n t _ n o d e = n e x t _ n o d e ;
n e x t _ n o d e = T r N o d e _ n e x t ( c u r r e n t _ n o d e ) ;
i n v a l i d a t e _ a n s w e r _ t r i e ( c u r r e n t _ n o d e , s g _ f r , T R A V E R S E _ P O S I T I O N _ N E X T P A S S _ R E G S ) ;
2011-11-09 11:00:31 +00:00
}
} else {
2011-11-16 12:47:43 +00:00
if ( I S _ A N S W E R _ L E A F _ N O D E ( c u r r e n t _ n o d e ) ) {
2013-12-19 10:56:52 +00:00
I N V A L I D A T E _ A N S W E R _ T R I E _ L E A F _ N O D E ( c u r r e n t _ n o d e , s g _ f r ) ;
2011-11-09 11:00:31 +00:00
} else {
2013-12-19 10:56:52 +00:00
i n v a l i d a t e _ a n s w e r _ t r i e ( T r N o d e _ c h i l d ( c u r r e n t _ n o d e ) , s g _ f r , T R A V E R S E _ P O S I T I O N _ F I R S T P A S S _ R E G S ) ;
I N V A L I D A T E _ A N S W E R _ T R I E _ N O D E ( c u r r e n t _ n o d e , s g _ f r ) ;
2011-11-09 11:00:31 +00:00
}
}
}
return ;
}
2011-11-15 16:57:51 +00:00
# e n d i f /* I N C L U D E _ A N S W E R _ S E A R C H _ M O D E _ D I R E C T E D */
2010-04-15 01:09:59 +01:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * l o a d _ ( a n s w e r | s u b s t i t u t i o n ) _ l o o p * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def I N C L U D E _ L O A D _ A N S W E R _ L O O P
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
2012-05-14 19:11:58 +01:00
static i n l i n e C E L L * l o a d _ s u b s t i t u t i o n _ l o o p ( g t _ n o d e _ p t r c u r r e n t _ n o d e , int * v a r s _ a r i t y _ p t r , C E L L * s t a c k _ t e r m s U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# else
2012-05-14 19:11:58 +01:00
static i n l i n e C E L L * l o a d _ a n s w e r _ l o o p ( a n s _ n o d e _ p t r c u r r e n t _ n o d e U S E S _ R E G S ) {
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2011-05-25 18:50:54 +01:00
= = = = = = = = = = =
| |
| . . . |
| |
- - - - - - - - - - -
T R - - > | V A R _ 0 | < - - s t a c k _ v a r s _ b a s e
- - - - - - - - - - - *
| . . . | / | \
- - - - - - - - - - - | v a r s _ a r i t y ( N + 1 )
| V A R _ N | \ | /
- - - - - - - - - - - *
| | < - - s t a c k _ t e r m s _ l i m i t
- - - - - - - - - - -
| |
| . . . |
| |
- - - - - - - - - - |
| T E R M _ N | < - - s t a c k _ t e r m s
- - - - - - - - - - | *
| . . . | / | \
- - - - - - - - - - | | s t a c k _ t e r m s _ p a i r _ o f f s e t ( T R I E _ C O M P A C T _ P A I R S )
| T E R M _ 1 | \ | /
= = = = = = = = = = = *
2011-05-23 16:19:47 +01:00
L O C A L _ T r a i l T o p - - > | | < - - s t a c k _ t e r m s _ b a s e ( T R I E _ C O M P A C T _ P A I R S )
2011-05-25 18:50:54 +01:00
- - - - - - - - - - -
2010-04-15 01:09:59 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
int v a r s _ a r i t y = * v a r s _ a r i t y _ p t r ;
# else
int v a r s _ a r i t y = 0 ;
2011-05-23 16:19:47 +01:00
C E L L * s t a c k _ t e r m s = ( C E L L * ) L O C A L _ T r a i l T o p ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
C E L L * s t a c k _ v a r s _ b a s e = ( C E L L * ) T R ;
# define s t a c k _ t e r m s _ l i m i t ( s t a c k _ v a r s _ b a s e + v a r s _ a r i t y )
2010-04-23 04:22:10 +01:00
# i f def T R I E _ C O M P A C T _ P A I R S
2011-05-23 16:19:47 +01:00
# define s t a c k _ t e r m s _ b a s e ( ( C E L L * ) L O C A L _ T r a i l T o p )
2010-04-15 01:09:59 +01:00
int s t a c k _ t e r m s _ p a i r _ o f f s e t = 0 ;
2010-04-23 04:22:10 +01:00
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
2010-04-15 01:09:59 +01:00
Term t = T r N o d e _ e n t r y ( c u r r e n t _ n o d e ) ;
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
# else
2012-01-05 11:41:46 +00:00
c u r r e n t _ n o d e = ( a n s _ n o d e _ p t r ) U N T A G _ A N S W E R _ N O D E ( T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ) ;
2010-04-15 01:09:59 +01:00
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y T s ;
void * C y c l i c T e r m ;
t e r m _ a r r a y _ i n i t ( &Ts, 10);
Term R a t i o n a l T e r m T M P ; // a temporary temp to be used from the rational code
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
do {
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
C y c l i c T e r m = t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) c u r r e n t _ n o d e ) ;
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
if ( I s V a r T e r m ( t ) ) {
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
2014-02-13 11:57:46 +00:00
if ( t > V a r I n d e x O f T a b l e T e r m ( M A X _ T A B L E _ V A R S ) && TrNode_child((gt_node_ptr) t) != (gt_node_ptr)(1)) { //TODO: substitute the != 1 test to something more appropriate
2013-12-19 10:56:52 +00:00
/* R a t i o n a l t e r m */
R a t i o n a l T e r m T M P = ( Term ) t e r m _ a r r a y _ m e m b e r ( T s , ( void * ) t ) ;
if ( R a t i o n a l T e r m T M P ) {
/* r a t i o n a l t e r m i s a s s i g n e d a v a r i a b l e a l r e a d y */
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t ) ;
S T A C K _ P U S H _ U P ( R a t i o n a l T e r m T M P , s t a c k _ t e r m s ) ;
} else {
R a t i o n a l T e r m T M P = M k V a r T e r m ( ) ;
S T A C K _ P U S H _ U P ( R a t i o n a l T e r m T M P , s t a c k _ t e r m s ) ;
/* m e m o r i z e t h e r a t i o n a l t e r m a n d a s s i g n i t a v a r i a b l e */
t e r m _ a r r a y _ p u s h ( &Ts, (void *) t, (void *) RationalTermTMP);
}
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
{
2010-04-23 04:22:10 +01:00
# if ! defined ( M O D E _ G L O B A L _ T R I E _ L O O P ) | | defined ( G L O B A L _ T R I E _ F O R _ S U B T E R M S )
2013-12-19 10:56:52 +00:00
if ( t > V a r I n d e x O f T a b l e T e r m ( M A X _ T A B L E _ V A R S ) ) {
s t a c k _ t e r m s = l o a d _ s u b s t i t u t i o n _ l o o p ( ( g t _ n o d e _ p t r ) t , &vars_arity, stack_terms PASS_REGS);
} else
2010-04-23 04:22:10 +01:00
# e n d i f /* ! M O D E _ G L O B A L _ T R I E _ L O O P | | G L O B A L _ T R I E _ F O R _ S U B T E R M S */
2013-12-19 10:56:52 +00:00
{ i n t v a r _ i n d e x = V a r I n d e x O f T a b l e T e r m ( t ) ;
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t - v a r s _ a r i t y + v a r _ i n d e x + 1 ) ;
if ( v a r _ i n d e x > = v a r s _ a r i t y ) {
while ( v a r s _ a r i t y < v a r _ i n d e x )
s t a c k _ v a r s _ b a s e [ v a r s _ a r i t y + + ] = 0 ;
s t a c k _ v a r s _ b a s e [ v a r s _ a r i t y + + ] = M k V a r T e r m ( ) ;
} else if ( s t a c k _ v a r s _ b a s e [ v a r _ i n d e x ] = = 0 )
s t a c k _ v a r s _ b a s e [ v a r _ i n d e x ] = M k V a r T e r m ( ) ;
S T A C K _ P U S H _ U P ( s t a c k _ v a r s _ b a s e [ v a r _ i n d e x ] , s t a c k _ t e r m s ) ;
}
2010-04-15 01:09:59 +01:00
}
} else if ( I s A t o m O r I n t T e r m ( t ) ) {
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t ) ;
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( C y c l i c T e r m ) {
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 4 ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ; // Add a rational term marker necessary as we read both ways the stack //
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ; // Add the term //
S T A C K _ P U S H _ U P ( C y c l i c T e r m , s t a c k _ t e r m s ) ; // Add the variable that the term will unify with //
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ; // Add a rational term marker necessary as we read both ways the stack //
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
} else if ( I s P a i r T e r m ( t ) ) {
# i f def T R I E _ C O M P A C T _ P A I R S
if ( t = = C o m p a c t P a i r I n i t ) {
2013-12-19 10:56:52 +00:00
Term * s t a c k _ a u x = s t a c k _ t e r m s _ b a s e - s t a c k _ t e r m s _ p a i r _ o f f s e t ;
Term h e a d , t a i l = S T A C K _ P O P _ U P ( s t a c k _ a u x ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s R a t i o n a l T e r m ( t a i l ) ) {
Y a p _ E r r o r ( I N T E R N A L _ E R R O R , t a i l , "Rational element of a Rational Term appears as the first Tail of a list" ) ;
}
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
while ( S T A C K _ N O T _ E M P T Y ( s t a c k _ a u x , s t a c k _ t e r m s ) ) {
h e a d = S T A C K _ P O P _ U P ( s t a c k _ a u x ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( I s R a t i o n a l T e r m ( h e a d ) ) {
h e a d = S T A C K _ P O P _ U P ( s t a c k _ a u x ) ; // thats the rational term
R a t i o n a l T e r m T M P = S T A C K _ P O P _ U P ( s t a c k _ a u x ) ; // that is the variable to unify with
( void ) S T A C K _ P O P _ U P ( s t a c k _ a u x ) ; // eat the second rational mark
t a i l = M k P a i r T e r m ( h e a d , t a i l ) ;
Y a p _ u n i f y ( R a t i o n a l T e r m T M P , t a i l ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
t a i l = M k P a i r T e r m ( h e a d , t a i l ) ;
}
s t a c k _ t e r m s = s t a c k _ t e r m s _ b a s e - s t a c k _ t e r m s _ p a i r _ o f f s e t ;
s t a c k _ t e r m s _ p a i r _ o f f s e t = ( int ) S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( t a i l , s t a c k _ t e r m s ) ;
2010-04-15 01:09:59 +01:00
} else { / * C o m p a c t P a i r E n d L i s t / C o m p a c t P a i r E n d T e r m * /
2013-12-19 10:56:52 +00:00
Term last ;
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t + 1 ) ;
last = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
R a t i o n a l T e r m T M P = T e r m N i l ;
if ( I s R a t i o n a l T e r m ( last ) ) { / / r a t h e r u n l i k e l y c a s e t h e r a t i o n a l t e r m i s t h e l a s t o f a l i s t
R a t i o n a l T e r m T M P = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ; // in this case we need to invert the term with the end of list
last = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ; // variable to unify with
( void ) S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ; // eat the second rational mark
}
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S T A C K _ P U S H _ U P ( s t a c k _ t e r m s _ p a i r _ o f f s e t , s t a c k _ t e r m s ) ;
s t a c k _ t e r m s _ p a i r _ o f f s e t = ( int ) ( s t a c k _ t e r m s _ b a s e - s t a c k _ t e r m s ) ;
if ( t = = C o m p a c t P a i r E n d L i s t )
S T A C K _ P U S H _ U P ( T e r m N i l , s t a c k _ t e r m s ) ;
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( R a t i o n a l T e r m T M P && RationalTermTMP != TermNil) {
/* m o s t p r o b a b l y t h i s n e v e r o c c u r s */
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( last , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( R a t i o n a l T e r m T M P , s t a c k _ t e r m s ) ;
S T A C K _ P U S H _ U P ( ( Term ) R a t i o n a l M a r k , s t a c k _ t e r m s ) ;
} else
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
S T A C K _ P U S H _ U P ( last , s t a c k _ t e r m s ) ;
2010-04-15 01:09:59 +01:00
}
2010-04-23 04:22:10 +01:00
# else /* ! T R I E _ C O M P A C T _ P A I R S */
2010-04-15 01:09:59 +01:00
Term h e a d = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
Term t a i l = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
t = M k P a i r T e r m ( h e a d , t a i l ) ;
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
} else if ( I s A p p l T e r m ( t ) ) {
F u n c t o r f = ( F u n c t o r ) R e p A p p l ( t ) ;
if ( f = = F u n c t o r D o u b l e ) {
2013-12-19 10:56:52 +00:00
union {
Term t _ d b l [ s i z e o f ( Float ) / s i z e o f ( Term ) ] ;
Float d b l ;
} u ;
t = T r N o d e _ e n t r y ( c u r r e n t _ n o d e ) ;
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
u . t _ d b l [ 0 ] = t ;
2010-04-15 01:09:59 +01:00
# if S I Z E O F _ D O U B L E = = 2 * S I Z E O F _ I N T _ P
2013-12-19 10:56:52 +00:00
t = T r N o d e _ e n t r y ( c u r r e n t _ n o d e ) ;
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
u . t _ d b l [ 1 ] = t ;
2010-04-15 01:09:59 +01:00
# e n d i f /* S I Z E O F _ D O U B L E x S I Z E O F _ I N T _ P */
2013-12-19 10:56:52 +00:00
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
t = M k F l o a t T e r m ( u . d b l ) ;
2010-04-15 01:09:59 +01:00
} else if ( f = = F u n c t o r L o n g I n t ) {
Int l i = T r N o d e _ e n t r y ( c u r r e n t _ n o d e ) ;
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
t = M k L o n g I n t T e r m ( l i ) ;
2014-01-17 09:39:29 +00:00
} else if ( f = = F u n c t o r B i g I n t | | f = = F u n c t o r S t r i n g ) {
C E L L * p t r = ( C E L L * ) T r N o d e _ e n t r y ( c u r r e n t _ n o d e ) ;
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
t = A b s A p p l ( p t r ) ;
2010-04-15 01:09:59 +01:00
} else {
2013-12-19 10:56:52 +00:00
int f _ a r i t y = A r i t y O f F u n c t o r ( f ) ;
t = Y a p _ M k A p p l T e r m ( f , f _ a r i t y , s t a c k _ t e r m s ) ;
s t a c k _ t e r m s + = f _ a r i t y ;
2010-04-15 01:09:59 +01:00
}
A U X _ S T A C K _ C H E C K _ E X P A N D ( s t a c k _ t e r m s , s t a c k _ t e r m s _ l i m i t ) ;
S T A C K _ P U S H _ U P ( t , s t a c k _ t e r m s ) ;
}
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
if ( C y c l i c T e r m ) {
R a t i o n a l T e r m T M P = S T A C K _ P O P _ D O W N ( s t a c k _ t e r m s ) ;
if I s R a t i o n a l T e r m ( R a t i o n a l T e r m T M P ) {
//printf("Special Case\n");
} else if ( I s P a i r T e r m ( R a t i o n a l T e r m T M P ) ) {
Y a p _ u n i f y ( ( Term ) C y c l i c T e r m , R a t i o n a l T e r m T M P ) ;
} else if ( I s A p p l T e r m ( R a t i o n a l T e r m T M P ) ) {
Y a p _ u n i f y ( ( Term ) C y c l i c T e r m , R a t i o n a l T e r m T M P ) ;
}
S T A C K _ P U S H _ U P ( R a t i o n a l T e r m T M P , s t a c k _ t e r m s ) ;
}
R a t i o n a l T e r m T M P = T e r m N i l ;
C y c l i c T e r m = NULL ;
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
t = T r N o d e _ e n t r y ( c u r r e n t _ n o d e ) ;
c u r r e n t _ n o d e = T r N o d e _ p a r e n t ( c u r r e n t _ n o d e ) ;
} while ( c u r r e n t _ n o d e ) ;
2013-12-19 10:56:52 +00:00
# i f def T R I E _ R A T I O N A L _ T E R M S
t e r m _ a r r a y _ f r e e ( &Ts);
# e n d i f /* R A T I O N A L T E R M S U P P O R T F O R T R I E S */
2010-04-15 01:09:59 +01:00
# i f def M O D E _ G L O B A L _ T R I E _ L O O P
* v a r s _ a r i t y _ p t r = v a r s _ a r i t y ;
# e n d i f /* M O D E _ G L O B A L _ T R I E _ L O O P */
return s t a c k _ t e r m s ;
# u n def s t a c k _ t e r m s _ l i m i t
# i f def T R I E _ C O M P A C T _ P A I R S
# u n def s t a c k _ t e r m s _ b a s e
# e n d i f /* T R I E _ C O M P A C T _ P A I R S */
}
# e n d i f /* I N C L U D E _ L O A D _ A N S W E R _ L O O P */
2011-11-09 11:00:31 +00:00
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
* * U n def M a c r o s * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * /
# u n def I N C R E M E N T _ G L O B A L _ T R I E _ R E F E R E N C E
# u n def N E W _ S U B G O A L _ T R I E _ N O D E
# u n def N E W _ A N S W E R _ T R I E _ N O D E
# u n def N E W _ G L O B A L _ T R I E _ N O D E
# u n def S U B G O A L _ C H E C K _ I N S E R T _ E N T R Y
# u n def A N S W E R _ C H E C K _ I N S E R T _ E N T R Y