How to effectively implement a nested structure containing arrays of other nested structures in a language that does not support them?

Structure

This is the main structure that I need to create by creating a type tParent(pseudocode, where ()is an array declaration):

type Ne {
    single D()
    dword DC
    single B
    single V
    single D
}

type L {
    Ne Ns()
    dword NC
}

type tParent {
    L La()
    dword LC
    single LR
}

tParent nTest 

// would be accessed like nTest.La(0).Ns(0).B = 42 ...

However, for the proprietary language that should be used for this, there are no "arrays of user-defined types." Nesting support is supported, so in addition to ()array declarations in the above types, the code is valid.

Question

What is the most efficient way - algorithmically - to implement this structure. I was thinking about expanding the subtypes into arrays and accessing them using a second array that contains offsets, but I doubt it would be effective anyway.

+4
3

, , , . ,

 single typeName_fieldName_get(byte arr(), int offset) {
      return convertFomByteToSingle(
          arr(offset+OFFSET_OF_FIELD_NAME + 0),
          arr(offset+OFFSET_OF_FIELD_NAME + 1),
          arr(offset+OFFSET_OF_FIELD_NAME + 2),
          ....
          );
 }
+1

, ,

function("nTest", ["La","Ns"], ["0","0"]).b = 42

, , . - , - . , , :

function("nTest", [["La","0"],["Ns","0"]]).b = 42

, - , , :

function("nTest","La","0","Ns","0").b = 42

. ( ):

temp = nTest
temp = temp.La
temp = temp(0)
temp = temp.Ns
temp = temp(0)
return temp

, ​​ , . , , .

, , , , , - :

function(["tParent","nTest"],["L","La"],["int","0"],["Ne","Ns"],["int","0"],["single","D"]) = 42
0

The only solution I can think of as you cannot use pointers is to use a linked list. Moving forward during the iteration will be O (1), but the search will, of course, be O (n), so depending on your use case, this may not be the most effective solution, but it seems to me that it is the only one available without the ability to store the address memory in a primitive array for use as pointers.

type tParent {
    ListL La
    dword LC
    single LR
}

type ListL {
    NodeL First
}

type NodeL {
    NodeL Next
    L Value
}
0
source

All Articles