I've been trying to parse things from tutorials online and I've come across a structure a few times.
Finally decided to look into it and
Using a string variable paired with RESTORE would accomplish basically the same thing as a dictionary structure, right?
Is Hashing basically DATA and READ?
Root / Programming Questions / [.]
Gaelstrom_ValenceCreated:
I think, conceptually, at least on a surface level, you could make something that felt like a dictionary, but there's not really any hashing going on. The compiler is just swapping in line number jump targets for those labels, and you are dealing with constant data. But this is a clever way of encapsulating some convenient ways of managing data. I imagine you are thinking of something like the following idea? (completely untested btw, I imagine I got the RESTORE part wrong)
DIM MONSTERS$[]=["Goblin","Human","Orc"] GET_DATA MONSTERS$[0] OUT HP1,STR1 'Gets the Goblin data GET_DATA MONSTERS$[1] OUT HP2,STR2 'Gets the Human data GET_DATA MONSTERS$[2] OUT HP3,STR3 'Gets the Orc data DEF GET_DATA NAME$ OUT OHP,OSTR RESTORE NAME$ READ OHP,OSTR END @Goblin DATA 10,3 @Human DATA 12,4 @Orc DATA 15,6Where the input string in the function is all that's needed to pull a completely different set of data ("Goblin" -> "Human" in the first line, for instance). The indexing is overkill, but just trying to make this feel like more of a dictionary.
I think, conceptually, at least on a surface level, you could make something that felt like a dictionary, but there's not really any hashing going on. The compiler is just swapping in line number jump targets for those labels, and you are dealing with constant data. But this is a clever way of encapsulating some convenient ways of managing data. I imagine you are thinking of something like the following idea? (completely untested btw, I imagine I got the RESTORE part wrong)Yeah, that's pretty much what I had in mind! I didn't know that Hashing was like, a verb hah.DIM MONSTERS$[]=["Goblin","Human","Orc"] GET_DATA MONSTERS$[0] OUT HP1,STR1 'Gets the Goblin data GET_DATA MONSTERS$[1] OUT HP2,STR2 'Gets the Human data GET_DATA MONSTERS$[2] OUT HP3,STR3 'Gets the Orc data DEF GET_DATA NAME$ OUT OHP,OSTR RESTORE NAME$ READ OHP,OSTR END @Goblin DATA 10,3 @Human DATA 12,4 @Orc DATA 15,6Where the input string in the function is all that's needed to pull a completely different set of data ("Goblin" -> "Human" in the first line, for instance). The indexing is overkill, but just trying to make this feel like more of a dictionary.
I looked further into hash functions, and I think I might've thought of a way to get something similar? As in, being able to search something non linearly, with a name (string), while being able to potentially add and delete from the table, unlike Data stuff. I haven't put this to practice yet but I'm tired and I want to get this down.
Though now that I think about it it might not be any more efficient than just searching through an array with a loop of some kind.
Make a Table, or Index string variable, whatever the right term is. Make sure all the keys you want to include are evenly spaced, pad them out with some arbitrary symbol. For example, here I make sure each key is 4 characters long:
Table$="Jon0MaryKen0"Then use a function to accept a Key or whatever, have the function pad out the Key with FORMAT$(). Then use INSTR to get the place within the Table string, DIV it up, and use that to refer to an Array.