file equality finally set up correctly
This commit is contained in:
parent
49f5f84c32
commit
08b69a6630
|
@ -23,7 +23,6 @@ NOTES ON USE:
|
||||||
// - comments
|
// - comments
|
||||||
// - memcpy / memmove replacements (different file for optimization options?)
|
// - memcpy / memmove replacements (different file for optimization options?)
|
||||||
// - examples and docs
|
// - examples and docs
|
||||||
// - finish a full set of tools for file name handling
|
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "4coder_config.h"
|
#include "4coder_config.h"
|
||||||
|
|
189
4ed_file.cpp
189
4ed_file.cpp
|
@ -181,29 +181,6 @@ struct Non_File_Table_Entry{
|
||||||
File_ID id;
|
File_ID id;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct File_Table_Entry{
|
|
||||||
Unique_Hash key;
|
|
||||||
File_ID id;
|
|
||||||
};
|
|
||||||
|
|
||||||
internal u32
|
|
||||||
tbl_file_hash(void *item, void *arg){
|
|
||||||
Unique_Hash uhash = *((Unique_Hash*)item);
|
|
||||||
u32 hash = uhash.d[0] + 101;
|
|
||||||
hash = ((hash << 6) + hash) + uhash.d[1];
|
|
||||||
hash = ((hash << 6) + hash) + uhash.d[2];
|
|
||||||
hash = ((hash << 6) + hash) + uhash.d[3];
|
|
||||||
return(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal i32
|
|
||||||
tbl_file_compare(void *a, void *b, void *arg){
|
|
||||||
Unique_Hash ahash = *((Unique_Hash*)a);
|
|
||||||
Unique_Hash bhash = *((Unique_Hash*)b);
|
|
||||||
i32 result = !uhash_equal(ahash, bhash);
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct File_Array{
|
struct File_Array{
|
||||||
Editing_File *files;
|
Editing_File *files;
|
||||||
i32 size;
|
i32 size;
|
||||||
|
@ -217,7 +194,6 @@ struct Working_Set{
|
||||||
File_Node free_sentinel;
|
File_Node free_sentinel;
|
||||||
File_Node used_sentinel;
|
File_Node used_sentinel;
|
||||||
|
|
||||||
Table non_file_table;
|
|
||||||
Table table;
|
Table table;
|
||||||
|
|
||||||
String clipboards[64];
|
String clipboards[64];
|
||||||
|
@ -225,6 +201,42 @@ struct Working_Set{
|
||||||
i32 clipboard_current, clipboard_rolling;
|
i32 clipboard_current, clipboard_rolling;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct File_Entry{
|
||||||
|
String short_name;
|
||||||
|
String long_name;
|
||||||
|
File_ID id;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct File_Entry_Comparison{
|
||||||
|
File_Entry entry;
|
||||||
|
Unique_Hash hash;
|
||||||
|
b32 use_hash;
|
||||||
|
};
|
||||||
|
|
||||||
|
internal i32
|
||||||
|
tbl_file_compare(void *a, void *b, void *arg){
|
||||||
|
File_Entry_Comparison *fa = (File_Entry_Comparison*)a;
|
||||||
|
File_Entry *fb = (File_Entry*)b;
|
||||||
|
System_Functions *system = (System_Functions*)arg;
|
||||||
|
Unique_Hash uhash;
|
||||||
|
i32 result = 1;
|
||||||
|
b32 success;
|
||||||
|
|
||||||
|
if (fa->use_hash){
|
||||||
|
uhash = system->file_unique_hash(fb->long_name, &success);
|
||||||
|
if (success && uhash_equal(uhash, fa->hash)){
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (match(fa->entry.short_name, fb->short_name)){
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
working_set_extend_memory(Working_Set *working_set, Editing_File *new_space, i16 number_of_files){
|
working_set_extend_memory(Working_Set *working_set, Editing_File *new_space, i16 number_of_files){
|
||||||
File_ID id;
|
File_ID id;
|
||||||
|
@ -342,59 +354,16 @@ working_set_get_active_file(Working_Set *working_set, i32 id){
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Editing_File*
|
|
||||||
working_set_contains_file(Working_Set *working_set, Unique_Hash file_hash){
|
|
||||||
Editing_File *result = 0;
|
|
||||||
File_Table_Entry *entry = 0;
|
|
||||||
|
|
||||||
entry = (File_Table_Entry*)table_find_item(
|
|
||||||
&working_set->table, &file_hash, 0, tbl_file_hash, tbl_file_compare);
|
|
||||||
if (entry){
|
|
||||||
result = working_set_index(working_set, entry->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Editing_File*
|
|
||||||
working_set_contains_non_file(Working_Set *working_set, String filename){
|
|
||||||
Editing_File *result = 0;
|
|
||||||
Non_File_Table_Entry *entry = 0;
|
|
||||||
|
|
||||||
entry = (Non_File_Table_Entry*)table_find_item(
|
|
||||||
&working_set->non_file_table, &filename, 0, tbl_string_hash, tbl_string_compare);
|
|
||||||
if (entry){
|
|
||||||
result = working_set_index(working_set, entry->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Editing_File*
|
|
||||||
working_set_contains(System_Functions *system, Working_Set *working_set, String filename){
|
|
||||||
Unique_Hash file_hash;
|
|
||||||
Editing_File *result;
|
|
||||||
b32 success = 0;
|
|
||||||
//terminate_with_null(&filename);
|
|
||||||
file_hash = system->file_unique_hash(filename, &success);
|
|
||||||
if (success){
|
|
||||||
result = working_set_contains_file(working_set, file_hash);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
result = working_set_contains_non_file(working_set, filename);
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
working_set_init(Working_Set *working_set, Partition *partition, General_Memory *general){
|
working_set_init(Working_Set *working_set, Partition *partition, General_Memory *general){
|
||||||
i16 init_count = 16;
|
|
||||||
i16 array_init_count = 256;
|
|
||||||
|
|
||||||
Editing_File *files, *null_file;
|
Editing_File *files, *null_file;
|
||||||
void *mem;
|
void *mem;
|
||||||
i32 mem_size, table_size;
|
i32 mem_size, table_size;
|
||||||
|
|
||||||
|
i32 item_size = sizeof(File_Entry);
|
||||||
|
i16 init_count = 16;
|
||||||
|
i16 array_init_count = 256;
|
||||||
|
|
||||||
dll_init_sentinel(&working_set->free_sentinel);
|
dll_init_sentinel(&working_set->free_sentinel);
|
||||||
dll_init_sentinel(&working_set->used_sentinel);
|
dll_init_sentinel(&working_set->used_sentinel);
|
||||||
|
|
||||||
|
@ -410,20 +379,14 @@ working_set_init(Working_Set *working_set, Partition *partition, General_Memory
|
||||||
++working_set->file_count;
|
++working_set->file_count;
|
||||||
|
|
||||||
table_size = working_set->file_max;
|
table_size = working_set->file_max;
|
||||||
mem_size = table_required_mem_size(table_size, sizeof(File_Table_Entry));
|
mem_size = table_required_mem_size(table_size, item_size);
|
||||||
mem = general_memory_allocate(general, mem_size, 0);
|
mem = general_memory_allocate(general, mem_size, 0);
|
||||||
memset(mem, 0, mem_size);
|
memset(mem, 0, mem_size);
|
||||||
table_init_memory(&working_set->table, mem, table_size, sizeof(File_Table_Entry));
|
table_init_memory(&working_set->table, mem, table_size, item_size);
|
||||||
|
|
||||||
table_size = working_set->file_max; // / 4;
|
|
||||||
mem_size = table_required_mem_size(table_size, sizeof(Non_File_Table_Entry));
|
|
||||||
mem = general_memory_allocate(general, mem_size, 0);
|
|
||||||
memset(mem, 0, mem_size);
|
|
||||||
table_init_memory(&working_set->non_file_table, mem, table_size, sizeof(Non_File_Table_Entry));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
working_set_grow_if_needed(Table *table, General_Memory *general, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){
|
working_set__grow_if_needed(Table *table, General_Memory *general, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){
|
||||||
Table btable;
|
Table btable;
|
||||||
i32 new_max, mem_size;
|
i32 new_max, mem_size;
|
||||||
void *mem;
|
void *mem;
|
||||||
|
@ -441,57 +404,39 @@ working_set_grow_if_needed(Table *table, General_Memory *general, void *arg, Has
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
working_set_add_file(Working_Set *working_set, Unique_Hash key, File_ID file_id, General_Memory *general){
|
working_set__entry_comp(System_Functions *system, String filename, File_Entry_Comparison *out){
|
||||||
File_Table_Entry entry;
|
out->entry.long_name = filename;
|
||||||
entry.key = key;
|
out->entry.short_name = front_of_directory(filename);
|
||||||
entry.id = file_id;
|
out->hash = system->file_unique_hash(filename, &out->use_hash);
|
||||||
working_set_grow_if_needed(&working_set->table, general, 0, tbl_file_hash, tbl_file_compare);
|
|
||||||
table_add(&working_set->table, &entry, 0, tbl_file_hash, tbl_file_compare);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline Editing_File*
|
||||||
working_set_add_non_file(Working_Set *working_set, String filename, File_ID file_id, General_Memory *general){
|
working_set_contains(System_Functions *system, Working_Set *working_set, String filename){
|
||||||
Non_File_Table_Entry entry;
|
File_Entry_Comparison entry_comp;
|
||||||
entry.name = filename;
|
File_Entry *entry;
|
||||||
entry.id = file_id;
|
Editing_File *result = 0;
|
||||||
working_set_grow_if_needed(&working_set->table, general, 0, tbl_string_hash, tbl_string_compare);
|
working_set__entry_comp(system, filename, &entry_comp);
|
||||||
table_add(&working_set->non_file_table, &entry, 0, tbl_string_hash, tbl_string_compare);
|
entry = (File_Entry*)table_find_item(&working_set->table, &entry_comp, system, tbl_string_hash, tbl_file_compare);
|
||||||
|
if (entry){
|
||||||
|
result = working_set_index(working_set, entry->id);
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
working_set_add(System_Functions *system, Working_Set *working_set, Editing_File *file, General_Memory *general){
|
working_set_add(System_Functions *system, Working_Set *working_set, Editing_File *file, General_Memory *general){
|
||||||
Unique_Hash file_hash;
|
File_Entry_Comparison entry_comp;
|
||||||
b32 success = 0;
|
working_set__grow_if_needed(&working_set->table, general, system, tbl_string_hash, tbl_file_compare);
|
||||||
file_hash = system->file_unique_hash(file->name.source_path, &success);
|
working_set__entry_comp(system, file->name.source_path, &entry_comp);
|
||||||
if (success){
|
entry_comp.entry.id = file->id;
|
||||||
working_set_add_file(working_set, file_hash, file->id, general);
|
table_add(&working_set->table, &entry_comp, system, tbl_string_hash, tbl_file_compare);
|
||||||
}
|
|
||||||
else{
|
|
||||||
working_set_add_non_file(working_set, file->name.source_path, file->id, general);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void
|
|
||||||
working_set_remove_file(Working_Set *working_set, Unique_Hash file_hash){
|
|
||||||
table_remove_match(&working_set->table, &file_hash, 0, tbl_file_hash, tbl_file_compare);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void
|
|
||||||
working_set_remove_non_file(Working_Set *working_set, String filename){
|
|
||||||
table_remove_match(&working_set->non_file_table, &filename, 0, tbl_string_hash, tbl_string_compare);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
working_set_remove(System_Functions *system, Working_Set *working_set, String filename){
|
working_set_remove(System_Functions *system, Working_Set *working_set, String filename){
|
||||||
Unique_Hash file_hash;
|
File_Entry_Comparison entry_comp;
|
||||||
b32 success = 0;
|
working_set__entry_comp(system, filename, &entry_comp);
|
||||||
file_hash = system->file_unique_hash(filename, &success);
|
table_remove_match(&working_set->table, &entry_comp, system, tbl_string_hash, tbl_file_compare);
|
||||||
if (success){
|
|
||||||
working_set_remove_file(working_set, file_hash);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
working_set_remove_non_file(working_set, filename);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(allen): Pick better first options.
|
// TODO(allen): Pick better first options.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
"w:\4ed\misc\build_exp.bat" /Zi
|
REM "w:\4ed\misc\build_exp.bat" /Zi
|
||||||
REM "w:\4ed\misc\build_all.bat" /DFRED_SUPER /DFRED_NOT_PACKAGE /Zi
|
"w:\4ed\misc\build_all.bat" /DFRED_SUPER /DFRED_NOT_PACKAGE /Zi
|
||||||
REM "w:\4ed\misc\build_all.bat" /O2 /Zi
|
REM "w:\4ed\misc\build_all.bat" /O2 /Zi
|
||||||
|
|
Loading…
Reference in New Issue