library/src/datastructures/BP-HashTable.cc
// Will search a traversal path for a table.  Returns NULL if the table cannot be found. Type
// must be BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE.
Will search a traversal path for a table.  Returns NULL if the table cannot be found. Type
must be BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE.
Will search a traversal path for a table . Returns NULL if the table cannot be found . Type must be BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE .
P_BP_HASH_TABLE_KEYED_ENTRY BP_HashRegLookupTableByPath
(
	P_BP_HASH_TABLE_REGISTRY      hreg,
	BP_HASH_TABLE_TRAVERSAL_PATH  table_path
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(NULL);
	if(!table_path)
		return NULL;
	if(!table_path[0])
		return NULL;
	size_t path_entry_count = BP_CountNullTerminatedPtrArray(table_path);
	if(!path_entry_count)
	{
		return NULL;
	}
	P_BP_HASH_TABLE_KEYED_ENTRY found_table = NULL;
	size_t path_entry_iter = 0;
	P_BP_HASH_TABLE_KEYED_ENTRY lookup_position = hreg->hive;
	if(!lookup_position)
	{
		return NULL;
	}
	for
	(
		;
		path_entry_iter < path_entry_count && lookup_position;
		path_entry_iter++
	)
	{
		if(!lookup_position->hh.tbl)
		{
			return NULL;
		}
		found_table = NULL;
		HASH_FIND
		(
			hh,
			lookup_position,
			table_path[path_entry_iter],
			bpstrlen(table_path[path_entry_iter]),
			found_table
		);
		if(!found_table)
			return NULL;
		if(found_table->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
			return NULL;
		if(path_entry_count == 1)
			return found_table;
		if(path_entry_iter == (path_entry_count-1))
		{
			return found_table;
		}
		lookup_position = (P_BP_HASH_TABLE_KEYED_ENTRY) found_table->data;
		if(!lookup_position)
			break;
	}
	if(path_entry_iter == (path_entry_count-1))
		return found_table;
	return NULL;
}
P_BP_HASH_TABLE_KEYED_ENTRY BP_HashRegLookupTableByPath ( P_BP_HASH_TABLE_REGISTRY hreg , BP_HASH_TABLE_TRAVERSAL_PATH table_path ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( NULL ) ; if ( ! table_path ) return NULL ; if ( ! table_path [ 0 ] ) return NULL ; size_t path_entry_count = BP_CountNullTerminatedPtrArray ( table_path ) ; if ( ! path_entry_count ) { return NULL ; } P_BP_HASH_TABLE_KEYED_ENTRY found_table = NULL ; size_t path_entry_iter = 0 ; P_BP_HASH_TABLE_KEYED_ENTRY lookup_position = hreg -> hive ; if ( ! lookup_position ) { return NULL ; } for ( ; path_entry_iter < path_entry_count && lookup_position ; path_entry_iter ++ ) { if ( ! lookup_position -> hh . tbl ) { return NULL ; } found_table = NULL ; HASH_FIND ( hh , lookup_position , table_path [ path_entry_iter ] , bpstrlen ( table_path [ path_entry_iter ] ) , found_table ) ; if ( ! found_table ) return NULL ; if ( found_table -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) return NULL ; if ( path_entry_count == 1 ) return found_table ; if ( path_entry_iter == ( path_entry_count - 1 ) ) { return found_table ; } lookup_position = ( P_BP_HASH_TABLE_KEYED_ENTRY ) found_table -> data ; if ( ! lookup_position ) break ; } if ( path_entry_iter == ( path_entry_count - 1 ) ) return found_table ; return NULL ; }
Will search a traversal path for a table.
Will search a traversal path for a table .
// macro to override hreg on null // ensure we have a search path // count the number of entries in the table // local storage point for lookup // iterator for the path entry positions // The current lookup position within the lookup loop below.  Used for discovering // nested tables. // attempt to lookup the table by path // ensure we have our hash table values or exit immediately (hh is a static // structure and will always exist so long as lookup_position) is a structure // itself. // reset the found table on loop // attempt to lookup the table // if our lookup fails we can immediately exit the lookup // the type of the entry must be table.  If it's not, it's likely an abstract // type entry rather than a hash table entry.  Imagine it being like the record found // was a file in a directory, rather than a directory itself. // if the entry count is only 1 deep, we can just return the table itself // exit if we're in the correct position and we have a table entry // printf("\n At lookup position?!"); // printf("\n Lookup Table?: %s - %p: ", found_table->key, found_table->data); // BP_HashRegDisplayKeyPath(table_path); // return the found table here // advance the lookup position // advance the lookup position // return the found table if it was found at the correct // depth. // if no table was found at the correct depth, go ahead and exit