A couple of questions about arrays and slices
Cecil Ward
cecil at cecilward.com
Sat Jun 24 07:43:53 UTC 2023
On Saturday, 24 June 2023 at 07:36:26 UTC, Cecil Ward wrote:
> Jonathan, is it possible that I wanted one thing and got
> another? My description in the earlier post was of the _aim_ of
> the program. What I ended up with might be something else? I
> wanted an array of uints whose values are the results/outputs
> of the mapping function. Since it is keyed by strings I assumed
> that the runtime generates some kind of hash for fast lookup
> when I ask it to retrieve an entry by the string (key)
> associated with it. I assumed that in some sense the hashing
> was sort of separate with some degree of independence from the
> underlying array, if that makes sense. The lookup is just
> assumed to be fast but how it is done we don’t really care. I
> just wanted to expand the array as I did successfully elsewhere
> with reserve, as I built this structure by successive additions
> of data. I have a number of strings and the map is meant to
> output the ordinal number in which I first saw them,
> zero-based. Then I want to come back and randomly look up one
> ordinal given a string preferably with a very fast lookup. The
> number of entries can not practically be more than 30, and even
> that would be highly unusual, maybe ten is the practical limit
> in my particular case, so it’s hardly MySQL.
I just realised something, your point about altering the table
and having to rehash, is well taken. I hadn’t considered that.
The reason for my foolishness in failing to realise that I’m
asking the impractical is my pattern of usage. I add all the
entries into the mapping table and have no interest in any
lookups until it is fully built. Then a second function starts to
do lookups while the data remains unchanging and that usage
pattern can be guaranteed. I could even idup it if that would
help, as copying < 32 uints wouldn’t take forever. A typical
value would be a mere 5 or less. I only picked 32 to be
completely safely ott.
More information about the Digitalmars-d-learn
mailing list