library/src/datastructures/BP-HashTable.cc
// This is the recursing version of the destroy table routine.  This is necessary
// because we have to assure we can checkout a full directory before deleting the
// directory.  The BP_HashRegDestroyTable routine performs the initial table checkout,
// and this routine recurses into the table and unlocks/deletes members
// of the table.  This routine should never be called directly unless
// first ensuring that the table they're calling this with is checked out
// beforehand.
This is the recursing version of the destroy table routine.  This is necessary
because we have to assure we can checkout a full directory before deleting the
directory.  The BP_HashRegDestroyTable routine performs the initial table checkout,
and this routine recurses into the table and unlocks/deletes members
of the table.  This routine should never be called directly unless
first ensuring that the table they're calling this with is checked out
beforehand.
This is the recursing version of the destroy table routine . This is necessary because we have to assure we can checkout a full directory before deleting the directory . The BP_HashRegDestroyTable routine performs the initial table checkout and this routine recurses into the table and unlocks / deletes members of the table . This routine should never be called directly unless first ensuring that the table they ' re calling this with is checked out beforehand .
BP_ERROR_T BP_HashRegDestroyTable_r
(
	P_BP_HASH_TABLE_REGISTRY    hreg,
	P_BP_HASH_TABLE_KEYED_ENTRY table
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(ERR_FAILURE);
	if(!table)
		return ERR_FAILURE;
	if(table->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
		return ERR_FAILURE;
	if(table->data)
	{
		P_BP_HASH_TABLE_KEYED_ENTRY entry_table   = (P_BP_HASH_TABLE_KEYED_ENTRY) table->data;
		P_BP_HASH_TABLE_KEYED_ENTRY entry       = NULL;
		P_BP_HASH_TABLE_KEYED_ENTRY tmp         = NULL;
		P_BP_HASH_TABLE_KEYED_ENTRY sub_table   = NULL;
		BP_ERROR_T data_destroy_status  = ERR_FAILURE;
		BP_ERROR_T table_destroy_status = ERR_FAILURE;
		HASH_ITER(hh, entry_table, entry, tmp)
		{
			if(entry == table)
				continue;
			data_destroy_status  = ERR_FAILURE;
			table_destroy_status = ERR_FAILURE;
			if(entry->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
			{
				data_destroy_status = BP_HashRegDestroyKeyedEntryData
				(
					hreg,
					entry
				);
				if(data_destroy_status == ERR_FAILURE)
				{
					return ERR_FAILURE;
				}
			}
			else
			{
				table_destroy_status = BP_HashRegDestroyTable_r
				(
					hreg,
					entry
				);
				if(table_destroy_status == ERR_FAILURE)
				{
					return ERR_FAILURE;
				}
			}
		}
	}
	char * destroyed_mem = (char *) strdup(table->key);
	if( BP_HashRegDestroyKeyedEntryTable(hreg,table) == ERR_FAILURE)
	{
		free(destroyed_mem);
		return ERR_FAILURE;
	}
	else
	{
		free(destroyed_mem);
	}
	hreg->total_tables_in_hive--;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HashRegDestroyTable_r ( P_BP_HASH_TABLE_REGISTRY hreg , P_BP_HASH_TABLE_KEYED_ENTRY table ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( ERR_FAILURE ) ; if ( ! table ) return ERR_FAILURE ; if ( table -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) return ERR_FAILURE ; if ( table -> data ) { P_BP_HASH_TABLE_KEYED_ENTRY entry_table = ( P_BP_HASH_TABLE_KEYED_ENTRY ) table -> data ; P_BP_HASH_TABLE_KEYED_ENTRY entry = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY tmp = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY sub_table = NULL ; BP_ERROR_T data_destroy_status = ERR_FAILURE ; BP_ERROR_T table_destroy_status = ERR_FAILURE ; HASH_ITER ( hh , entry_table , entry , tmp ) { if ( entry == table ) continue ; data_destroy_status = ERR_FAILURE ; table_destroy_status = ERR_FAILURE ; if ( entry -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) { data_destroy_status = BP_HashRegDestroyKeyedEntryData ( hreg , entry ) ; if ( data_destroy_status == ERR_FAILURE ) { return ERR_FAILURE ; } } else { table_destroy_status = BP_HashRegDestroyTable_r ( hreg , entry ) ; if ( table_destroy_status == ERR_FAILURE ) { return ERR_FAILURE ; } } } } char * destroyed_mem = ( char * ) strdup ( table -> key ) ; if ( BP_HashRegDestroyKeyedEntryTable ( hreg , table ) == ERR_FAILURE ) { free ( destroyed_mem ) ; return ERR_FAILURE ; } else { free ( destroyed_mem ) ; } hreg -> total_tables_in_hive -- ; return ERR_SUCCESS ; }
This is the recursing version of the destroy table routine.
This is the recursing version of the destroy table routine .
// macro to override hreg on null // return indicating failure // ensure the table provided is the correct type // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Begin Table Recursion %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // if there is no data, check lock status and return // accordingly. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Set Cascading Pointer %%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // cascading hash table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt to Recursively Lock Children %%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // temporary iterator values used during the HASH_ITER loop below // status for last data and table locks // iterate through all hashes and display // always skip self references // reset lock status on loop // It's either a data entry or a hash table.  If it's data, just lock it.  If it's a table, // check out the tables member elements. // printf("\n Destroying data!: %s", entry->key); // destroy the keyed entry at this position // exit if the lock failed // printf("\n [!!] Failed to destroy data."); // printf("\n Destroying table!: %s", entry->key); // recurse and destroy lower tables/data // exit if the destruction fails // printf("\n Failed to destroy: %s", entry->key); // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt to Unlock Table %%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // destroy the keyed entry; cascade outward from innermost (aka first/deepest return is fisrt delete) // printf("\n [!!] Failed to destroy tables keyed entry: %s", destroyed_mem); // printf("\n [+] Success destroying tables keyed entry: %s", destroyed_mem); /**/ // decrease the total number of tables in the hive // return indicating success