lookuptable

Steven Schveighoffer schveiguy at gmail.com
Thu Apr 23 04:29:12 UTC 2020


On 4/22/20 5:21 PM, Sebastiaan Koppe wrote:
> On Wednesday, 22 April 2020 at 20:27:12 UTC, Steven Schveighoffer wrote:
>> Just wanted to throw this out there on a slow day. I wrote this little 
>> utility to generate static lookup tables, because using an AA is too 
>> expensive for something like e.g. looking up database row data by 
>> column name.
>>
>> It's very crude, but very short and sweet. Hopefully people find a use 
>> for it.
>>
>> Let me know if you have any requests or find any bugs on github.
>>
>> https://code.dlang.org/packages/lookuptable
>>
> 
> Nice.
> 
> For the indexLookup you can also use https://github.com/skoppe/perfect-hash

Hm... thanks for the suggestion. I'm not sure if it fits here, as the 
point is to avoid runtime cost and GC allocation, not make lookups 
uber-fast.

These are meant to be short-lived things. My main target was e.g. 
mysql-native has an "asAA" function which generates an AA with keys 
being the column names. This is kind of crappy, because if you do that 
for each row, then you are generating and throwing away a LOT of data.

But if you generate the lookup index once per sequence, and you reuse 
that, you have much more efficiency, and are only generating one array. 
Possibly if I can figure out a good API, you could do it with 
malloc/free instead of using GC, but I'm happy with it right now anyway.

-Steve


More information about the Digitalmars-d-announce mailing list