May 15, 2024, 12:59:07 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


string pointer hash magic

Started by Jerry Muelver, March 06, 2008, 02:39:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jerry Muelver

On a hint from Paul, and a little RVA (Random Variable Assignment) on my own, I discovered that I can create a hash array, then create a string point in a SUB, assign a string value to it, then dump it into an element in my hash, delete the string pointer, return to the main loop, and access the element just as if it had been created out in the open! Magic! Make a hash, load it offstage with all kinds and sizes of strings, and it all holds together. How do you programmer guys ever get smart enough to invent this stuff in the first place?!  ::)

mydict = DictCreate(100)

dictAdd(mydict,"John","Red")
DictAdd(mydict,"Joe","Green")
DictAdd(mydict,"Sue","Yellow")
DictAdd(mydict,"Phil","Purple")
gosub addJer
DictAdd(mydict,"Lisa","Blue")
DictAdd(mydict,"Tammy","Black")
DictAdd(mydict,"George","white")
DictAdd(mydict,"Paul","Indigo")
DictAdd(mydict,"Merideth Abigal","Violet")
'DictAdd(mydict,"Lisa","no")

PRINT DictLookup(myDict,"Lisa")
PRINT DictLookup(myDict,"Sue")
PRINT DictLookup(myDict,"Jerry")

PRINT:PRINT "Iterating":PRINT "---------"
pos = DictGetStartAssoc(myDict)
WHILE pos
pAssoc = DictGetNextAssoc(myDict,pos)
PRINT DictGetKey(pAssoc)," ",DictGetValue(pAssoc)
ENDWHILE
'print "len = ",str$(len(#<string>hypt))
DO:UNTIL INKEY$ <> ""
DictFree(mydict)

END

sub addJer
def hypt as pointer
hypt = NEW(string,1000)
#<string>hypt = "Big long string "
for i = 0 to 4
#<string>hypt += #<string>hypt
next i
DictAdd(mydict,"Jerry",#<string>hypt)
delete hypt
RETURN
ENDSUB


Ionic Wind Support Team

Thats because the associative array make it own copy of your key and value pair, so you are free to do what you wish to the originals.  The They can be whatever length your system can handle.

Paul.
Ionic Wind Support Team

Jerry Muelver

Neato! First thing I did with it was invent a hybrid text-RTF file format for doing single-file multi-page stuff. The app follows pagename hyperlinks even when they're word-wrapped on the page. This is getting REALLY interesting!