[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: lookup-table thoughts (was Re: matching multip

Subject: Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?
From: Tom Myers <tommy@xxxxxxxxxxxxxx>
Date: Thu, 08 Nov 2001 19:24:00 -0500
log lookup table
Jeni Tennison wrote

>Mike Kay wrote: 
> > As for the divide-and-conquer algorithm, it looks interesting and 
> > performs well, but as it produces completely different output from 
> > the other two, I can't quite see the relevance.
>Gah, yes, my idiocy. Dimitre, can you see a way of using a divide 
>and conquer algorithm to produce a multiply-nested tree?
><xsl:call-template name="accumDivAndConquer"> 
><xsl:with-param name="count" select="3" /> 
><xsl:with-param name="base" select="'foo'" /> 
></xsl:call-template>
>producing:
><foo> 
><foo> 
><foo>foo</foo> 
></foo> 
></foo>
>Jeni
>- --- 
and probably Dimitre has already answered (I'm on digest) but
here's one version, based on the idea that
   dC(5,"foo") = <X><X><X><X><X>foo</X></X></X></X></X> via
   dC(0,A) = A
   dC(2*N,A) = dC(N,dC(N,A))
   dC(2*N+1,A) = dC(N, dC(N, cons("X",A) ) )
so I expect stack depth to be O(log(N)), time to be O(N^2),
max space to be O(N), space allocation to be O(N^2)...rather
like the tail-recursive except for O(log(N)) instead of O(1)
stack space, and of course not needing anything special in
the engine.
------------------------------

<xsl:template name="divConq">
   <xsl:param name="N" select="10"/>
   <xsl:param name="A" select="/.."/>
   <xsl:param name="Ndiv2" select="($N - $N mod 2) div 2"/>
   <xsl:choose>
     <xsl:when test="not($N)"><xsl:copy-of select="$A"/></xsl:when>
     <xsl:otherwise>     
        <xsl:variable name="onebase"> 
          <xsl:choose>
            <xsl:when test="$N mod 2">
              <X><xsl:copy-of select="$A"/></X>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="$A"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="halfway">
          <xsl:call-template name="divConq">
            <xsl:with-param name="N" select="$Ndiv2"/>
            <xsl:with-param name="A" select="$onebase"/>
          </xsl:call-template>
       </xsl:variable>
       <xsl:call-template name="divConq">
          <xsl:with-param name="N" select="$Ndiv2"/>
          <xsl:with-param name="A" select="$halfway"/>
       </xsl:call-template>
    </xsl:otherwise>
   </xsl:choose>
</xsl:template>
----------------------------------------

hope that makes sense...

Tom Myers


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.