? Is Hashing basically DATA and READ? (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
What's going on?? See: Site Update March 2022

Is Hashing basically DATA and READ?

  • #1 ✎ 78 Gaelstrom_Valence Drawing I like to draw! Hobbies Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength First Month Joined in the very first month of SmileBASIC Source Website 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? Posted
  • #2 ✎ 125 glennxserge 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,6 Where 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. Posted
  • #3 ✎ 78 Gaelstrom_Valence Drawing I like to draw! Hobbies Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength First Month Joined in the very first month of SmileBASIC Source Website
    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,6 Where 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.
    Yeah, that's pretty much what I had in mind! I didn't know that Hashing was like, a verb hah. And I doooo think that would work, I believe you'd just need to add an @ to the beginning of the NAME$ string variable
    Posted
  • #4 ✎ 78 Gaelstrom_Valence Drawing I like to draw! Hobbies Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength First Month Joined in the very first month of SmileBASIC Source Website 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. Posted