Compare structure

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Compare structure

Post 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.
SeregaZ
Enthusiast
Enthusiast
Posts: 619
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: Compare structure

Post 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.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Compare structure

Post 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 ...
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Compare structure

Post 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
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Compare structure

Post by Little John »

Sicro wrote:

Code: Select all

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