From: David S. W. <dw...@us...> - 2009-11-17 19:32:21
|
Update of /cvsroot/xsb/XSB/emu In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17298 Modified Files: slgdelay.h tab_structs.h tables.c tr_utils.c Log Message: Added pointers in the Child field of leaf nodes of answers to point to the ALN node *preceding* the ALN node that points to it. This pointer is used in the deletion of an answer. It is tagged so that it can be known what the pointer is. If there are conditional answers, this field is used for pointing to the delay elements, and so is not used for this ALN pointer. In that case, the entire ALN list must be run when deleting an answer with a delay list. Index: slgdelay.h =================================================================== RCS file: /cvsroot/xsb/XSB/emu/slgdelay.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- slgdelay.h 17 Nov 2009 14:59:34 -0000 1.33 +++ slgdelay.h 17 Nov 2009 19:32:08 -0000 1.34 @@ -162,15 +162,16 @@ * Handling of conditional answers. */ -#define UNCONDITIONAL_MARK 0x3 +#define UNCONDITIONAL_MARK 0x1 -#define Delay(X) (ASI) ((word) (TN_Child(X)) & ~UNCONDITIONAL_MARK) +#define Delay(X) (ASI) ((word) (TN_Child(X)) & ~(UNCONDITIONAL_MARK | HasALNPtr)) #define is_conditional_answer(ANS) \ - (Child(ANS) && !((word) (Child(ANS)) & UNCONDITIONAL_MARK)) + (Child(ANS) && !hasALNtag(ANS) && !((word) (Child(ANS)) & UNCONDITIONAL_MARK)) #define is_unconditional_answer(ANS) \ - (!Child(ANS) || ((word) (Child(ANS)) & UNCONDITIONAL_MARK)) + !is_conditional_answer(ANS) + /* (!Child(ANS) || ((word) (Child(ANS)) & UNCONDITIONAL_MARK)) */ /* Checking for these two conditionis was made more difficult when WFS @@ -197,7 +198,7 @@ */ #define mark_conditional_answer(ANS, SUBG, NEW_DL,STRUCT_MGR) \ - if (Child(ANS) == NULL) { \ + if (Child(ANS) == NULL || hasALNtag(ANS)) { \ create_as_info(STRUCT_MGR,ANS, SUBG); \ } \ else { \ Index: tab_structs.h =================================================================== RCS file: /cvsroot/xsb/XSB/emu/tab_structs.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- tab_structs.h 17 Nov 2009 14:59:34 -0000 1.1 +++ tab_structs.h 17 Nov 2009 19:32:08 -0000 1.2 @@ -804,6 +804,11 @@ #define empty_return_handle(SF) empty_return(th,SF) #endif +/* tags for ALP pointers in leaf nodes, for faster delete */ +#define HasALNPtr 0x2 +#define untag_as_ALNptr(Node) ((ALNptr)((word)(Child(Node)) & ~HasALNPtr)) +#define hasALNtag(Node) ((word)(Child(Node)) & HasALNPtr) + /* Appending to the Answer List of a SF ------------------------------------ */ #define SF_AppendNewAnswerList(pSF,pAnsList) { \ @@ -819,17 +824,19 @@ #define SF_AppendNewAnswer(pSF,pAns) SF_AppendToAnswerList(pSF,pAns,pAns) #define SF_AppendToAnswerList(pSF,pHead,pTail) { \ - if ( has_answers(pSF) ) \ + if ( has_answers(pSF) ) { \ /* * Insert new answer at the end of the answer list. */ \ ALN_Next(subg_ans_list_tail(pSF)) = pHead; \ - else \ + Child(ALN_Answer(pHead)) = (NODEptr) ((word)(subg_ans_list_tail(pSF)) | HasALNPtr); \ + } else { \ /* * The dummy answer list node is the only node currently in the list. * It's pointed to by the head ptr, but the tail ptr is NULL. */ \ ALN_Next(subg_ans_list_ptr(pSF)) = pHead; \ + } \ subg_ans_list_tail(pSF) = pTail; \ } Index: tables.c =================================================================== RCS file: /cvsroot/xsb/XSB/emu/tables.c,v retrieving revision 1.69 retrieving revision 1.70 diff -u -r1.69 -r1.70 --- tables.c 17 Nov 2009 14:59:34 -0000 1.69 +++ tables.c 17 Nov 2009 19:32:08 -0000 1.70 @@ -675,7 +675,9 @@ do { if ( is_conditional_answer(ALN_Answer(pALN)) ) { tag = COND_ANSWERS; - break; + } + if (hasALNtag(ALN_Answer(pALN))) { /* reset to null */ + Child(ALN_Answer(pALN)) = NULL; } pALN = ALN_Next(pALN); } while ( IsNonNULL(pALN) ); @@ -690,7 +692,9 @@ do { if ( is_conditional_answer(ALN_Answer(pALN)) ) { tag = COND_ANSWERS; - break; + } + if (hasALNtag(ALN_Answer(pALN))) { /* reset to null */ + Child(ALN_Answer(pALN)) = NULL; } pALN = ALN_Next(pALN); } while ( IsNonNULL(pALN) ); Index: tr_utils.c =================================================================== RCS file: /cvsroot/xsb/XSB/emu/tr_utils.c,v retrieving revision 1.181 retrieving revision 1.182 diff -u -r1.181 -r1.182 --- tr_utils.c 17 Nov 2009 14:59:34 -0000 1.181 +++ tr_utils.c 17 Nov 2009 19:32:08 -0000 1.182 @@ -657,7 +657,7 @@ extern void hashtable1_destroy(void *, int); - static void delete_variant_table(CTXTdeclc BTNptr x, int incr, xsbBool should_warn) { +static void delete_variant_table(CTXTdeclc BTNptr x, int incr, xsbBool should_warn) { // printf("in delete variant table\n"); @@ -1155,7 +1155,7 @@ * MUTEX_DELAY. But I'm not sure that other parts of this function * are thread-safe. */ -void delete_return(CTXTdeclc BTNptr l, VariantSF sg_frame,int eval_method) +void delete_return(CTXTdeclc BTNptr leaf, VariantSF sg_frame,int eval_method) { ALNptr a, n, next; NLChoice c; @@ -1164,36 +1164,44 @@ TChoice tc; #endif - xsb_dbgmsg((LOG_INTERN, "DELETE_NODE: %d - Par: %d", l, BTN_Parent(l))); + xsb_dbgmsg((LOG_INTERN, "DELETE_NODE: %d - Par: %d", leaf, BTN_Parent(leaf))); /* deleting an answer makes it false, so we have to deal with delay lists */ SET_TRIE_ALLOCATION_TYPE_SF(sg_frame); - if (is_conditional_answer(l)) { - ASI asi = Delay(l); + if (is_conditional_answer(leaf)) { + ASI asi = Delay(leaf); SYS_MUTEX_LOCK( MUTEX_DELAY ) ; release_all_dls(CTXTc asi); SYS_MUTEX_UNLOCK( MUTEX_DELAY ) ; /* TLS 12/00 changed following line from - (l == subg_ans_root_ptr(sg_frame) && .. + (leaf == subg_ans_root_ptr(sg_frame) && .. so that negation failure simplification is properly performed */ - if (l == BTN_Child(subg_ans_root_ptr(sg_frame)) && - IsEscapeNode(l)) - groundcall=TRUE; /* do it here, when l is still valid */ + if (leaf == BTN_Child(subg_ans_root_ptr(sg_frame)) && + IsEscapeNode(leaf)) + groundcall=TRUE; /* do it here, when leaf is still valid */ } if (is_completed(sg_frame)) { - safe_delete_branch(l); + safe_delete_branch(leaf); } else { - delete_branch(CTXTc l,&subg_ans_root_ptr(sg_frame),eval_method); - n = subg_ans_list_ptr(sg_frame); - /* Find previous sibling -pvr */ - while (ALN_Answer(ALN_Next(n)) != l) { - n = ALN_Next(n);/* if a is not in that list a core dump will result */ - } - if (n == NULL) { - xsb_exit(CTXTc "Error in delete_return()"); + delete_branch(CTXTc leaf,&subg_ans_root_ptr(sg_frame),eval_method); + if (hasALNtag(leaf)) { + n = untag_as_ALNptr(leaf); + } else { + n = subg_ans_list_ptr(sg_frame); + /* Find previous sibling -pvr */ + while (ALN_Answer(ALN_Next(n)) != leaf) { + n = ALN_Next(n);/* if a is not in that list a core dump will result */ + } + if (n == NULL) { + xsb_exit(CTXTc "Error in delete_return()"); + } } + if (ALN_Next(n) && ALN_Next(ALN_Next(n)) && + hasALNtag(ALN_Answer(ALN_Next(ALN_Next(n))))) { + Child(ALN_Answer(ALN_Next(ALN_Next(n)))) = Child(leaf); + } a = ALN_Next(n); next = ALN_Next(a); ALN_Answer(a) = NULL; /* since we eagerly release trie nodes, this is @@ -1222,15 +1230,13 @@ } #endif - ALN_Next(n) = next; - if(next == NULL){ /* last answer */ subg_ans_list_tail(sg_frame) = n; } } - if (is_conditional_answer(l)) { + if (is_conditional_answer(leaf)) { SYS_MUTEX_LOCK( MUTEX_DELAY ) ; - simplify_pos_unsupported(CTXTc l); + simplify_pos_unsupported(CTXTc leaf); if (groundcall) { mark_subgoal_failed(sg_frame); simplify_neg_fails(CTXTc sg_frame); |