DataStructure

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2798
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

DataStructure

Post by Michael Vogel »

According to some ideas like StringSection I'd like to ask if the DataSection command could get some improvements...
...I have a list of more than 20.000 cities, their country and latitude/longitude values. I'd like to include the list into a PB source to have the data "onboard" -- and as compact as possible.

So the country will be translated to a single byte and the coordinates to floats, the cityname will be kept as a string:

Code: Select all

Andorra la Vella	1	42,51	1,51
Les Escaldes	1	42,50	1,53
Abû Zabi     	2	24,48	54,37
al-ŽAyn       	2	24,23	55,74
Khawr Fakkân	2	25,34	56,36
:
When I transfer this to PB, I have two possiblities, one is to write three lines for each city...

Code: Select all

Data.s	Andorra la Vella
Data.b	1
Data.f	42.51	1.51
...or to split the data into three (or four) different areas:

Code: Select all

Data.s	"Andorra la Vella","Les Escaldes",...
Data.b	1,1,2,...
Data.f	Data42.51,1.51,42.50,...
Would anyone see an improvement in having the possibility to get different data types in one Data row? I'm not sure, if such things are needed often (for me, this is the first time, I think about such things :wink:) -- however, a data section could look like this:

Code: Select all

DataStructure .x Uses "sbff"
Data.x "Andorra la Vella",1,42.51,1.51
Data.x "Les Escaldes,1,42.50,1.53
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: DataStructure

Post by KJ67 »

Something like

Code: Select all

Structure XYZ
  a.i
  b.s
  c.f
  d.f
EndStructure

DataSection
  Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
would be very useful
The best preparation for tomorrow is doing your best today.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: DataStructure

Post by blueznl »

Oh, KJ67, that's a nice idea! And it matches the generic syntax of PureBasic nicely!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Re: DataStructure

Post by mback2k »

blueznl wrote:Oh, KJ67, that's a nice idea! And it matches the generic syntax of PureBasic nicely!
Yeah, this idea is a lot more PureBasic-style than the StringSection thing.
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: DataStructure

Post by Seymour Clufley »

mback2k wrote:Yeah, this idea is a lot more PureBasic-style than the StringSection thing.
It's a completely different thing. This doesn't address multilines, Chr(34)s within the string etc., which is what my StringSection request is about.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: DataStructure

Post by flaith »

KJ67 wrote:Something like

Code: Select all

Structure XYZ
  a.i
  b.s
  c.f
  d.f
EndStructure

DataSection
  Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
would be very useful
And how do you read the datas ?
“Fear is a reaction. Courage is a decision.” - WC
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: DataStructure

Post by KJ67 »

Code: Select all

Structure XYZ
  a.i
  b.s
  c.f
  d.f
EndStructure

Define.XYZ MyVar

Restore MyData
Read.XYZ MyVar

DataSection
MyData:
  Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
Why not follow the rules that already exists, just allow reading structures too?
Personally I do not need any brand new function, just a update of the already existing rules and function.
The best preparation for tomorrow is doing your best today.
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: DataStructure

Post by flaith »

:D hey, really neat that way
“Fear is a reaction. Courage is a decision.” - WC
User avatar
Demivec
Addict
Addict
Posts: 4261
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: DataStructure

Post by Demivec »

Wouldn't this problem be the same as the one in the file library. If a structure was read from a file you would still need to use ReadInteger(), ReadString(), and ReadFloat().

If a solution like that mentioned above is implemented for the DataSection then it can be done for the file library by using a ReadStructure(fileID, *pointer, structure). At least it would seem reasonable. Likewise a WriteStructure(fileID, *pointer, structure) could be possible.

Code: Select all

Structure XYZ
  a.i
  b.s
  c.f
  d.f
EndStructure

Define fileID = 0

If OpenFile(fileID,"C:\outputFile")
  Define.XYZ MyVar
  Restore MyData
  Read.XYZ MyVar
  WriteStructure(fileID,@MyVar,XYZ)
  
  CloseFile(fileID)
EndIf 

DataSection
  MyData:
  Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection

It certainly would fill in a few holes. I'm not sure how many it would create though. :)
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: DataStructure

Post by jamirokwai »

KJ67 wrote:

Code: Select all

Structure XYZ
  a.i
  b.s
  c.f
  d.f
EndStructure

Define.XYZ MyVar

Restore MyData
Read.XYZ MyVar

DataSection
MyData:
  Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
Why not follow the rules that already exists, just allow reading structures too?
Personally I do not need any brand new function, just a update of the already existing rules and function.
Great Idea!
Regards,
JamiroKwai
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: DataStructure

Post by ts-soft »

Demivec wrote:Wouldn't this problem be the same as the one in the file library. If a structure was read from a file you would still need to use ReadInteger(), ReadString(), and ReadFloat().

If a solution like that mentioned above is implemented for the DataSection then it can be done for the file library by using a ReadStructure(fileID, *pointer, structure). At least it would seem reasonable. Likewise a WriteStructure(fileID, *pointer, structure) could be possible.

Code: Select all

Structure XYZ
  a.i
  b.s
  c.f
  d.f
EndStructure

Define fileID = 0

If OpenFile(fileID,"C:\outputFile")
  Define.XYZ MyVar
  Restore MyData
  Read.XYZ MyVar
  ;WriteStructure(fileID,@MyVar,XYZ)
  WriteData(fileID, @MyVar, SizeOf(XYZ))
 
  CloseFile(fileID)
EndIf

DataSection
  MyData:
  Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection 
The only problem is a non fixed String, but with WriteStructure should the same problem
User avatar
Demivec
Addict
Addict
Posts: 4261
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: DataStructure

Post by Demivec »

ts-soft wrote:The only problem is a non fixed String, but with WriteStructure should the same problem
Well, since these are only wishes it means that is what would be taken care of by the developers. :wink:

Since my suggestion for files, and the other's for datasections would be compile-time functions that would transform into an appropriate series of actions based on the structure, it shouldn't be hard to deal with a 'normal' string. There would be other problems, but not that one.

These are just ideas, all can be accomplished with what currently exists.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: DataStructure

Post by Tenaja »

KJ67 wrote:Something like

Code: Select all

Structure XYZ
  a.i
  b.s
  c.f
  d.f
EndStructure

DataSection
  Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
would be very useful
+1
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: DataStructure

Post by davido »

+1

I'd like it for my 25,000 Uk places
DE AA EB
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: DataStructure

Post by heartbone »

Michael Vogel wrote:According to some ideas like StringSection I'd like to ask if the DataSection command could get some improvements...
...I have a list of more than 20.000 cities, their country and latitude/longitude values. I'd like to include the list into a PB source to have the data "onboard" -- and as compact as possible.

So the country will be translated to a single byte and the coordinates to floats, the cityname will be kept as a string:

Code: Select all

Andorra la Vella	1	42,51	1,51
Les Escaldes	1	42,50	1,53
Abû Zabi     	2	24,48	54,37
al-ŽAyn       	2	24,23	55,74
Khawr Fakkân	2	25,34	56,36
:
When I transfer this to PB, I have two possiblities, one is to write three lines for each city...

Code: Select all

Data.s	Andorra la Vella
Data.b	1
Data.f	42.51	1.51
...or to split the data into three (or four) different areas:

Code: Select all

Data.s	"Andorra la Vella","Les Escaldes",...
Data.b	1,1,2,...
Data.f	Data42.51,1.51,42.50,...
Would anyone see an improvement in having the possibility to get different data types in one Data row? I'm not sure, if such things are needed often (for me, this is the first time, I think about such things :wink:) -- however, a data section could look like this:

Code: Select all

DataStructure .x Uses "sbff"
Data.x "Andorra la Vella",1,42.51,1.51
Data.x "Les Escaldes,1,42.50,1.53
Since you guys are continuing to extend this three plus year old thread, I'll throw in my 2¢.
The original poster's premise is that he has two possibilities.

I see many other ways to get the job done, that is to achieve "I'd like to include the list into a PB source to have the data "onboard" -- and as compact as possible."

Using a float to store the coordinates, when they only run to two decimal places is a waste but could be supported.

How about using an integer and dividing it by 100 to get the float value?

How about storing said integer (as well as the country byte) in a fixed field string and then converting the substring into your float after reading the data?

Code: Select all

;       LLLLLLLLLLLLLLLLLLLLLCCCYYYYYXXXXX
Data.s "Andorra la Vella1    0010425100151"
That approach would certainly get that job requirement done quickly by properly using the language as it exists, would it not?
Keep it BASIC.
Post Reply