2023-06-30 21:23:40 -07:00
|
|
|
#pragma once
|
|
|
|
|
2023-07-18 21:13:12 -07:00
|
|
|
#if GEN_TIME
|
2023-06-30 21:23:40 -07:00
|
|
|
#include "gen.hpp"
|
2023-07-11 22:33:11 -07:00
|
|
|
#include "Array.Upfront.hpp"
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
using namespace gen;
|
|
|
|
|
|
|
|
Code gen__hashtable_base()
|
|
|
|
{
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeVar hashIndex = def_variable( t_sw, name(HashIndex) );
|
|
|
|
CodeVar entry_prev = def_variable( t_sw, name(PrevIndex) );
|
|
|
|
CodeVar entry_index = def_variable( t_sw, name(EntryIndex) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeStruct find_result = def_struct( name(HashTable_FindResult), def_struct_body( 3
|
2023-06-30 21:23:40 -07:00
|
|
|
, hashIndex
|
|
|
|
, entry_prev
|
|
|
|
, entry_index
|
|
|
|
));
|
|
|
|
|
|
|
|
return find_result;
|
|
|
|
}
|
|
|
|
|
2023-07-11 15:29:45 -07:00
|
|
|
Code gen__hashtable( StrC type )
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-15 13:13:44 -07:00
|
|
|
static CodeType t_allocator_info = def_type( name(AllocatorInfo) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType t_find_result = def_type( name(HashTable_FindResult) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
StringCached name;
|
|
|
|
{
|
|
|
|
char const* name_str = str_fmt_buf( "HashTable_%s", type.Ptr );
|
|
|
|
s32 len = str_len( name_str );
|
|
|
|
|
|
|
|
name = get_cached_string({ len, name_str });
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType t_ht_type = def_type( name );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType t_type = def_type( type );
|
|
|
|
CodeType t_type_ptr = def_type( type, __, spec_ptr );
|
|
|
|
CodeType t_type_ref = def_type( type, __, spec_ref );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
// Hash table depends on array container for its entry structure.
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType t_ht_entry, t_array_ht_entry;
|
|
|
|
CodeStruct ht_entry, array_ht_entry;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
|
|
|
char const* name_str = str_fmt_buf( "HashTable_%s_Entry", type.Ptr );
|
|
|
|
s32 len = str_len( name_str );
|
|
|
|
|
|
|
|
StringCached ht_entry_name = get_cached_string({ len, name_str });
|
|
|
|
|
|
|
|
t_ht_entry = def_type( ht_entry_name );
|
2023-07-12 00:41:16 -07:00
|
|
|
ht_entry = def_struct( ht_entry_name, def_struct_body( args(
|
|
|
|
def_variable( t_u64, name(Key))
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_variable( t_sw, name(Next))
|
|
|
|
, def_variable( t_type, name(Value))
|
2023-07-12 00:41:16 -07:00
|
|
|
)));
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-11 00:10:20 -07:00
|
|
|
array_ht_entry = gen__array( ht_entry_name );
|
2023-06-30 21:23:40 -07:00
|
|
|
t_array_ht_entry = def_type( array_ht_entry->Name );
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeStruct hashtable = {0};
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeUsing using_entry = def_using( name(Entry), t_ht_entry );
|
|
|
|
CodeUsing using_array_entry = def_using( name(Array_Entry), t_array_ht_entry );
|
|
|
|
CodeUsing using_find_result = def_using( name(FindResult), t_find_result );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType t_array_sw = def_type( name(Array_sw) );
|
|
|
|
CodeType t_array_entry = def_type( name(Array_Entry) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeVar hashes = def_variable( t_array_sw, name(Hashes) );
|
|
|
|
CodeVar entries = def_variable( t_array_entry, name(Entries));
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn init;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-11 22:33:11 -07:00
|
|
|
char const* tmpl = stringize(
|
2023-06-30 21:23:40 -07:00
|
|
|
<type> result = { 0 };
|
|
|
|
|
|
|
|
result.Hashes = Array_sw ::init( allocator );
|
|
|
|
result.Entries = Array_Entry::init( allocator );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
);
|
2023-07-11 22:33:11 -07:00
|
|
|
Code body = def_execution( token_fmt( "type", (StrC)name, tmpl ) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
init = def_function( name(init), def_param( t_allocator_info, name(allocator)), t_ht_type, body, spec_static_member );
|
|
|
|
}
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn init_reserve;
|
2023-07-11 22:33:11 -07:00
|
|
|
{
|
|
|
|
char const* tmpl = stringize(
|
|
|
|
<type> result = { { nullptr }, { nullptr } };
|
|
|
|
|
|
|
|
result.Hashes = Array_sw::init_reserve( allocator, num );
|
|
|
|
result.Hashes.get_header()->Num = num;
|
|
|
|
|
|
|
|
result.Entries = Array_Entry::init_reserve( allocator, num );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
);
|
|
|
|
Code body = def_execution( token_fmt( "type", (StrC)name, tmpl ) );
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeParam params = def_params( args( def_param( t_allocator_info, name(allocator)), def_param( t_sw, name(num))));
|
2023-07-11 22:33:11 -07:00
|
|
|
|
|
|
|
init_reserve = def_function( name(init_reserve), params, t_ht_type, body, spec_static_member );
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn clear = def_function( name(clear), __, t_void
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
2023-07-11 00:10:20 -07:00
|
|
|
for ( s32 idx = 0; idx < Hashes.num(); idx++ )
|
2023-06-30 21:23:40 -07:00
|
|
|
Hashes[ idx ] = -1;
|
|
|
|
|
|
|
|
Entries.clear();
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn destroy = def_function( name(destroy), __, t_void
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
2023-07-11 22:33:11 -07:00
|
|
|
if ( Hashes && Hashes.get_header()->Capacity )
|
2023-07-09 22:15:25 -07:00
|
|
|
Hashes.free();
|
2023-07-11 22:33:11 -07:00
|
|
|
if ( Entries && Hashes.get_header()->Capacity )
|
2023-06-30 21:23:40 -07:00
|
|
|
Entries.free();
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn get = def_function( name(get), def_param( t_u64, name(key)), t_type_ptr
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
|
|
|
sw idx = find( key ).EntryIndex;
|
2023-07-11 22:33:11 -07:00
|
|
|
if ( idx >= 0 )
|
2023-06-30 21:23:40 -07:00
|
|
|
return & Entries[ idx ].Value;
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeUsing using_map_proc;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-11 22:33:11 -07:00
|
|
|
char const* tmpl = stringize(
|
2023-06-30 21:23:40 -07:00
|
|
|
void (*) ( u64 key, <type> value )
|
|
|
|
);
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType value = def_type( token_fmt( "type", (StrC)t_type.to_string(), tmpl ) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
using_map_proc = def_using ( name(MapProc), value);
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn map;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType t_map_proc = def_type( name(MapProc) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
Code body = def_execution( code(
|
2023-07-15 19:27:38 -07:00
|
|
|
GEN_ASSERT_NOT_NULL( map_proc );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
for ( sw idx = 0; idx < Entries.num(); idx++ )
|
|
|
|
{
|
|
|
|
map_proc( Entries[ idx ].Key, Entries[ idx ].Value );
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
map = def_function( name(map), def_param( t_map_proc, name(map_proc) ), t_void, body );
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeUsing using_map_mut_proc;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-11 22:33:11 -07:00
|
|
|
char const* tmpl = stringize(
|
2023-06-30 21:23:40 -07:00
|
|
|
void (*) ( u64 key, <type> value )
|
|
|
|
);
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType value = def_type( token_fmt( "type", (StrC)t_type_ptr.to_string(), tmpl ) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
using_map_mut_proc = def_using ( name(MapMutProc), value);
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn map_mut;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeType t_map_mut_proc = def_type( name(MapMutProc));
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
Code body = def_execution( code(
|
2023-07-15 19:27:38 -07:00
|
|
|
GEN_ASSERT_NOT_NULL( map_proc );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
for ( sw idx = 0; idx < Entries.num(); idx++ )
|
|
|
|
{
|
|
|
|
map_proc( Entries[ idx ].Key, & Entries[ idx ].Value );
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
map_mut = def_function( name(map_mut), def_param( t_map_mut_proc, name(map_proc)), t_void, body );
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn grow = def_function( name(grow), __, t_void
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
|
|
|
sw new_num = array_grow_formula( Entries.num() );
|
|
|
|
rehash( new_num );
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn rehash;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-11 22:33:11 -07:00
|
|
|
char const* tmpl = stringize(
|
2023-06-30 21:23:40 -07:00
|
|
|
sw idx;
|
|
|
|
sw last_added_index;
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
<type> new_ht = init_reserve( Hashes.get_header()->Allocator, new_num );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
Array_sw::Header* hash_header = new_ht.Hashes.get_header();
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
for ( idx = 0; idx < new_ht.Hashes.num(); ++idx )
|
|
|
|
new_ht.Hashes[ idx ] = -1;
|
|
|
|
|
|
|
|
for ( idx = 0; idx < Entries.num(); ++idx )
|
|
|
|
{
|
|
|
|
Entry& entry = Entries[ idx ];
|
|
|
|
|
|
|
|
FindResult find_result;
|
|
|
|
|
|
|
|
if ( new_ht.Hashes.num() == 0 )
|
|
|
|
new_ht.grow();
|
|
|
|
|
|
|
|
entry = Entries[ idx ];
|
|
|
|
find_result = new_ht.find( entry.Key );
|
|
|
|
last_added_index = new_ht.add_entry( entry.Key );
|
|
|
|
|
|
|
|
if ( find_result.PrevIndex < 0 )
|
|
|
|
new_ht.Hashes[ find_result.HashIndex ] = last_added_index;
|
|
|
|
|
|
|
|
else
|
|
|
|
new_ht.Entries[ find_result.PrevIndex ].Next = last_added_index;
|
|
|
|
|
|
|
|
new_ht.Entries[ last_added_index ].Next = find_result.EntryIndex;
|
|
|
|
new_ht.Entries[ last_added_index ].Value = entry.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy();
|
2023-07-11 22:33:11 -07:00
|
|
|
*this = new_ht;
|
2023-06-30 21:23:40 -07:00
|
|
|
);
|
2023-07-11 22:33:11 -07:00
|
|
|
Code body = def_execution( token_fmt( "type", (StrC)name, tmpl ) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-11 00:10:20 -07:00
|
|
|
rehash = def_function( name(rehash), def_param( t_sw, name(new_num)), t_void, body );
|
2023-06-30 21:23:40 -07:00
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn rehash_fast;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-11 22:33:11 -07:00
|
|
|
char const* tmpl = stringize(
|
2023-06-30 21:23:40 -07:00
|
|
|
sw idx;
|
|
|
|
|
|
|
|
for ( idx = 0; idx < Entries.num(); idx++ )
|
|
|
|
Entries[ idx ].Next = -1;
|
|
|
|
|
|
|
|
for ( idx = 0; idx < Hashes.num(); idx++ )
|
|
|
|
Hashes[ idx ] = -1;
|
|
|
|
|
|
|
|
for ( idx = 0; idx < Entries.num(); idx++ )
|
|
|
|
{
|
|
|
|
Entry* entry;
|
|
|
|
|
|
|
|
FindResult find_result;
|
|
|
|
}
|
|
|
|
);
|
2023-07-11 22:33:11 -07:00
|
|
|
Code body = def_execution( token_fmt( "type", name, tmpl ) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
rehash_fast = def_function( name(rehash_fast), __, t_void, body );
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn remove = def_function( name(remove), def_param( t_u64, name(key)), t_void
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
|
|
|
FindResult find_result = find( key);
|
|
|
|
|
|
|
|
if ( find_result.EntryIndex >= 0 )
|
|
|
|
{
|
|
|
|
Entries.remove_at( find_result.EntryIndex );
|
|
|
|
rehash_fast();
|
|
|
|
}
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn remove_entry = def_function( name(remove_entry), def_param( t_sw, name(idx)), t_void
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
|
|
|
Entries.remove_at( idx );
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn set;
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeParam params = def_params( args(
|
2023-07-12 00:41:16 -07:00
|
|
|
def_param( t_u64, name(key))
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_param( t_type, name(value))
|
2023-07-12 00:41:16 -07:00
|
|
|
));
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
Code body = def_execution( code(
|
|
|
|
sw idx;
|
|
|
|
FindResult find_result;
|
|
|
|
|
|
|
|
if ( Hashes.num() == 0 )
|
|
|
|
grow();
|
|
|
|
|
|
|
|
find_result = find( key );
|
|
|
|
|
|
|
|
if ( find_result.EntryIndex >= 0 )
|
|
|
|
{
|
|
|
|
idx = find_result.EntryIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = add_entry( key );
|
|
|
|
|
|
|
|
if ( find_result.PrevIndex >= 0 )
|
|
|
|
{
|
|
|
|
Entries[ find_result.PrevIndex ].Next = idx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Hashes[ find_result.HashIndex ] = idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Entries[ idx ].Value = value;
|
|
|
|
|
|
|
|
if ( full() )
|
|
|
|
grow();
|
|
|
|
));
|
|
|
|
|
|
|
|
set = def_function( name(set), params, t_void, body );
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn slot = def_function( name(slot), def_param( t_u64, name(key)), t_sw
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
|
|
|
for ( sw idx = 0; idx < Hashes.num(); ++idx )
|
|
|
|
if ( Hashes[ idx ] == key )
|
|
|
|
return idx;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn add_entry = def_function( name(add_entry), def_param( t_u64, name(key)), t_sw
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
|
|
|
sw idx;
|
|
|
|
Entry entry = { key, -1 };
|
|
|
|
|
|
|
|
idx = Entries.num();
|
|
|
|
Entries.append( entry );
|
|
|
|
return idx;
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn find = def_function( name(find), def_param( t_u64, name(key)), t_find_result
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
|
|
|
FindResult result = { -1, -1, -1 };
|
|
|
|
|
|
|
|
if ( Hashes.num() > 0 )
|
|
|
|
{
|
|
|
|
result.HashIndex = key % Hashes.num();
|
|
|
|
result.EntryIndex = Hashes[ result.HashIndex ];
|
|
|
|
|
|
|
|
while ( result.EntryIndex >= 0 )
|
|
|
|
{
|
|
|
|
if ( Entries[ result.EntryIndex ].Key == key )
|
|
|
|
break;
|
|
|
|
|
|
|
|
result.PrevIndex = result.EntryIndex;
|
|
|
|
result.EntryIndex = Entries[ result.EntryIndex ].Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-15 13:13:44 -07:00
|
|
|
CodeFn full = def_function( name(full), __, t_b32
|
2023-06-30 21:23:40 -07:00
|
|
|
, def_execution( code(
|
|
|
|
return 0.75f * Hashes.num() < Entries.num();
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
2023-07-12 00:41:16 -07:00
|
|
|
hashtable = def_struct( name, def_struct_body( args(
|
2023-07-12 12:59:47 -07:00
|
|
|
using_entry
|
2023-06-30 21:23:40 -07:00
|
|
|
, using_array_entry
|
|
|
|
, using_find_result
|
|
|
|
, using_map_proc
|
|
|
|
, using_map_mut_proc
|
|
|
|
|
|
|
|
, init
|
2023-07-11 22:33:11 -07:00
|
|
|
, init_reserve
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
, clear
|
|
|
|
, destroy
|
|
|
|
, get
|
|
|
|
, grow
|
|
|
|
, map
|
|
|
|
, map_mut
|
|
|
|
, rehash
|
|
|
|
, rehash_fast
|
|
|
|
, remove
|
|
|
|
, remove_entry
|
|
|
|
, set
|
|
|
|
, slot
|
|
|
|
|
|
|
|
, hashes
|
|
|
|
, entries
|
|
|
|
|
|
|
|
, access_protected
|
|
|
|
, add_entry
|
|
|
|
, find
|
|
|
|
, full
|
2023-07-12 00:41:16 -07:00
|
|
|
)));
|
2023-06-30 21:23:40 -07:00
|
|
|
}
|
|
|
|
|
2023-07-12 00:41:16 -07:00
|
|
|
return def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
2023-06-30 21:23:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct GenHashTableRequest
|
|
|
|
{
|
|
|
|
StrC Dependency;
|
|
|
|
StrC Type;
|
|
|
|
};
|
2023-07-11 15:29:45 -07:00
|
|
|
Array<GenHashTableRequest> GenHashTableRequests;
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-11 15:29:45 -07:00
|
|
|
void gen__hashtable_request( StrC type, StrC dep = {} )
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
|
|
|
do_once_start
|
2023-07-29 13:00:06 -07:00
|
|
|
GenHashTableRequests = Array<GenHashTableRequest>::init( GlobalAllocator );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
gen_array( sw );
|
|
|
|
do_once_end
|
|
|
|
|
|
|
|
// Make sure we don't already have a request for the type.
|
2023-07-11 15:29:45 -07:00
|
|
|
for ( sw idx = 0; idx < GenHashTableRequests.num(); ++idx )
|
2023-06-30 21:23:40 -07:00
|
|
|
{
|
|
|
|
StrC const reqest_type = GenHashTableRequests[ idx ].Type;
|
|
|
|
|
|
|
|
if ( reqest_type.Len != type.Len )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( str_compare( reqest_type.Ptr, type.Ptr, reqest_type.Len ) == 0 )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-11 15:29:45 -07:00
|
|
|
GenHashTableRequest request = { dep, type };
|
|
|
|
GenHashTableRequests.append( request );
|
2023-06-30 21:23:40 -07:00
|
|
|
}
|
2023-07-11 22:33:11 -07:00
|
|
|
#define gen_hashtable( type ) gen__hashtable_request( code(type))
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
u32 gen_hashtable_file()
|
|
|
|
{
|
|
|
|
Builder
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_hashtable_file;
|
|
|
|
gen_hashtable_file.open( "hashtable.Upfront.gen.hpp" );
|
|
|
|
|
2023-07-15 19:27:38 -07:00
|
|
|
gen_hashtable_file.print( def_include( txt_StrC("gen.hpp")) );
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_hashtable_file.print( def_include( txt_StrC("Array.Upfront.hpp")) );
|
|
|
|
gen_hashtable_file.print( def_include( txt_StrC("array.Upfront.gen.hpp")) );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_hashtable_file.print( def_using_namespace( name(gen)));
|
2023-06-30 21:23:40 -07:00
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_hashtable_file.print( gen__hashtable_base());
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
GenHashTableRequest* current = GenHashTableRequests;
|
2023-07-11 15:29:45 -07:00
|
|
|
s32 left = GenHashTableRequests.num();
|
2023-06-30 21:23:40 -07:00
|
|
|
while (left--)
|
|
|
|
{
|
|
|
|
GenHashTableRequest const& request = * current;
|
|
|
|
|
2023-07-11 15:29:45 -07:00
|
|
|
Code generated_buffer = gen__hashtable( current->Type );
|
2023-06-30 21:23:40 -07:00
|
|
|
|
|
|
|
if ( request.Dependency )
|
|
|
|
{
|
|
|
|
char const* cmt_str = str_fmt_buf( "// Dependency for %s type", request.Type );
|
|
|
|
s32 cmt_len = str_len( cmt_str );
|
|
|
|
|
|
|
|
Code cmt = def_comment( { cmt_len, cmt_str } );
|
|
|
|
Code include = def_include( request.Dependency );
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_hashtable_file.print( cmt );
|
|
|
|
gen_hashtable_file.print( include );
|
2023-06-30 21:23:40 -07:00
|
|
|
}
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_hashtable_file.print( generated_buffer );
|
2023-06-30 21:23:40 -07:00
|
|
|
current++;
|
|
|
|
}
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_hashtable_file.write();
|
2023-06-30 21:23:40 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-07-18 21:13:12 -07:00
|
|
|
#endif // GEN_TIME
|