library/src/datastructures/BP-HashTable.cc
// Attempts to create a reasonable string from a keyed entry
// by crawling backwards and joining keys.
Attempts to create a reasonable string from a keyed entry
by crawling backwards and joining keys.
Attempts to create a reasonable string from a keyed entry by crawling backwards and joining keys .
char * BP_HashRegCreateReasonableStringPathFromKeyedEntry
(
	P_BP_HASH_TABLE_REGISTRY      hreg,
	P_BP_HASH_TABLE_KEYED_ENTRY   relative_position
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(NULL);
	if(!hreg)
		return NULL;
	if(!relative_position)
		return NULL;
	if(!relative_position->key)
		return NULL;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(hreg);
	char * joined_str_loop_preserve = NULL;
	char * join_str_arr[10] = {0};
	size_t join_str_arr_n   = 0;
	char * joined_str = NULL;
	P_BP_HASH_TABLE_KEYED_ENTRY path_top = NULL;
	P_BP_HASH_TABLE_KEYED_ENTRY relative_position_iter = relative_position;
	for
	(
			;
			relative_position_iter;
			relative_position_iter = (P_BP_HASH_TABLE_KEYED_ENTRY) relative_position_iter->parent
	)
	{
		if(!joined_str)
		{
			joined_str = BP_JoinStrings("/", relative_position_iter->key);
		}
		else
		{
			join_str_arr_n = 0;
			join_str_arr[join_str_arr_n] = "/";
			join_str_arr_n++;
			join_str_arr[join_str_arr_n] = relative_position_iter->key;
			join_str_arr_n++;
			join_str_arr[join_str_arr_n] = joined_str;
			join_str_arr_n++;
			join_str_arr[join_str_arr_n] = NULL;
			joined_str_loop_preserve = BP_JoinStringArray(join_str_arr, join_str_arr_n, NULL);
			if(joined_str)
				bpfree(joined_str);
			if(joined_str_loop_preserve)
			{
				joined_str = joined_str_loop_preserve;
			}
		}
		if(!relative_position_iter->parent)
		{
			break;
		}
	} 
	if(joined_str_loop_preserve)
	if(joined_str_loop_preserve != joined_str)
		bpfree(joined_str_loop_preserve);
	char * ret_str = NULL;
	if(joined_str)
	{
		ret_str = ht_strdup(hreg, joined_str);
		bpfree(joined_str);
		joined_str = NULL;
	}
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(hreg);
	return ret_str;
}
char * BP_HashRegCreateReasonableStringPathFromKeyedEntry ( P_BP_HASH_TABLE_REGISTRY hreg , P_BP_HASH_TABLE_KEYED_ENTRY relative_position ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( NULL ) ; if ( ! hreg ) return NULL ; if ( ! relative_position ) return NULL ; if ( ! relative_position -> key ) return NULL ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( hreg ) ; char * joined_str_loop_preserve = NULL ; char * join_str_arr [ 10 ] = { 0 } ; size_t join_str_arr_n = 0 ; char * joined_str = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY path_top = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY relative_position_iter = relative_position ; for ( ; relative_position_iter ; relative_position_iter = ( P_BP_HASH_TABLE_KEYED_ENTRY ) relative_position_iter -> parent ) { if ( ! joined_str ) { joined_str = BP_JoinStrings ( " " , relative_position_iter -> key ) ; } else { join_str_arr_n = 0 ; join_str_arr [ join_str_arr_n ] = " " ; join_str_arr_n ++ ; join_str_arr [ join_str_arr_n ] = relative_position_iter -> key ; join_str_arr_n ++ ; join_str_arr [ join_str_arr_n ] = joined_str ; join_str_arr_n ++ ; join_str_arr [ join_str_arr_n ] = NULL ; joined_str_loop_preserve = BP_JoinStringArray ( join_str_arr , join_str_arr_n , NULL ) ; if ( joined_str ) bpfree ( joined_str ) ; if ( joined_str_loop_preserve ) { joined_str = joined_str_loop_preserve ; } } if ( ! relative_position_iter -> parent ) { break ; } } if ( joined_str_loop_preserve ) if ( joined_str_loop_preserve != joined_str ) bpfree ( joined_str_loop_preserve ) ; char * ret_str = NULL ; if ( joined_str ) { ret_str = ht_strdup ( hreg , joined_str ) ; bpfree ( joined_str ) ; joined_str = NULL ; } BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( hreg ) ; return ret_str ; }
Attempts to create a reasonable string from a keyed entry
by crawling backwards and joining keys.
Attempts to create a reasonable string from a keyed entry by crawling backwards and joining keys .
// macro to override hreg on null // enter critical section // this is used for preserving a pointer on loop (for tracking memory for destroy) // join string array // joined string is the actual composite string // holds the top path when it's found // attempt to retrieve the top entry // if we don't have a joined string, allocate from dup // set from start position key if necessary // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Join String %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // reset string array // append slash // add key // prefix with the joining string // terminate the array // join string array // destroy old memory // ensure we have preserved a pointer // update pointer // -- end if else ------------ // ensure we have a relative position // loop-end // destroy preserve if necessary // set the return string (needs to be allocated on the hash table) // duplicate the path within the registry // destroy joined string // printf("\n"); // printf("\n Path Iter Joined Hash Table?: %p:%s", ret_str, ret_str); // printf("\n Path Iter Joined normal?:     %s", joined_str); // printf("\n"); // leave the critical section // return the joined string