Best way of handling a certain given datastructure
Best way of handling a certain given datastructure
(OP)
Hi,
Given is the following form of datastructure
set a { DATE "2019-05-12"
{ PARAMETERS { { NAME "LENGTH" VALUE "100" }
{ NAME "HEIGHT" VALUE "314" }
{ NAME "WEIGHT" VALUE "1000" }
{ NAME "COLOR" VALUE "blue" } ) )
In reality, this datastructure is much bigger. The structure is given by a certain software as a result.
What is the advantage of storeing to key-value pairs which keys are NAME and VALUE and which first value
looks like a key and its second value is the value (instead of storing "real" key-value pairs like "Weight" 1000)?
How can I effectively access this structure to retrieve - say - the COLOR "blue" from it?
Thanks in advance!
Given is the following form of datastructure
set a { DATE "2019-05-12"
{ PARAMETERS { { NAME "LENGTH" VALUE "100" }
{ NAME "HEIGHT" VALUE "314" }
{ NAME "WEIGHT" VALUE "1000" }
{ NAME "COLOR" VALUE "blue" } ) )
In reality, this datastructure is much bigger. The structure is given by a certain software as a result.
What is the advantage of storeing to key-value pairs which keys are NAME and VALUE and which first value
looks like a key and its second value is the value (instead of storing "real" key-value pairs like "Weight" 1000)?
How can I effectively access this structure to retrieve - say - the COLOR "blue" from it?
Thanks in advance!
RE: Best way of handling a certain given datastructure
For example you could have at 2019-05-12 this set of parameters
LENGTH = "100"
HEIGHT = "314"
WEIGHT = "1000"
COLOR" = "blue"
and on 2019-12-12 a set of parameters like this
LENGTH = "200"
HEIGHT = "614"
WEIGHT = "2000"
COLOR = "red"
The you could store the parameters in a data structure like above and later retrieve for given date the appropriate parameter set like this:
CODE
Output:
CODE
RE: Best way of handling a certain given datastructure
Thank you very much for your answer and your coding! :)
I was astonished about one detail of the layout of that structure:
The usage of NAME and VALUE as keys and (for example) "LENGTH" and "100" as
their values instead of using "LENGTH as key and "100" as its value.
I think (please correct me...that's why I am asking in this forum about this! :) )
that this layout makes a direct access to a searched key-value pair via the dict
command of TCL impossible and one needs a linear search to access a certain
information.
What do you think?
RE: Best way of handling a certain given datastructure
I thing the same as you.
For direct searching I would use a dictionary of dictionaries like you mentioned.
From this data structure we could retrieve for given date the appropriate parameter set at similar way:
CODE
Output:
CODE
RE: Best way of handling a certain given datastructure
I am feeling better now... :)
A big thank you for adapting your tcl examples according to the progress in the thread! :)
I initially asked for a way to efficiently access the data structure, because I didn't understand
the reason behind this special NAME "x" VALUE "y" layout thinking of something real "deep TCL", I
had simply overlooked.
But as you also think, that a real key-value layout of a real dictionary would be better for searching, I am sure,
that there is no "deep TCL" behind the NAME "x" VALUE "y" layout -- at least when it comes to retrieving values from it.
May be I get the chance to ask the author of that software (which creates that NAME/VALUE-structure initially), for the
reason for that layout...
Will see...
Thank you very much, mikrom, for your effort to help me and your help!
Cheers! :)
tuxic
RE: Best way of handling a certain given datastructure
I have not deep tcl knowledge, but if you have the original data structure as you mentioned, you can transform it programmatically into a simpler data structure you desired.
Here is a little example:
CODE
Output:
CODE