library/src/datastructures/BP-HashTable.cc
// attemmpts to convert a hash entry to path
attemmpts to convert a hash entry to path
attemmpts to convert a hash entry to path
BP_HASH_TABLE_TRAVERSAL_PATH BP_HashRegEntryToPath(P_BP_HASH_TABLE_KEYED_ENTRY entry)
{
	if(!entry)
		return NULL;
	if(!entry->key)
		return NULL;
	if(!BP_HashRegPathArrayIndexFilterTest(entry->key, bpstrlen(entry->key)))
		return NULL;
	P_BP_HTKE reverse_iter_entry = NULL;
	int parent_idx_n = 0;
	if(entry->parent)
	{
		for
		(
			reverse_iter_entry = entry;
			reverse_iter_entry;
			reverse_iter_entry = (P_BP_HTKE) reverse_iter_entry->parent
		)
		{
			parent_idx_n++;
			if(!reverse_iter_entry->parent)
				break;
		}
	}
	else
	{
		reverse_iter_entry = entry;
		parent_idx_n++;
	}
	if(!parent_idx_n)
		return NULL;
	if(!reverse_iter_entry)
		return NULL;
	char ** table_path = (char **) bpcalloc
	(
		sizeof(char *) * (parent_idx_n + 1),
		1
	);
	if(parent_idx_n == 1)
	{
		table_path[0] = bpstrdup(entry->key);
		table_path[1] = NULL;
		return table_path;
	}
	for
	(
		reverse_iter_entry = entry;
		reverse_iter_entry;
		reverse_iter_entry = (P_BP_HTKE) reverse_iter_entry->parent
	)
	{
		parent_idx_n--;
		if(parent_idx_n < 0)
			break;
		table_path[parent_idx_n] = bpstrdup(reverse_iter_entry->key);
	}
	return table_path;
}
BP_HASH_TABLE_TRAVERSAL_PATH BP_HashRegEntryToPath ( P_BP_HASH_TABLE_KEYED_ENTRY entry ) { if ( ! entry ) return NULL ; if ( ! entry -> key ) return NULL ; if ( ! BP_HashRegPathArrayIndexFilterTest ( entry -> key , bpstrlen ( entry -> key ) ) ) return NULL ; P_BP_HTKE reverse_iter_entry = NULL ; int parent_idx_n = 0 ; if ( entry -> parent ) { for ( reverse_iter_entry = entry ; reverse_iter_entry ; reverse_iter_entry = ( P_BP_HTKE ) reverse_iter_entry -> parent ) { parent_idx_n ++ ; if ( ! reverse_iter_entry -> parent ) break ; } } else { reverse_iter_entry = entry ; parent_idx_n ++ ; } if ( ! parent_idx_n ) return NULL ; if ( ! reverse_iter_entry ) return NULL ; char * * table_path = ( char * * ) bpcalloc ( sizeof ( char * ) * ( parent_idx_n + 1 ) , 1 ) ; if ( parent_idx_n == 1 ) { table_path [ 0 ] = bpstrdup ( entry -> key ) ; table_path [ 1 ] = NULL ; return table_path ; } for ( reverse_iter_entry = entry ; reverse_iter_entry ; reverse_iter_entry = ( P_BP_HTKE ) reverse_iter_entry -> parent ) { parent_idx_n -- ; if ( parent_idx_n < 0 ) break ; table_path [ parent_idx_n ] = bpstrdup ( reverse_iter_entry -> key ) ; } return table_path ; }
attemmpts to convert a hash entry to path
attemmpts to convert a hash entry to path
// ensure we have an entry and a key // ensure the index passes filter checks // reverse entry iterator // parent index count (used for dynamic stack allocation) // check to see that we have a parent // fast loop to reverse-traverse through the list // if we are the top entry (aka no-parent // run count and pointer checks // allocate space for table (returned from routine, add extra entry for null ptr) // -- if the index count is 1, we can just add the key and return quick // set the key // return the filled out path // ----- // if the index count is greater than 1, we have to reverse lookup // again (cannot forward lookup due to the potential for multiple // lookup paths). // fast loop to reverse-traverse through the list // subtract from the parent index on loop // never go negative // check table path // return the filled out table path