BASIC Developer & Support Resources > Scripting Languages

HASH Extension Module



I'm trying to get the hash extension to work for the anagram challenge on the RPi forum. It doesn't seem to be working as expected and I'm getting a seg fault.

--- Code: Script BASIC ---INCLUDE hash.bas hh = HASH::New() flen = FILELEN("tail.dat")OPEN "tail.dat" FOR INPUT AS #1fraw = INPUT(flen, 1)SPLITA fraw BY "\n" TO wordlistCLOSE(1) FOR lstidx = 0 TO UBOUND(wordlist)  SPLITA wordlist[lstidx] BY "" TO wordarray  FOR wrdidx = 0 TO UBOUND(wordarray)    IF wordarray[wrdidx] < "a" OR wordarray[wrdidx] > "z" THEN GOTO NextWord  NEXT  SPLITA wordlist[lstidx] BY "" TO thisword   FOR i = 0 TO UBOUND(thisword)    FOR j = i + 1 TO UBOUND(thisword)      IF thisword[i] > thisword[j] THEN        temp = thisword[i]        thisword[i] = thisword[j]        thisword[j] = temp      END IF    NEXT  NEXT  FOR x = 0 TO UBOUND(thisword)    sortword &= thisword[x]  NEXT  IF HASH::Exists(hh, sortword) = undef THEN' IF anagram{sortword} = undef THEN'   anagram{sortword} = wordlist[lstidx] & ":"    HASH::SetValue hh, sortword, wordlist[lstidx] & ":"  ELSE'   anagram{sortword} &= " " & wordlist[lstidx] & ","    strdta = HASH::Value(hh, sortword)    HASH::SetValue(hh, sortword, strdta & " " & wordlist[lstidx] & ",")  END IF  sortword = ""NextWord:NEXT HASH::Start hhNextKey:HASH::Next(hh)' thiskey = HASH::ThisKey(hh)thisana = HASH::ThisValue(hh)IF thisana = undef THEN GOTO Done' PRINT thisana,"\n"IF RIGHT(thisana, 1) = "," THEN  PRINT LEFT(thisana, LEN(thisana) - 1), "\n"END IFGOTO NextKey Done: HASH::Release hh 
Attached is the tail for the British Insane Dictionary. (last 10,000 words)

HERE is what I'm trying to reproduce but using the HASH module rather than an associative array.

As things stand ScriptBasic is in last place with the English insane Dictionary anagram challenge.

Our only hope to save face is getting the HASH extension module to work.

it dies reading 7901 keys from the built hash of 10,000.

This may be a case of HASH not recognizing the end of the iteration.


[0] Message Index

Go to full version