digitalmars.D.announce - lookuptable
- Steven Schveighoffer (9/9) Apr 22 2020 Just wanted to throw this out there on a slow day. I wrote this little
- Sebastiaan Koppe (5/14) Apr 22 2020 Nice.
- Sebastiaan Koppe (3/5) Apr 22 2020 That is not quite true, only for strings.
- Steven Schveighoffer (13/30) Apr 22 2020 Hm... thanks for the suggestion. I'm not sure if it fits here, as the
- Sebastiaan Koppe (12/20) Apr 23 2020 Granted, it was far-fetched.
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 -Steve
Apr 22 2020
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 -SteveNice. For the indexLookup you can also use https://github.com/skoppe/perfect-hash
Apr 22 2020
On Wednesday, 22 April 2020 at 21:21:31 UTC, Sebastiaan Koppe wrote:For the indexLookup you can also use https://github.com/skoppe/perfect-hashThat is not quite true, only for strings.
Apr 22 2020
On 4/22/20 5:21 PM, Sebastiaan Koppe wrote:On Wednesday, 22 April 2020 at 20:27:12 UTC, Steven Schveighoffer wrote: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. -SteveJust 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/lookuptableNice. For the indexLookup you can also use https://github.com/skoppe/perfect-hash
Apr 22 2020
On Thursday, 23 April 2020 at 04:29:12 UTC, Steven Schveighoffer wrote: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.Granted, it was far-fetched.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.Yeah, that is quite crappy. I remember mapping each row to a struct and use member access, but then you have to sync the struct and the query yourself. It doesn't have to be short-lived though. Most apps process the same set of queries, so pre-creating all your prepared statements and mappings might make sense. I am not sure about mysql, but postgres gives you back the columns and types after preparing a statement, so you could do some runtime mapping once at startup (and at each reconnect).
Apr 23 2020