library/src/datastructures/BP-HashTable.cc
// Will search a traversal path and return an ENTRY based on a path query.
Will search a traversal path and return an ENTRY based on a path query.
Will search a traversal path and return an ENTRY based on a path query .
P_BP_HASH_TABLE_KEYED_ENTRY BP_HashRegLookupTableEntryByDataKeyIndexAndTablePath
(
	P_BP_HASH_TABLE_REGISTRY      hreg,
	BP_HASH_TABLE_TRAVERSAL_PATH  table_path,
	char *                        data_index_key
)
{
	if(!table_path)
		return NULL;
	if(!data_index_key)
		return NULL;
	if(!table_path[0])
	{
		return NULL;
	}
	size_t ptr_array_size = BP_CountNullTerminatedPtrArray(table_path);
	char ** tmp_path_lookup_array = (char **) bpcalloc
	(
		sizeof(char *) * (ptr_array_size+2),
		1
	);
	if(!tmp_path_lookup_array)
		return NULL;
	size_t table_idx = 0;
	for(; table_path[table_idx]; table_idx++)
	{
		tmp_path_lookup_array[table_idx] = bpstrdup(table_path[table_idx]);
	}
	tmp_path_lookup_array[ptr_array_size]   = bpstrdup(data_index_key);
	tmp_path_lookup_array[ptr_array_size+1] = NULL;
	P_BP_HASH_TABLE_KEYED_ENTRY lookup_entry = BP_HashRegLookupTableEntryByPath(hreg, tmp_path_lookup_array);
	if(!lookup_entry)
	{
		BP_DestroyPointerArrayNullTerminated((void **) tmp_path_lookup_array);
		bpfree(tmp_path_lookup_array);
		return NULL;
	}
	BP_DestroyPointerArrayNullTerminated((void **) tmp_path_lookup_array);
	bpfree(tmp_path_lookup_array);
	return lookup_entry;
}
P_BP_HASH_TABLE_KEYED_ENTRY BP_HashRegLookupTableEntryByDataKeyIndexAndTablePath ( P_BP_HASH_TABLE_REGISTRY hreg , BP_HASH_TABLE_TRAVERSAL_PATH table_path , char * data_index_key ) { if ( ! table_path ) return NULL ; if ( ! data_index_key ) return NULL ; if ( ! table_path [ 0 ] ) { return NULL ; } size_t ptr_array_size = BP_CountNullTerminatedPtrArray ( table_path ) ; char * * tmp_path_lookup_array = ( char * * ) bpcalloc ( sizeof ( char * ) * ( ptr_array_size + 2 ) , 1 ) ; if ( ! tmp_path_lookup_array ) return NULL ; size_t table_idx = 0 ; for ( ; table_path [ table_idx ] ; table_idx ++ ) { tmp_path_lookup_array [ table_idx ] = bpstrdup ( table_path [ table_idx ] ) ; } tmp_path_lookup_array [ ptr_array_size ] = bpstrdup ( data_index_key ) ; tmp_path_lookup_array [ ptr_array_size + 1 ] = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY lookup_entry = BP_HashRegLookupTableEntryByPath ( hreg , tmp_path_lookup_array ) ; if ( ! lookup_entry ) { BP_DestroyPointerArrayNullTerminated ( ( void * * ) tmp_path_lookup_array ) ; bpfree ( tmp_path_lookup_array ) ; return NULL ; } BP_DestroyPointerArrayNullTerminated ( ( void * * ) tmp_path_lookup_array ) ; bpfree ( tmp_path_lookup_array ) ; return lookup_entry ; }
Will search a traversal path and return an ENTRY based on a path query.
Will search a traversal path and return an ENTRY based on a path query .
// basic null checks // ensure we have a first element // -- calculate size and allocate memory ----- // count the pointer array // allocate space for the lookup (table size + extra ptr + null) // exit if memory allocation failed // -- copy in strings for lookup ---------- // copy in elements // append data index and add key // -- attempt lookup ------------------- // gather lookup query // -- destroy allocated data and exit // destroy the path lookup array entries // destroy array structure // return the looked up entry