/*add the state S into hash table*/ PlanHashEntry *hash_plan_state( State *S, int step ) { int sum, index; PlanHashEntry *h, *tmp; sum = state_sum( S ); index = sum & PLAN_HASH_BITS; for ( h = lplan_hash_entry[index]; h; h = h->next ) { if ( h->sum != sum ) continue; if ( same_state( S, &(h->S) ) ) break; } /*found the same state in the hash table*/ if ( h ) { if ( h->step != -1 ) { printf("\n\n[error]:reencountering a state that is already in plan! debug me\n\n"); exit( 1 ); } h->step = step; return h; } /* not found the same state in hash table*/ /* h points to the last one*/ /* jovi: comments by jovi, seems it is not necessary * This is for addding a nes state */ for ( h = lplan_hash_entry[index]; h && h->next; h = h->next ) ; tmp = new_PlanHashEntry(); tmp->sum = sum; copy_source_to_dest( &(tmp->S), S ); tmp->step = step; if ( h ) { h->next = tmp; } else { lplan_hash_entry[index] = tmp; } return tmp; }
PlanHashEntry *hash_plan_state( State *S, int step ) { int sum, index; PlanHashEntry *h, *tmp; sum = state_sum( S ); index = sum & PLAN_HASH_BITS; for ( h = lplan_hash_entry[index]; h; h = h->next ) { if ( h->sum != sum ) continue; if ( same_state( S, &(h->S) ) ) break; } if ( h ) { if ( h->step != -1 ) { printf("\n\nreencountering a state that is already in plan! debug me\n\n"); exit( 1 ); } h->step = step; return h; } for ( h = lplan_hash_entry[index]; h && h->next; h = h->next ); tmp = new_PlanHashEntry(); tmp->sum = sum; copy_source_to_dest( &(tmp->S), S ); tmp->step = step; if ( h ) { h->next = tmp; } else { lplan_hash_entry[index] = tmp; } return tmp; }