Page 1 of 1

Compare structure

Posted: Thu Dec 27, 2018 6:20 pm
by User_Russian
I propose to add a function to compare structures.
Some examples.

Code: Select all

x.POINT
y.POINT

Debug CompareStructure(x, y) ; Return 1 - equal.

Code: Select all

x.POINT
y.POINT\x = 10

Debug CompareStructure(x, y) ; Return 0 - not equal.

Code: Select all

Structure Test
  x.l
  List l.Test()
EndStructure

x.Test
y.Test

AddElement(x\l())
x\l()\x=10

AddElement(y\l())
y\l()\x=10

Debug CompareStructure(x, y) ; Return 1 - equal.

Code: Select all

Structure Test
  x.l
  List l.Test()
EndStructure

x.Test
y.Test

AddElement(x\l())
x\l()\x=10

AddElement(y\l())
y\l()\x=10

AddElement(y\l())


Debug CompareStructure(x, y) ; Return 0 - not equal.

Re: Compare structure

Posted: Sat Jan 19, 2019 6:29 pm
by SeregaZ
procedures have some defaults values, for example:
Procedure Main(value.a=1), so Main(5) or Main() will be correct and that procedure will know about value - it is 1.

so can be this system be apply to structures?

Code: Select all

Structure Test
  x.l=5
  y.l
EndStructure
it means when i am create some array for example Dim Array.Test(5) - all x values in each item have 5 by default, not 0 as it is now.

Re: Compare structure

Posted: Sat Jan 19, 2019 6:47 pm
by Little John
SeregaZ wrote:so can be this system be apply to structures?

Code: Select all

Structure Test
  x.l=5
  y.l
EndStructure
it means when i am create some array for example Dim Array.Test(5) - all x values in each item have 5 by default, not 0 as it is now.
This has already been suggested and discussed here.

And it is not the same topic as the topic of this thread ...

Re: Compare structure

Posted: Sat Jan 19, 2019 7:37 pm
by Sicro

Code: Select all

Macro CompareStructure(data1, data2, struc, result)
  Define json1, json2
  json1 = CreateJSON(#PB_Any)
  json2 = CreateJSON(#PB_Any)
  If json1 And json2
    InsertJSONStructure(JSONValue(json1), data1, struc)
    InsertJSONStructure(JSONValue(json2), data2, struc)
    PokeI(@result, Bool(ComposeJSON(json1) = ComposeJSON(json2)))
  EndIf
  If json1 : FreeJSON(json1) : EndIf
  If json2 : FreeJSON(json2) : EndIf
EndMacro

Structure Test
  x.l
  List l.Test()
EndStructure

x.Test
y.Test

AddElement(x\l())
x\l()\x=10

AddElement(y\l())
y\l()\x=10

CompareStructure(x, y, Test, result)
Debug result

Re: Compare structure

Posted: Sat Jan 19, 2019 7:50 pm
by Little John
Sicro wrote:

Code: Select all

Bool(ComposeJSON(json1) = ComposeJSON(json2))
Cool idea! 8)