Hello,

I'm looking for a "convenient" way to implement a type for kinds of flexible 
records. "Best" means simple and efficient. A flexible record is a kind of set 
of name:value symbol, but completely modifyable at runtime. The necessary 
untyped aspect of the question is handled by values beeing pointers.
Compared to a mapping *collection*, these objects have some specificity:
* conceptually, each one forms a single, whole, data unit -- as opposed to a 
set of data.
* Keys are all names (thus, a subset of string), and rather short.
* The number of symbols is typically small; these object are defined by hand! 
As opposed to extremely varying & possibly huge numbers of collection items.

The most important operation for such an object is value lookup. Some trials 
have shown me that data structures with sophisticated algorithms such as radix 
tries or hash table are counter productive (they are severely outperformed by 
simple sequences up to > 100 items). --> 
http://groups.google.com/group/pilud/browse_thread/thread/9d7992f97c976cef#



The simplest method may be to create a tool type for name:value symbols, and 
put this into a TFPList. Lookup is thus traversing the sequence, checking the 
name until found, returning the value.

Another way would be to hold // sequences for names and values. Lookup should 
be faster, since names are not hidden in symbol structure. Once a name's index 
is known, the matching value can be reached using this index. I guess the name 
sequence could be at best a linked list, since it's only traversed; while 
values, which are only indexed, should be held in a flexible array (TFPList) 
for direct indexing. Comments?



But I'm a bit troubled by the documentation about TStrings. TStrings declares 
interface methods to deal with "associated objects" (not implemented) and 
"value parts", eg:
   function AddObject(); virtual;   Add a string and associated object to the 
list.
   property ValueFromIndex: String; [rw]   Return the value part of a string 
based on it's index.
The description of the type reads:
"...  It also allows an arbitrary object to be associated with each string.
It also introduces methods to manage a series of name=value settings, as found 
in many configuration files..."

Side-question: What is the purpose of introducing unimplemented methods? 
Sub-classes can extend a super-class anyway, no? Is it just an incentive to 
implement those methods?

I would like to know the underlying structure of TString (linked list, 
"flexible-ised" dynamic array, what else?).
What is actually a name:value association? How does it work and how is one 
supposed to use it? The _name_ of the feature perfectly fits my needs :-) but 
can I use it for my flexible record type?
Associated objects are not implemented at all (all methods virtual). How is one 
supposed to design such a feature? Associate a // list of objects (maintaining 
matching indexes)? But if a TString is an array, lookup is probably slower than 
necessary (since it's a plain traversal), or am I wrong on this?

Thank you for your patience with a newcomer :-)


Denis
________________________________

vit esse estrany ☣

spir.wikidot.com
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to