library/src/datastructures/BP-HashTable.cc
// Will search a traversal path for a table.  Returns NULL if the table cannot be found.  Type must not
// be a table.
Will search a traversal path for a table.  Returns NULL if the table cannot be found.  Type must not
be a table.
Will search a traversal path for a table . Returns NULL if the table cannot be found . Type must not be a table .
P_BP_HASH_TABLE_KEYED_ENTRY BP_HashRegLookupTableEntryByPath
(
	P_BP_HASH_TABLE_REGISTRY      hreg,
	BP_HASH_TABLE_TRAVERSAL_PATH  entry_path
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(NULL);
	if(!entry_path)
		return NULL;
	if(!entry_path[0])
		return NULL;
	size_t path_entry_count = BP_CountNullTerminatedPtrArray(entry_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,
			entry_path[path_entry_iter],
			bpstrlen(entry_path[path_entry_iter]),
			found_table
		);
		if(!found_table)
			return NULL;
		if(path_entry_iter == (path_entry_count-1))
		{
			if(found_table->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
				return found_table;
			else
				return NULL;
		}
		if(found_table->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
			return NULL;
		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_HashRegLookupTableEntryByPath ( P_BP_HASH_TABLE_REGISTRY hreg , BP_HASH_TABLE_TRAVERSAL_PATH entry_path ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( NULL ) ; if ( ! entry_path ) return NULL ; if ( ! entry_path [ 0 ] ) return NULL ; size_t path_entry_count = BP_CountNullTerminatedPtrArray ( entry_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 , entry_path [ path_entry_iter ] , bpstrlen ( entry_path [ path_entry_iter ] ) , found_table ) ; if ( ! found_table ) return NULL ; if ( path_entry_iter == ( path_entry_count - 1 ) ) { if ( found_table -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) return found_table ; else return NULL ; } if ( found_table -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) return NULL ; 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 (not just table, contains final entry as well) // 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 // if the entry count is only 1 deep, we can just return the table itself // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Advance Table %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 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. // 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