Results 1 to 1 of 1

Thread: Multidimensional Dynamic String Arrays

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    52
    Posts
    1,482
    Blog Entries
    2
    Rep Power
    164

    Multidimensional Dynamic String Arrays

    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......

    but that is what dictionary-module is made for: to handle data fast and easy.
    #MinVersion 1.9.12.0
    Attached Files Attached Files
    Last edited by ReneMiner; 25-04-2014 at 12:34.


Similar Threads

  1. Constant String Arrays with non-linear "indexes"
    By ReneMiner in forum Suggestions/Ideas discussions
    Replies: 3
    Last Post: 22-08-2013, 10:21
  2. is Union a step to dynamic UDT-arrays?
    By ReneMiner in forum Core module
    Replies: 5
    Last Post: 18-05-2013, 15:15
  3. "Dynamic Arrays" in my UDT...
    By Oscar Ugolini in forum thinBasic General
    Replies: 4
    Last Post: 18-09-2012, 21:12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •