ReneMiner
24-04-2014, 14:46
A weird approach, but works - pretty simple - thanks to dictionary-module.
Create multidimensional dynamic string-arrays in "unlimited" dimensions and need 20 Bytes to append these to anything.
Each dimension can be in a range from -2,147,483,648 to 2,147,483,647.
Use MKIndex() or MKL$() to pass Indexes and also the boundaries on creation.
Pass HiBounds only on .Create() to have all dimensions 1-based, optional pass LowBounds and HiBounds to set the range of all dimensions individually.
Example using 3 dimensions, but could have 4 or more as well:
#INCLUDE "MD_String.tBasicU"
Uses "console"
' now create some multi-dimensional dynamic-string-Item
Dim foo As MD_String
foo.Create( MKIndex(-3,-2, -1), _ ' lowbounds (3 dimensions)
MKIndex( 1, 2, 3 ) _ ' hibounds (3 dimensions)
)
' foo will have (-3 to 1, -2 to 2, -1 to 3) strings attached now
' 5 * 5 * 5
' ======================
' 125 elements
Dim i, j, k As Long
For i = 1 To foo.nDims ' .nDims tells us the number of dimensions
PrintL "Dimension " & i & ": " & foo.GetLowBound(i) & " To " & foo.GetHiBound(i)
Next
PrintL
PrintL "Have a total of " & foo.ElementsTotal & " elements"
PrintL $CRLF + Repeat$(42, "-")
PrintL $CRLF + "Press any key to continue" + $CRLF
WaitKey
For i = foo.GetLowBound(1) To foo.GetHiBound(1)
For j = foo.GetLowBound(2) To foo.GetHiBound(2)
For k = foo.GetLowBound(3) To foo.GetHiBound(3)
PrintL foo.SetText( MKIndex(i,j,k), "I am " & i & ", " & j & ", " & k )
Next
Next
Next
PrintL $CRLF & "do some checks now:" & $CRLF
' check element 0,0,0
PrintL foo.GetText( MKIndex(0,0,0) )
' check element 1,1,1
PrintL foo.GetText( MKIndex(1,1,1) )
' check element -1,-1,-1
PrintL foo.GetText( MKIndex(-1,-1,-1) )
foo.SetText( MKIndex(1,2,3), "I am some new 1,2,3-text now" )
PrintL foo.GetText( MKIndex(1,2,3) )
PrintL $CRLF & "check len:" & $CRLF
For i = 1 To 5
Print "----" & TStr$(i - 1) & "----" & TStr$(i)
Next
PrintL
PrintL Repeat$(5,"----5----0")
PrintL foo.GetText( MKIndex(1,2,3) )
PrintL "len is " & foo.GetLen( MKIndex(1,2,3) )
PrintL
PrintL "find data at ptr:"
PrintL Memory_Get(foo.GetPtr( MKIndex(1,2,3) ), foo.GetLen( MKIndex(1,2,3) ) )
PrintL
PrintL "try something invalid now:"
PrintL foo.GetText( MKIndex(1,2,3,4,5) )
PrintL $CRLF + Repeat$(42, "-")
PrintL $CRLF + "Press any key to release a secret" + $CRLF
WaitKey
Dim sKey As String
For i = foo.GetLowBound(1) To foo.GetHiBound(1)
For j = foo.GetLowBound(2) To foo.GetHiBound(2)
For k = foo.GetLowBound(3) To foo.GetHiBound(3)
sKey = "k" & Hex$(i,8) & Hex$(j,8) & Hex$(k,8)
PrintL "Key: " & sKey & " Bucket: " & Dictionary_Find( foo.pDict, sKey )
Next
Next
Next
PrintL $CRLF + Repeat$(42, "-")
PrintL $CRLF + "Press the famous ANY-key to end"
WaitKey
Ok, you got me -
I cheated a little up there...:eusadance:...
but that is what dictionary-module is made for: to handle data fast and easy.
#MinVersion 1.9.12.0
Create multidimensional dynamic string-arrays in "unlimited" dimensions and need 20 Bytes to append these to anything.
Each dimension can be in a range from -2,147,483,648 to 2,147,483,647.
Use MKIndex() or MKL$() to pass Indexes and also the boundaries on creation.
Pass HiBounds only on .Create() to have all dimensions 1-based, optional pass LowBounds and HiBounds to set the range of all dimensions individually.
Example using 3 dimensions, but could have 4 or more as well:
#INCLUDE "MD_String.tBasicU"
Uses "console"
' now create some multi-dimensional dynamic-string-Item
Dim foo As MD_String
foo.Create( MKIndex(-3,-2, -1), _ ' lowbounds (3 dimensions)
MKIndex( 1, 2, 3 ) _ ' hibounds (3 dimensions)
)
' foo will have (-3 to 1, -2 to 2, -1 to 3) strings attached now
' 5 * 5 * 5
' ======================
' 125 elements
Dim i, j, k As Long
For i = 1 To foo.nDims ' .nDims tells us the number of dimensions
PrintL "Dimension " & i & ": " & foo.GetLowBound(i) & " To " & foo.GetHiBound(i)
Next
PrintL
PrintL "Have a total of " & foo.ElementsTotal & " elements"
PrintL $CRLF + Repeat$(42, "-")
PrintL $CRLF + "Press any key to continue" + $CRLF
WaitKey
For i = foo.GetLowBound(1) To foo.GetHiBound(1)
For j = foo.GetLowBound(2) To foo.GetHiBound(2)
For k = foo.GetLowBound(3) To foo.GetHiBound(3)
PrintL foo.SetText( MKIndex(i,j,k), "I am " & i & ", " & j & ", " & k )
Next
Next
Next
PrintL $CRLF & "do some checks now:" & $CRLF
' check element 0,0,0
PrintL foo.GetText( MKIndex(0,0,0) )
' check element 1,1,1
PrintL foo.GetText( MKIndex(1,1,1) )
' check element -1,-1,-1
PrintL foo.GetText( MKIndex(-1,-1,-1) )
foo.SetText( MKIndex(1,2,3), "I am some new 1,2,3-text now" )
PrintL foo.GetText( MKIndex(1,2,3) )
PrintL $CRLF & "check len:" & $CRLF
For i = 1 To 5
Print "----" & TStr$(i - 1) & "----" & TStr$(i)
Next
PrintL
PrintL Repeat$(5,"----5----0")
PrintL foo.GetText( MKIndex(1,2,3) )
PrintL "len is " & foo.GetLen( MKIndex(1,2,3) )
PrintL
PrintL "find data at ptr:"
PrintL Memory_Get(foo.GetPtr( MKIndex(1,2,3) ), foo.GetLen( MKIndex(1,2,3) ) )
PrintL
PrintL "try something invalid now:"
PrintL foo.GetText( MKIndex(1,2,3,4,5) )
PrintL $CRLF + Repeat$(42, "-")
PrintL $CRLF + "Press any key to release a secret" + $CRLF
WaitKey
Dim sKey As String
For i = foo.GetLowBound(1) To foo.GetHiBound(1)
For j = foo.GetLowBound(2) To foo.GetHiBound(2)
For k = foo.GetLowBound(3) To foo.GetHiBound(3)
sKey = "k" & Hex$(i,8) & Hex$(j,8) & Hex$(k,8)
PrintL "Key: " & sKey & " Bucket: " & Dictionary_Find( foo.pDict, sKey )
Next
Next
Next
PrintL $CRLF + Repeat$(42, "-")
PrintL $CRLF + "Press the famous ANY-key to end"
WaitKey
Ok, you got me -
I cheated a little up there...:eusadance:...
but that is what dictionary-module is made for: to handle data fast and easy.
#MinVersion 1.9.12.0