library/src/datastructures/BP-HashTable.cc
// display single table (optionally set tab depth)
display single table (optionally set tab depth)
display single table ( optionally set tab depth )
BP_ERROR_T BP_HashRegDisplayTable
(
	P_BP_HASH_TABLE_REGISTRY    hreg,
	P_BP_HASH_TABLE_KEYED_ENTRY table_entry,
	size_t                      display_tab_depth,
	BP_BOOL                     recurse,
	BP_BOOL                     display_entries
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(ERR_FAILURE);
	if(!hreg->hive)
		return ERR_FAILURE;
	char *tabs = (char *) calloc(display_tab_depth+2, 1);
	if(!tabs)
	{
		if(BP_DEBUG_BREAKPOINT_ON_ALLOC_FAIL)
		{
			asm("int3");
		}
		return ERR_FAILURE;
	}
	memset(tabs, '\t', display_tab_depth+1);
	P_BP_HASH_TABLE_KEYED_ENTRY tmp_table = (P_BP_HASH_TABLE_KEYED_ENTRY) table_entry->data;
	printf("\n%s [T>]  %p: %s ", tabs, table_entry, table_entry->key);
	if(!tmp_table)
		printf("( 0 entries, null table )");
	else
		printf("( %u entries in table )", tmp_table ? HASH_COUNT((P_BP_HASH_TABLE_KEYED_ENTRY) tmp_table) : 100);
	int tmp_val = 0;
	printf(" lock: %s", BP_HASH_TABLE_SEM_IS_LOCKED(table_entry->lock, tmp_val) ? "UL" : "L");
	printf(" :%i", tmp_val );
	if(table_entry->parent)
	{
		P_BP_HASH_TABLE_KEYED_ENTRY tmp_parent = (P_BP_HASH_TABLE_KEYED_ENTRY) table_entry->parent;
		printf(" parent: %s", tmp_parent->key);
	}
	else
	{
		printf(" parent: NULL");
	}
	%%%%
	%%%%
	P_BP_HASH_TABLE_KEYED_ENTRY entry = NULL;
	P_BP_HASH_TABLE_KEYED_ENTRY tmp   = NULL;
	display_tab_depth++;
	HASH_ITER(hh, tmp_table, entry, tmp)
	{
		tmp_table = (P_BP_HASH_TABLE_KEYED_ENTRY) entry->data;
		if(entry->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
		{
			BP_HashRegDisplayDataEntry
			(
					hreg,
					entry,
					display_tab_depth
			);
			continue;
		}
		else
		{
			BP_HashRegDisplayTable(hreg, entry, display_tab_depth, recurse, display_entries);
		}
	}
	if(tabs)
		free(tabs);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HashRegDisplayTable ( P_BP_HASH_TABLE_REGISTRY hreg , P_BP_HASH_TABLE_KEYED_ENTRY table_entry , size_t display_tab_depth , BP_BOOL recurse , BP_BOOL display_entries ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( ERR_FAILURE ) ; if ( ! hreg -> hive ) return ERR_FAILURE ; char * tabs = ( char * ) calloc ( display_tab_depth + 2 , 1 ) ; if ( ! tabs ) { if ( BP_DEBUG_BREAKPOINT_ON_ALLOC_FAIL ) { asm ( " " ) ; } return ERR_FAILURE ; } memset ( tabs , ' \t ' , display_tab_depth + 1 ) ; P_BP_HASH_TABLE_KEYED_ENTRY tmp_table = ( P_BP_HASH_TABLE_KEYED_ENTRY ) table_entry -> data ; printf ( " \n " , tabs , table_entry , table_entry -> key ) ; if ( ! tmp_table ) printf ( " " ) ; else printf ( " " , tmp_table ? HASH_COUNT ( ( P_BP_HASH_TABLE_KEYED_ENTRY ) tmp_table ) : 100 ) ; int tmp_val = 0 ; printf ( " " , BP_HASH_TABLE_SEM_IS_LOCKED ( table_entry -> lock , tmp_val ) ? " " : " " ) ; printf ( " " , tmp_val ) ; if ( table_entry -> parent ) { P_BP_HASH_TABLE_KEYED_ENTRY tmp_parent = ( P_BP_HASH_TABLE_KEYED_ENTRY ) table_entry -> parent ; printf ( " " , tmp_parent -> key ) ; } else { printf ( " " ) ; } P_BP_HASH_TABLE_KEYED_ENTRY entry = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY tmp = NULL ; display_tab_depth ++ ; HASH_ITER ( hh , tmp_table , entry , tmp ) { tmp_table = ( P_BP_HASH_TABLE_KEYED_ENTRY ) entry -> data ; if ( entry -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) { BP_HashRegDisplayDataEntry ( hreg , entry , display_tab_depth ) ; continue ; } else { BP_HashRegDisplayTable ( hreg , entry , display_tab_depth , recurse , display_entries ) ; } } if ( tabs ) free ( tabs ) ; return ERR_SUCCESS ; }
display single table (optionally set tab depth)
display single table ( optionally set tab depth )
// macro to override hreg on null // ensure we have a table lookup // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Format Tab Depth Buffer %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create space for tabs // add tabs to buffer // tmp hash table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Display Table Line %%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // display initial basic // display entry counts // display semaphore lock status // create reference to parent so we can access its members // display the parent key and ptr // display the parent key and ptr // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Recursion Logic %%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // temporary iterator values used during the HASH_ITER loop below // increase the display tab depth in case of recursion (keeps // things lined up) // iterate through all hashes and display // set temp table // It's either a data entry or a hash table.  Display either based on // parameter preference. // display the data entry // continue the loop // recurse here // destroy tabs buffer // return indicating success