Author Topic: HASH Extension Module  (Read 210 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2745
    • ScriptBasic Open Source Project
HASH Extension Module
« on: July 28, 2019, 09:51:18 PM »
AIR,

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
  1. INCLUDE hash.bas
  2.  
  3. hh = HASH::New()
  4.  
  5. flen = FILELEN("tail.dat")
  6. OPEN "tail.dat" FOR INPUT AS #1
  7. fraw = INPUT(flen, 1)
  8. SPLITA fraw BY "\n" TO wordlist
  9. CLOSE(1)
  10.  
  11. FOR lstidx = 0 TO UBOUND(wordlist)
  12.   SPLITA wordlist[lstidx] BY "" TO wordarray
  13.   FOR wrdidx = 0 TO UBOUND(wordarray)
  14.     IF wordarray[wrdidx] < "a" OR wordarray[wrdidx] > "z" THEN GOTO NextWord
  15.   NEXT
  16.   SPLITA wordlist[lstidx] BY "" TO thisword
  17.  
  18.   FOR i = 0 TO UBOUND(thisword)
  19.     FOR j = i + 1 TO UBOUND(thisword)
  20.       IF thisword[i] > thisword[j] THEN
  21.         temp = thisword[i]
  22.         thisword[i] = thisword[j]
  23.         thisword[j] = temp
  24.       END IF
  25.     NEXT
  26.   NEXT
  27.   FOR x = 0 TO UBOUND(thisword)
  28.     sortword &= thisword[x]
  29.   NEXT
  30.   IF HASH::Exists(hh, sortword) = undef THEN
  31. ' IF anagram{sortword} = undef THEN
  32. '   anagram{sortword} = wordlist[lstidx] & ":"
  33.    HASH::SetValue hh, sortword, wordlist[lstidx] & ":"
  34.   ELSE
  35. '   anagram{sortword} &= " " & wordlist[lstidx] & ","
  36.    strdta = HASH::Value(hh, sortword)
  37.     HASH::SetValue(hh, sortword, strdta & " " & wordlist[lstidx] & ",")
  38.   END IF
  39.   sortword = ""
  40. NextWord:
  41. NEXT
  42.  
  43. HASH::Start hh
  44. NextKey:
  45. HASH::Next(hh)
  46. ' thiskey = HASH::ThisKey(hh)
  47. thisana = HASH::ThisValue(hh)
  48. IF thisana = undef THEN GOTO Done
  49. ' PRINT thisana,"\n"
  50. IF RIGHT(thisana, 1) = "," THEN
  51.   PRINT LEFT(thisana, LEN(thisana) - 1), "\n"
  52. END IF
  53. GOTO NextKey
  54.  
  55. Done:
  56.  
  57. HASH::Release hh
  58.  

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.


Offline John

  • Forum Support / SB Dev
  • Posts: 2745
    • ScriptBasic Open Source Project
Re: HASH Extension Module
« Reply #1 on: August 02, 2019, 10:20:05 AM »
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.

« Last Edit: August 03, 2019, 08:54:25 AM by John »