Can I use data structures like dictionaries in templates?

The file I want to analyze is in an archive format, with file names listed as null-terminated strings at a specific location.
I intend to specify these file names as comments. To correctly retrieve the file names, I need to find the index values associated with the file offsets in the header table.

Unfortunately, the header table is not sorted, so I can’t retrieve the values immediately. I tried using a brute-force approach with a for loop, but since the number of files is in the tens of thousands, this process takes a very long time.

I would like to use data structures like dictionaries or hashmaps from other languages to map offsets to indices for quick retrieval. However, it seems that this isn’t possible in templates.

I’m not sure if I’m thinking about this correctly, but are there any features that could help with this task?

Thanks you

There may be a few different ways to get this to work. Are you creating a <comment=…> function for a struct and is most of your computation work inside that comment function? If so, note that the comment function is only called whenever data needs to be displayed in the Template Results table (it is called in real-time and on-demand). Inside the struct you may be able to created a cached value, for example, ‘local int cachedIndex = -1;’ and then in the comment function only calculate the index and store the index if the value is -1.

010 Editor does not have built-in support for hash-maps but data structures can be created using local structs. For example, you could create a dictionary something like this:

typedef local struct {
    string str;
    int    index;
} DICT <optimize=false>;

local int dictSize = 1000;
DICT dict[dictSize];
dict[0].str = "First";
dict[1].str = "Second";

One thing 010 Editor is not able to do right now is resizing arrays and you have to know the size of the array before you create the data structure. Resizing will be coming in the future. If you want to post up some code we can take a look or you can also email to ‘support@sweetscape.com’ if the code is not public.

Graeme
SweetScape Software

I didn’t realize that the comment function gets executed every time it’s displayed. This method works really well!

I didn’t realize that the comment function gets executed every time it’s displayed. This method works really well!

Thank you!