Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'aa 0.06
- 'Associative Array Module
- 'FreeBasic Source Code
- 'Copyright Wednesday, November 14th 2007 - July 2nd 2013 Timothy Robert Keal
- 'requires "bi/bi 0.03.bas"
- Const False=&H0
- Const True=&HFFFFFFFF
- Const aa_sep=&H2F
- Const aa_ptrmx=&H26
- Const aa_bnkmx=&HA4
- Const aa_chro=&H00
- Const aa_valo=&H98
- Const aa_ptro=&H9C
- Const aa_lasto=&HA0
- dim as long aa=aa_a(False)
- 're-allocate using given
- Function aa_a(aa as long) as long
- Return aa_allocate(aa)
- End Function
- 'seek pointer using master
- Function aa_p(label as string) as long
- dim as long temp=bi_sp(label)
- dim as long ret=aa_seekptr(aa,temp,0)
- FreeBank temp
- Return ret
- End Function
- 'set integer using master
- Sub aa_s(label as string,value as long)
- dim as long temp=bi_sp(ucase(label))
- aa_pokeint aa,temp,0,value
- FreeBank temp
- End Sub
- 'get integer using master
- Function aa_g(label as string) as long
- dim as long temp=bi_sp(ucase(label))
- dim as long ret=aa_peekint(aa,temp,0)
- FreeBank temp
- Return ret
- End Function
- 'set float using master
- Function aa_sf(label$,value#)
- dim as long temp=bi_sp(ucase(label))
- aa_pokefloat aa,temp,0,value
- FreeBank temp
- End Function
- 'get float using master
- Function aa_gf(label as string) as double
- dim as long temp=bi_sp(ucase(label))
- dim as double ret=aa_peekfloat(aa,temp,0)
- FreeBank temp
- Return ret
- End Function
- 're-allocate using given
- Function aa_allocate(aa as long) as long
- If aa<>False Then aa_collapse(aa)
- aa=CreateBank(aa_bnkmx)
- PokeByte aa,aa_lasto,True
- Return aa
- End Function
- 'collapse using given
- Function aa_collapse(aa as long) as long
- dim as long emptyflag=False
- If aa=False Then Return False
- If BankSize(aa)<>aa_bnkmx Then
- FreeBank aa
- Return aa
- EndIf
- ptrbyte=&H00
- do while ptrbyte<(aa_ptrmx Shl &H2)
- aa_collapse PeekInt(aa,ptrbyte+aa_chro)
- ptrbyte=ptrbyte+&H04
- loop
- dim as long aa2=False
- aa2=PeekInt(aa,aa_ptro)
- If aa2<>False Then aa_collapse aa2
- If PeekByte(aa,aa_lasto)=True
- d3_collapse PeekInt(aa,aa_valo)
- EndIf
- FreeBank aa
- Return False
- End Function
- 'seek pointer using given
- Function aa_seekptr(aa as long,ptr1 as ptr,offset as long) as long
- dim as long nullflag=False
- If ptr1=False Then nullflag=True
- If nullflag=False Then
- If offset>=BankSize(ptr1) Then nullflag=True
- EndIf
- dim as long emptyflag=False
- If aa=0 Then emptyflag=True
- If emptyflag=False Then
- If BankSize(aa)<>aa_bnkmx Then emptyflag=True
- EndIf
- If emptyflag=True Return False
- If nullflag=True Then
- Return aa
- EndIf
- dim as long ptrbyte=PeekByte(ptr1,offset)
- dim as long aa2=False
- If ptrbyte=aa_sep Then
- aa2=PeekInt(aa,aa_ptro)
- If aa2=False Then Return False
- Return aa_seekptr(aa2,ptr1,offset+&H1)
- EndIf
- Return aa_seekptr(PeekInt(aa,(ptrbyte Shl &H2)+aa_chro),ptr1,offset+&H1)
- End Function
- 'poke integer using given
- Function aa_pokeint(aa as long,ptr1 as ptr,offset as long,value as long) as long
- dim as long nullflag=False
- If ptr1=False Then nullflag=True
- If nullflag=False Then
- If offset>=BankSize(ptr1) Then nullflag=True
- EndIf
- dim as long emptyflag=False
- If aa=0 Then
- emptyflag=True
- aa=CreateBank(aa_bnkmx)
- EndIf
- If emptyflag=False Then
- If BankSize(aa)<>aa_bnkmx Then
- emptyflag=True
- ResizeBank aa,aa_bnkmx
- EndIf
- EndIf
- If nullflag=True Then
- PokeInt aa,aa_valo,value
- Return aa
- EndIf
- dim as long ptrbyte=PeekByte(ptr1,offset)
- dim as long aa2=False
- If ptrbyte=aa_sep Then
- aa2=PeekInt(aa,aa_ptro)
- If aa2=False Then
- aa2=aa_allocate(aa2)
- PokeInt aa,aa_ptro,aa2
- EndIf
- Return aa_pokeint(aa2,ptr1,offset+&H1,value)
- EndIf
- aa2=PeekInt(aa,(ptrbyte Shl &H2)+aa_chro)
- If aa2=False Then
- aa2=aa_allocate(aa2)
- PokeByte(aa2,aa_lasto,False)
- PokeInt aa,(ptrbyte Shl &H2)+aa_chro,aa2
- EndIf
- Return aa_pokeint(aa2,ptr,offset+1,value)
- End Function
- 'peek integer using given
- Function aa_peekint(aa as long,ptr1 as long,offset as long) as long
- dim as long nullflag=False
- If ptr1=False Then nullflag=True
- If nullflag=False Then
- If offset>=BankSize(ptr1) Then nullflag=True
- EndIf
- Local emptyflag=False
- If aa=0 Then emptyflag=True
- If emptyflag=False Then
- If BankSize(aa)<>aa_bnkmx Then emptyflag=True
- EndIf
- If emptyflag=True Return False
- If nullflag=True Then
- Return PeekInt(aa,aa_valo)
- EndIf
- dim as long ptrbyte=PeekByte(ptr1,offset)
- dim as long aa2=False
- If ptrbyte=aa_sep Then
- aa2=PeekInt(aa,aa_ptro)
- If aa2=False Then Return False
- Return aa_peekint(aa2,ptr1,offset+&H1)
- EndIf
- aa2=PeekInt(aa,(ptrbyte Shl &H2)+aa_chro)
- If aa2=False Then Return False
- Return aa_peekint(aa2,ptr,offset+&H1)
- End Function
- 'poke float using given
- Function aa_pokefloat(aa as long,ptr1 as ptr,offset as long,value as double) as double
- Return aa_pokeint(aa,ptr1,offset,bi_fi(value))
- End Function
- 'peek float using given
- Function aa_peekfloat(aa as long,ptr1 as ptr,offset as long) as double
- Return bi_if(aa_peekint(aa,ptr1,offset))
- End Function
Add Comment
Please, Sign In to add comment