04-02-2023, 06:43 PM
(04-02-2023, 05:27 PM)TempodiBasic Wrote: Hi MadSciJr
I'm going on with the project of a dictionary with hashing by string.
I have adapted to the Luke's UDT my routines of managing a dictionary with string key (in this example with one char as key) with this final code...
...
as you run the code, you will notice that the IDCheck function makes very slower the code from the usage without IDCheck as this screenshot shows.
...
now it lasts to code FUNCTIONs for overwriting an item (hash key is duplicated: overwrite or discharge data?), appending an item to the same hash key or shifting data to the next unused hash key.
Following the APPEND way we need the Join and Split string functions and the conversion Int2Str, Str2Int, Lng2Str, Str2Lng functions.
Following the SHIFTING way we need a SearchUnusedItem and the FindShiftedData functions.
...
If it is almost interesting, I will post the other 2 ways with correlate functions the next time.
Thank you for feedbacks
This is interesting, Tempodi - I look forward to seeing your results!
This gives me a couple of thoughts / ideas:
- You mentioned bplus' idea of using split/join - was that for a dictionary? I thought that was for storing an array in an array? If it is a dictionary, do you have the link to bplus' code?
- That gives me another idea - what if we stored the whole dictionary in a big string (instead of an array) and leverage INSTR and _INSTRREV to find the key and data, and MID$ to pull it out? Would that be any faster than the hash/array methods we have been playing with? When I am back at my PC, I can try it. Thank the maker for INSTR! Imagine if we didn't have INSTR and _INSTRREV and instead had to implement them from scratch in QB64PE? We would have to make our own and they would probably be slower!
- If leveraging a built in function like INSTR is fastest, that shows me that built-in functions may be best. What if QB64PE had a built in dictionary that ran at native speed so we don't have to worry about performance or errors? I think 3 new commands that I would wish for to be added to QB64PE would be dictionary and also split / join!
I am going to play with implementing a dictionary in a string with INSTR, just as an experiment.
Thoughts?
PS Thanks for your help with this, just having someone to bounce these ideas off of is very helpful (and fun)!