Vladimir Nesterovsky
15 years ago
Hello!
A while ago I have proposed to introduce maps as built-in types in
xpath/xquery type system: Tuples and maps
(http://www.w3.org/Bugs/Public/show_bug.cgi?id=5630).
The suggestion has been declined (probably my arguments were not
convincing). I, however, still think that maps along with sequences are
primitives required to build sensible (not obscure one) algorithms. To
see that map is at times is the best way to resolve the problems we shall
refer to an utility function to allocate names in scope. Its signature
looks
like this:
<!--
Allocates unique names in the form $prefix{number}?.
Note that prefixes may coincide.
$prefixes - a name prefixes.
$names - allocated names pool.
$name-max-length - a longest allowable name length.
Returns unique names.
-->
<xsl:function name="t:allocate-names" as="xs:string*">
<xsl:param name="prefixes" as="xs:string*"/>
<xsl:param name="names" as="xs:string*"/>
<xsl:param name="name-max-length" as="xs:integer?"/>
Just try to program it and you will find yourselves coding something like
one defined at cobolxom
(http://www.nesterovsky-bros.com/download/cobol-names.xslt).
To be efficient such maps should provide, at worst, a logarithmic
operation
complexity:
Access to the map through a key (and/or by index) - complexity is LnN;
Creation of a new map with added or removed item - complexity is LnN;
Construction of the map from ordered items - complexity is O(N);
Construction of the map from unordered items - complexity is O(N*LnN);
Total enumeration of all items - complexity is O(N*LnN);
These performance metrics are found in many functional and procedural
implementations of the maps. Typical RB and AVL tree based maps satisfy
these restrictions.
What I suggest is to introduce map implementation into the exslt (assuming
inline functions are present). As a sketch I have implemented pure AVL
Tree
in Xslt 2.0
(http://www.nesterovsky-bros.com/weblog/2010/02/28/AVLTreeInXslt.aspx):
test.xslt (http://www.nesterovsky-bros.com/download/tree/test.xslt) - a
little test;
tree.xslt (http://www.nesterovsky-bros.com/download/tree/tree.xslt) - an
AVL
tree implementation;
tuple.xslt (http://www.nesterovsky-bros.com/download/tree/tuple.xslt) - a
tuple interface and implementation.
I do not assume that implementation like this should be used, but rather
think of some extension function(s) that provide(s) a better performance.
What do you think?
Are maps with required operation complexity already implemented and I've
just missed them?
Thanks.
--
Vladimir Nesterovsky
http://www.nesterovsky-bros.com/
A while ago I have proposed to introduce maps as built-in types in
xpath/xquery type system: Tuples and maps
(http://www.w3.org/Bugs/Public/show_bug.cgi?id=5630).
The suggestion has been declined (probably my arguments were not
convincing). I, however, still think that maps along with sequences are
primitives required to build sensible (not obscure one) algorithms. To
see that map is at times is the best way to resolve the problems we shall
refer to an utility function to allocate names in scope. Its signature
looks
like this:
<!--
Allocates unique names in the form $prefix{number}?.
Note that prefixes may coincide.
$prefixes - a name prefixes.
$names - allocated names pool.
$name-max-length - a longest allowable name length.
Returns unique names.
-->
<xsl:function name="t:allocate-names" as="xs:string*">
<xsl:param name="prefixes" as="xs:string*"/>
<xsl:param name="names" as="xs:string*"/>
<xsl:param name="name-max-length" as="xs:integer?"/>
Just try to program it and you will find yourselves coding something like
one defined at cobolxom
(http://www.nesterovsky-bros.com/download/cobol-names.xslt).
To be efficient such maps should provide, at worst, a logarithmic
operation
complexity:
Access to the map through a key (and/or by index) - complexity is LnN;
Creation of a new map with added or removed item - complexity is LnN;
Construction of the map from ordered items - complexity is O(N);
Construction of the map from unordered items - complexity is O(N*LnN);
Total enumeration of all items - complexity is O(N*LnN);
These performance metrics are found in many functional and procedural
implementations of the maps. Typical RB and AVL tree based maps satisfy
these restrictions.
What I suggest is to introduce map implementation into the exslt (assuming
inline functions are present). As a sketch I have implemented pure AVL
Tree
in Xslt 2.0
(http://www.nesterovsky-bros.com/weblog/2010/02/28/AVLTreeInXslt.aspx):
test.xslt (http://www.nesterovsky-bros.com/download/tree/test.xslt) - a
little test;
tree.xslt (http://www.nesterovsky-bros.com/download/tree/tree.xslt) - an
AVL
tree implementation;
tuple.xslt (http://www.nesterovsky-bros.com/download/tree/tuple.xslt) - a
tuple interface and implementation.
I do not assume that implementation like this should be used, but rather
think of some extension function(s) that provide(s) a better performance.
What do you think?
Are maps with required operation complexity already implemented and I've
just missed them?
Thanks.
--
Vladimir Nesterovsky
http://www.nesterovsky-bros.com/