lookuptable 0.1.4
Static lookup table for an array of values
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Simple library to generate a static lookup table.
Sometimes you want to generate a lookup table for something. And that lookup table is initialized once and never changes. If you use an AA, it can generate a lot of needless allocations as it's growing the buckets. Not only that, but the items themselves are individual allocations in the GC. If you have a lookup table of 100 items, that's a minimum of 101 allocations, cwhich can put a tax on the GC especially if you only intend to use it for a short time.
This lookup table is generated from known data -- the data must already be known before generating the table, and must have a length. Therefore, it knows how much buckets to allocate, and it can do all in one allocation, reducing the GC load when collecting.
It should be slightly faster than an AA, and much less taxing on GC collections.
Future improvements may include RAII possibilities (using malloc).
An example use case may be an array of headers read from an HTTP connection, where you want to look up values based on the header name. You read the headers into an array, and then generate a lookup table based on that.
There are 2 functions in here. indexLookup
returns the mapping of the item in the given random access range to its index. fieldLookup
is for values that have fields, or for using a lambda to generate the keys from the items. This version of the library will return the original item, but is indexed based on a field name, or based on a lambda to generate the key.
Docs may be filled out at some point if I feel this needs more polish.
- 0.1.4 released 3 years ago
- schveiguy/lookuptable
- Boost
- Copyright © 2019, Steven Schveighoffer
- Authors:
- Dependencies:
- none
- Versions:
-
0.1.4 2021-Feb-01 0.1.3 2020-Apr-22 0.1.2 2020-Mar-30 0.1.1 2020-Mar-26 0.1.0 2020-Mar-26 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
55 downloads total
-
- Score:
- 0.7
- Short URL:
- lookuptable.dub.pm