Re: Proposed note for insert and new functions for XForms 2.0

John,

I included some remarks/questions inline.

Kind regards,

Nick Van den Bleeken
R&D Manager

Phone: +32 3 821 01 70
Office fax: +32 3 821 01 71
nick.van.den.bleeken@inventivegroup.com<mailto:nick.van.den.bleeken@inventivegroup.com>
www.inventivedesigners.com


[cid:image001.png@01CBF2F8.1DA19110][cid:image002.png@01CBF2F8.1DA19110][cid:image003.png@01CBF2F8.1DA19110]

On 28 Sep 2011, at 23:51, John Boyer wrote:
RECOMMENDATION: Add a function with signature along the lines of "nodeset first-child(nodeset?, boolean?)" that returns the first child node of a given node, or the context node if no first parameter.  The function SHOULD achieve O(1) on the operation.  By default ignore whitespace text nodes, but if second parameter given and true, then include them in result.

With this function implemented efficiently (and the efficient insert above), N stack operations will take O(N) processing time, and without it, the result is O(N^2).
Why couldn't you just rewrite foo[1] to ibm:first-child(foo) during the static optimization phase when parsing the XPath expression (with ibm:first-child your proprietary extension function)? I think/hope that your XPath engine already does a lot other static optimizations when 'compiling/analizing' the XPath expression.

Efficiently implementing queue-based algorithms requires the ability to push on one side of a list and pop from the other.
Given the ability described above to efficiently insert at the beginning of the list, it seems we only need a way to efficiently identify the last child of a node in constant time.

RECOMMENDATION: Add a function with signature along the lines of "nodeset last-child(nodeset?, boolean?)" that returns the last child node of a given node, or the context node if no first parameter.  The function SHOULD achieve O(1) on the operation. By default ignore whitespace text nodes, but if second parameter given and true, then include them in result.

Incidentally, the last-child() function also allows efficient insertion at the end of a list of children of a node by using it in the insert nodeset.
This is helpful in creating an efficient sort that constructs its result in least to greatest order.
The efficient first-child() and last-child() functions also appear to enable optimal O(N log N) sorting via XForms action loops, when used in combination with the iterate attribute.  Without having at least first-child(), the best sort performance appears to be O(N log N log log N).

A number of more useful data structures become possible to implement if it is also possible to obtain the parent, next sibling, and previous sibling of a node in constant time.  These functions would prove convenient in implementing some sorting methods in the most natural ways, but efficient versions of several comparison-based data structures (e.g. various priority queues, trees and graphs) appear to become possible as well.
Same remark/question why don't do this during the static optimization phase when parsing the XPath expression.


RECOMMENDATION: Add functions with signatures along the lines of
"nodeset parent(nodeset?)" returns the parent of a given node, or the context node if no first parameter.
"nodeset next-sibling(nodeset?, boolean?)" returns the next sibling of a given node, or the context node if no first parameter.
"nodeset prev-sibling(nodeset?, boolean?)" returns the previous sibling of a given node, or the context node if no first parameter.

These functions SHOULD achieve O(1) on the operation. For latter two functions, ignore whitespace text nodes by default, but if second parameter given and true, then include them in result.

For all of the functions, clearly if the first, last, next, previous or parent node doesn't exist, then an empty nodeset is returned.

Finally, the eval() function is already on the list for XForms 2.0 with the use case from Michael Sperberg-McQueen of being able to use a repeat to drill into and edit arbitrarily structured XML.  A second use case for the function pertains to algorithms like sorting as well as comparison-based data structure management.  Given an eval() function, it would be possible to allow a form author to provide the comparison expression as a string so that the sort or comparison data structure could compare strings, numbers, dates or even secondary keys in case of primary key equality.  This would help separate the algorithm or data structure from the application details.
Same remark/question why don't do this during the static optimization phase when parsing the XPath expression.


RECOMMENDATION: Add function with signature along lines of "object eval(string, nodeset?, number?)" that evaluates an xpath given in the string using the evaluation context of the eval() function, or in the context of a nodeset and a node at a given position, if those params are specified.

definitely +1 for this one there is already a wiki page for this one http://www.w3.org/MarkUp/Forms/wiki/Eval_function


________________________________

Inventive Designers' Email Disclaimer:
http://www.inventivedesigners.com/email-disclaimer

Received on Thursday, 29 September 2011 18:31:50 UTC