An hash array dictonary step by step
#29
(04-14-2023, 05:18 PM)bplus Wrote: What's throwing me off is that the way I learned a Dictionary Structure it has 2 parts for each item,  a Key and a Value for that Key.
1) Key is lookup Identifier like names of variables or colors or words 
2) the associated value(s) would be qualities of the name, values for the variable, or colors in _RGB32 say for the color name or definitions for word keys. 

So Steve's example is too simple. It is a regular dictionary function you would use for checking if words existed in a given dictionary. You aren't even getting the associated definition for a word. It's very nice for what it is though. Smile

ref:
https://en.wikibooks.org/wiki/A-level_Co...ctionaries

Aye.  I was just showing how I'd tend to link more items onto the same hash entry, so I wanted to keep it nice and simple to just highlight that type of usage.  For the associative values, I'd tend to do the same thing, except I'd structure my data so that the associative data came after the dictionary data.

Foe example, let's say I was working with color values, such as you mention above.  The DictValue would stay the same, but when I wrote my data, I'd write it as:

CHR$(0) + color$ + chr$(0) + color_value + chr$(1)

Thus when I did my lookup, I'd simply look for the CHR$(0) + color$ + CHR$(0) value as I'm doing now, to find my dictionary key, and then I'd grab the color value from that last CHR$(0) until the CHR$(1).

It's basically the combination of a linked list with a hash table, allowing for a quick search and lookup for the items inside them.  

My philosophy tends to be:  When showing a demo or an example of something, try to focus *only* on what you're wanting to demonstrate as much as possible and leave anything extra for later.  Wink  What I was showing here was what Matt was talking about with:

Quote:Now if you _want_ to be able to add multiple entries with the same key my bucket approach is better but neither are really suited for it. What you'd probably want is to create a linked list for each set of entries with the same key. For my approach, that means adding another link next to
nxt
that points to entries with the same key, making each bucket a bit of a "list of lists". You could also do this with Luke's approach but I think it would require a separate array to store the links for the list of entries with the same key. It's definitely doable though.

That said, I'd probably call this the user's problem [Image: biggrin.png] A hash table doesn't really need to support this natively, you can always modify the
Value
Type to hold a list and get the same thing.
Reply


Messages In This Thread
RE: An hash array dictonary step by step - by SMcNeill - 04-14-2023, 11:24 PM



Users browsing this thread: 3 Guest(s)