library/src/datastructures/BP-HashTable.cc
// Add a table to the registry by a provided path.
Add a table to the registry by a provided path.
Add a table to the registry by a provided path .
BP_ERROR_T BP_HashRegAddTableByPath
(
	P_BP_HASH_TABLE_REGISTRY     hreg,
	BP_HASH_TABLE_TRAVERSAL_PATH table_path
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(ERR_FAILURE);
	if(!table_path)
		return ERR_FAILURE;
	if(!table_path[0])
		return ERR_FAILURE;
	size_t path_entry_count = BP_CountNullTerminatedPtrArray(table_path);
	if(!path_entry_count)
		return ERR_FAILURE;
	P_BP_HASH_TABLE_KEYED_ENTRY table_lookup = BP_HashRegLookupTableByPath(	hreg, table_path );
	if(table_lookup)
	{
		return ERR_FAILURE;
	}
	char * saved_path_position = NULL;
	P_BP_HASH_TABLE_KEYED_ENTRY table_parent = NULL;
	if(path_entry_count)
	{
		if(path_entry_count-1)
		{
			saved_path_position = table_path[path_entry_count-1];
			table_path[path_entry_count-1] = NULL;
			table_parent = BP_HashRegLookupTableByPath(	hreg, table_path );
			table_path[path_entry_count-1] = saved_path_position;
			if(!table_parent)
				return ERR_FAILURE;
		}
	}
	P_BP_HASH_TABLE_KEYED_ENTRY new_entry = (P_BP_HASH_TABLE_KEYED_ENTRY) BP_HashRegAddMemoryEntry
	(
		hreg,
		BP_HASH_REG_MEM_ENTRY_TYPE_KEYED_ENTRY_IN_HIVE,
		sizeof(BP_HASH_TABLE_KEYED_ENTRY),
		BPLN
	);
	BP_HASH_TABLE_INIT_SEM(new_entry->lock);
	new_entry->key = strdup(table_path[path_entry_count-1]);
	new_entry->data =  NULL;
	new_entry->type = BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE;
	new_entry->parent = (void *) table_parent;
	BP_ERROR_T ret_status = ERR_FAILURE;
	ret_status = BP_HashRegAddTable
	(
		hreg,
		table_parent,
		new_entry
	);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HashRegAddTableByPath ( P_BP_HASH_TABLE_REGISTRY hreg , BP_HASH_TABLE_TRAVERSAL_PATH table_path ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( ERR_FAILURE ) ; if ( ! table_path ) return ERR_FAILURE ; if ( ! table_path [ 0 ] ) return ERR_FAILURE ; size_t path_entry_count = BP_CountNullTerminatedPtrArray ( table_path ) ; if ( ! path_entry_count ) return ERR_FAILURE ; P_BP_HASH_TABLE_KEYED_ENTRY table_lookup = BP_HashRegLookupTableByPath ( hreg , table_path ) ; if ( table_lookup ) { return ERR_FAILURE ; } char * saved_path_position = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY table_parent = NULL ; if ( path_entry_count ) { if ( path_entry_count - 1 ) { saved_path_position = table_path [ path_entry_count - 1 ] ; table_path [ path_entry_count - 1 ] = NULL ; table_parent = BP_HashRegLookupTableByPath ( hreg , table_path ) ; table_path [ path_entry_count - 1 ] = saved_path_position ; if ( ! table_parent ) return ERR_FAILURE ; } } P_BP_HASH_TABLE_KEYED_ENTRY new_entry = ( P_BP_HASH_TABLE_KEYED_ENTRY ) BP_HashRegAddMemoryEntry ( hreg , BP_HASH_REG_MEM_ENTRY_TYPE_KEYED_ENTRY_IN_HIVE , sizeof ( BP_HASH_TABLE_KEYED_ENTRY ) , BPLN ) ; BP_HASH_TABLE_INIT_SEM ( new_entry -> lock ) ; new_entry -> key = strdup ( table_path [ path_entry_count - 1 ] ) ; new_entry -> data = NULL ; new_entry -> type = BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ; new_entry -> parent = ( void * ) table_parent ; BP_ERROR_T ret_status = ERR_FAILURE ; ret_status = BP_HashRegAddTable ( hreg , table_parent , new_entry ) ; return ERR_SUCCESS ; }
Add a table to the registry by a provided path.
Add a table to the registry by a provided path .
// macro to override hreg on null // ensure we have a key to add // count the number of entries in the table // need at least one element // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Perform Preliminary Lookup (prevents overwrites) %% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to lookup the table (check if it already exists) // if we found the table, exit immediately as we cannot add something that // already exists. // printf("\n Path Here1?: %s - ", table_lookup->key); // BP_HashRegDisplayKeyPath(table_path); // prevent duplicate tables // printf("\n Sheeeeeet: %u ", path_entry_count); // Now lookup table parent (for forward-backward linking).  Linking in the // table parent allows for very easy record removal/deletion. // used to save a position in the path which is nullified during check below. // the actual table parent // only set parent if we have a path count. // only attempt to lookup parent if a parent could possibly exist. // preserve path // overwrite last path position // attempt to lookup parent at this point // printf("\n Null Failure At: "); // BP_HashRegDisplayKeyPath(table_path); // restore saved path position (before potential exit) // a table parent is required for proper linking (path indicative), if no parent // is set, return immediately. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Entry %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // allocate new entry // initialize the semaphore // set the key here -- local allocation (DO NOT CHANGE // FROM STRDUP to BPSTRDUP) // add new table to the entries after it has been resized // set the entry type as a hash table // set the parent pointer // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Perform Table Addition %%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create var to hold return status // call the actual add routine // printf("\n Gets Here: %s - ", ret_status == ERR_FAILURE ? "FAIL" : "SUCCESS"); // BP_HashRegDisplayKeyPath(table_path); // printf("\n"); // return indicating success