jargon

aa 0.06 freebasic.bas

Jul 3rd, 2013
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'aa 0.06
  2. 'Associative Array Module
  3. 'FreeBasic Source Code
  4. 'Copyright Wednesday, November 14th 2007 - July 2nd 2013 Timothy Robert Keal
  5. 'requires "bi/bi 0.03.bas"
  6.  
  7. Const False=&H0
  8. Const True=&HFFFFFFFF
  9.  
  10. Const aa_sep=&H2F
  11. Const aa_ptrmx=&H26
  12. Const aa_bnkmx=&HA4
  13. Const aa_chro=&H00
  14. Const aa_valo=&H98
  15. Const aa_ptro=&H9C
  16. Const aa_lasto=&HA0
  17.  
  18. dim as long aa=aa_a(False)
  19.  
  20. 're-allocate using given
  21. Function aa_a(aa as long) as long
  22.     Return aa_allocate(aa)
  23. End Function
  24.  
  25. 'seek pointer using master
  26. Function aa_p(label as string) as long
  27.     dim as long temp=bi_sp(label)
  28.     dim as long ret=aa_seekptr(aa,temp,0)
  29.     FreeBank temp
  30.     Return ret
  31. End Function
  32.  
  33. 'set integer using master
  34. Sub aa_s(label as string,value as long)
  35.     dim as long temp=bi_sp(ucase(label))
  36.     aa_pokeint aa,temp,0,value
  37.     FreeBank temp
  38. End Sub
  39.  
  40. 'get integer using master
  41. Function aa_g(label as string) as long
  42.     dim as long temp=bi_sp(ucase(label))
  43.     dim as long ret=aa_peekint(aa,temp,0)
  44.     FreeBank temp
  45.     Return ret
  46. End Function
  47.  
  48. 'set float using master
  49. Function aa_sf(label$,value#)
  50.     dim as long temp=bi_sp(ucase(label))
  51.     aa_pokefloat aa,temp,0,value
  52.     FreeBank temp
  53. End Function
  54.  
  55. 'get float using master
  56. Function aa_gf(label as string) as double
  57.     dim as long temp=bi_sp(ucase(label))
  58.     dim as double ret=aa_peekfloat(aa,temp,0)
  59.     FreeBank temp
  60.     Return ret
  61. End Function
  62.  
  63. 're-allocate using given
  64. Function aa_allocate(aa as long) as long
  65.     If aa<>False Then aa_collapse(aa)
  66.     aa=CreateBank(aa_bnkmx)
  67.     PokeByte aa,aa_lasto,True
  68.     Return aa
  69. End Function
  70.  
  71. 'collapse using given
  72. Function aa_collapse(aa as long) as long
  73.     dim as long emptyflag=False
  74.     If aa=False Then Return False
  75.     If BankSize(aa)<>aa_bnkmx Then
  76.         FreeBank aa
  77.         Return aa
  78.     EndIf
  79.    
  80.     ptrbyte=&H00
  81.     do while ptrbyte<(aa_ptrmx Shl &H2)
  82.         aa_collapse PeekInt(aa,ptrbyte+aa_chro)
  83.         ptrbyte=ptrbyte+&H04
  84.     loop
  85.  
  86.     dim as long aa2=False
  87.  
  88.     aa2=PeekInt(aa,aa_ptro)
  89.     If aa2<>False Then aa_collapse aa2
  90.  
  91.     If PeekByte(aa,aa_lasto)=True
  92.         d3_collapse PeekInt(aa,aa_valo)
  93.     EndIf
  94.    
  95.     FreeBank aa
  96.     Return False
  97. End Function
  98.  
  99. 'seek pointer using given
  100. Function aa_seekptr(aa as long,ptr1 as ptr,offset as long) as long
  101.    
  102.     dim as long nullflag=False
  103.     If ptr1=False Then nullflag=True
  104.     If nullflag=False Then
  105.         If offset>=BankSize(ptr1) Then nullflag=True
  106.     EndIf
  107.        
  108.     dim as long emptyflag=False
  109.     If aa=0 Then emptyflag=True
  110.     If emptyflag=False Then
  111.         If BankSize(aa)<>aa_bnkmx Then emptyflag=True
  112.     EndIf
  113.    
  114.     If emptyflag=True Return False
  115.  
  116.     If nullflag=True Then
  117.         Return aa
  118.     EndIf
  119.  
  120.     dim as long ptrbyte=PeekByte(ptr1,offset)
  121.  
  122.     dim as long aa2=False
  123.    
  124.     If ptrbyte=aa_sep Then
  125.         aa2=PeekInt(aa,aa_ptro)
  126.         If aa2=False Then Return False
  127.         Return aa_seekptr(aa2,ptr1,offset+&H1)
  128.     EndIf
  129.    
  130.     Return aa_seekptr(PeekInt(aa,(ptrbyte Shl &H2)+aa_chro),ptr1,offset+&H1)
  131.  
  132. End Function
  133.  
  134. 'poke integer using given
  135. Function aa_pokeint(aa as long,ptr1 as ptr,offset as long,value as long) as long
  136.    
  137.     dim as long nullflag=False
  138.     If ptr1=False Then nullflag=True
  139.     If nullflag=False Then
  140.         If offset>=BankSize(ptr1) Then nullflag=True
  141.     EndIf
  142.        
  143.     dim as long emptyflag=False
  144.     If aa=0 Then
  145.         emptyflag=True
  146.         aa=CreateBank(aa_bnkmx)
  147.     EndIf
  148.     If emptyflag=False Then
  149.         If BankSize(aa)<>aa_bnkmx Then
  150.             emptyflag=True
  151.             ResizeBank aa,aa_bnkmx
  152.         EndIf
  153.     EndIf
  154.        
  155.     If nullflag=True Then
  156.         PokeInt aa,aa_valo,value
  157.         Return aa
  158.     EndIf
  159.  
  160.     dim as long ptrbyte=PeekByte(ptr1,offset)
  161.  
  162.     dim as long aa2=False
  163.    
  164.     If ptrbyte=aa_sep Then
  165.         aa2=PeekInt(aa,aa_ptro)
  166.         If aa2=False Then
  167.             aa2=aa_allocate(aa2)
  168.             PokeInt aa,aa_ptro,aa2
  169.         EndIf      
  170.         Return aa_pokeint(aa2,ptr1,offset+&H1,value)
  171.     EndIf
  172.  
  173.     aa2=PeekInt(aa,(ptrbyte Shl &H2)+aa_chro)
  174.     If aa2=False Then
  175.         aa2=aa_allocate(aa2)
  176.         PokeByte(aa2,aa_lasto,False)
  177.         PokeInt aa,(ptrbyte Shl &H2)+aa_chro,aa2
  178.     EndIf
  179.        
  180.     Return aa_pokeint(aa2,ptr,offset+1,value)
  181. End Function
  182.  
  183. 'peek integer using given
  184. Function aa_peekint(aa as long,ptr1 as long,offset as long) as long
  185.  
  186.     dim as long nullflag=False
  187.     If ptr1=False Then nullflag=True
  188.     If nullflag=False Then
  189.         If offset>=BankSize(ptr1) Then nullflag=True
  190.     EndIf
  191.        
  192.     Local emptyflag=False
  193.     If aa=0 Then emptyflag=True
  194.     If emptyflag=False Then
  195.         If BankSize(aa)<>aa_bnkmx Then emptyflag=True
  196.     EndIf
  197.    
  198.     If emptyflag=True Return False
  199.  
  200.     If nullflag=True Then
  201.         Return PeekInt(aa,aa_valo)
  202.     EndIf
  203.  
  204.     dim as long ptrbyte=PeekByte(ptr1,offset)
  205.  
  206.     dim as long aa2=False
  207.    
  208.     If ptrbyte=aa_sep Then
  209.         aa2=PeekInt(aa,aa_ptro)
  210.         If aa2=False Then Return False
  211.         Return aa_peekint(aa2,ptr1,offset+&H1)
  212.     EndIf
  213.    
  214.     aa2=PeekInt(aa,(ptrbyte Shl &H2)+aa_chro)
  215.     If aa2=False Then Return False
  216.    
  217.     Return aa_peekint(aa2,ptr,offset+&H1)
  218.  
  219. End Function
  220.  
  221. 'poke float using given
  222. Function aa_pokefloat(aa as long,ptr1 as ptr,offset as long,value as double) as double
  223.         Return aa_pokeint(aa,ptr1,offset,bi_fi(value))
  224. End Function
  225.  
  226. 'peek float using given
  227. Function aa_peekfloat(aa as long,ptr1 as ptr,offset as long) as double
  228.         Return bi_if(aa_peekint(aa,ptr1,offset))
  229. End Function
Add Comment
Please, Sign In to add comment