[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Boolean logic


Subject: Re: [xsl] Boolean logic
From: davep <davep@xxxxxxxxxxxxx>
Date: Tue, 03 Jan 2012 18:14:29 +0000

On 01/03/2012 02:11 PM, David Carlisle wrote:
On 29/12/2011 14:48, davep wrote:
Select line:
   if n < 100 then 1
   if n < 200 then 2
   if n < 300 then 3
  etc.

isn't that bit just n idiv 256 + 1 rather than a repeated 'if' test?

Yes. Simplified when I re-wrote it.



except that I'm confused as assuming a line position assumes that your array is a dense format with all lines present, but I suspect it isn't, so rather than a line number don't you just want to select a line with the appropriate base child, something like:


line[base = (n idiv 256)]

If you look at the lines, you'll see the 0'th element is the 'base' for that line,
which then fills in the next 256 character positions.
So yes, it is sparse.



presumably things would be more efficient if you pre-processed the input array into some more amenable format, especially as xpath can't natively deal with integers written in hex?

Yes, easy enough. It's generated using awk. As you can see, it is quite sparse.

Mostly done in Python, but if anyone fancies some bit - twiddling
in xslt 2.0 (3.0???) This function is pretty key

#bit test, in 32 bit word
#@param1 word, 32bit unsigned int
#@para2, 0<bit<31  int representing bit to be tested
#   bit 0 is msb, bit 31 is ls bit
# return true, bit is set, false, bit is clear
def bitest(word,bit):
    if (bit < 0) | (bit > 31):
        sys.stderr.writelines("bitest: invalid bit pattern, %d" % bit)
        sys.exit(2)
    #convert 'bit' into pattern
    matchpatt= int('80000000',16)>>bit
    return bool(word & matchpatt)

Shift right 'bit' bits? Divide by 2^bit?
Kens http://www.cranesoftwrights.com/resources/bittest/index.htm seems right.


regards daveP




<glyphs> <line><base>0</base> <gp>0</gp><gp>4294967295</gp><gp>4294967295</gp><gp>2147483647</gp> <gp>0</gp><gp>4294959102</gp><gp>4294967295</gp><gp>4294967295</gp> </line> <line><base>1</base> <gp>4294967295</gp><gp>4278190079</gp><gp>4294967295</gp><gp>4294967295</gp> <gp>262144</gp><gp>8486915</gp><gp>0</gp><gp>4231004160</gp> </line> <line><base>2</base> <gp>50331648</gp><gp>0</gp><gp>0</gp><gp>0</gp> <gp>262144</gp><gp>25493504</gp><gp>1056964800</gp><gp>8</gp> </line> <line><base>3</base> <gp>262656</gp><gp>8</gp><gp>0</gp><gp>1143996416</gp> <gp>4294957040</gp><gp>4294967291</gp><gp>1147371519</gp><gp>1</gp> </line> <line><base>4</base> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> <gp>0</gp><gp>0</gp><gp>786432</gp><gp>192</gp> </line> <line><base>30</base> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> <gp>63</gp><gp>4294967295</gp><gp>4294967295</gp><gp>67108863</gp> </line> <line><base>31</base> <gp>1061158911</gp><gp>4294967295</gp><gp>2868854591</gp><gp>1073741823</gp> <gp>4294967295</gp><gp>4292870143</gp><gp>4023386079</gp><gp>2145189887</gp> </line> <line><base>32</base> <gp>2147421172</gp><gp>1443692647</gp><gp>16</gp><gp>4293984256</gp> <gp>32767</gp><gp>4254</gp><gp>0</gp><gp>0</gp> </line> <line><base>33</base> <gp>4718624</gp><gp>16452</gp><gp>4294443008</gp><gp>0</gp> <gp>2097152</gp><gp>256</gp><gp>0</gp><gp>0</gp> </line> <line><base>34</base> <gp>1141276740</gp><gp>3968</gp><gp>288</gp><gp>51</gp> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> </line> <line><base>35</base> <gp>65536</gp><gp>0</gp><gp>0</gp><gp>0</gp> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> </line> <line><base>37</base> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> <gp>0</gp><gp>3074</gp><gp>33792</gp><gp>64</gp> </line> <line><base>224</base> <gp>0</gp><gp>0</gp><gp>112</gp><gp>2048</gp> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> </line> <line><base>245</base> <gp>134086655</gp><gp>0</gp><gp>0</gp><gp>0</gp> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> </line> <line><base>246</base> <gp>0</gp><gp>4261412864</gp><gp>2145583111</gp><gp>4294961150</gp> <gp>4294967295</gp><gp>802815</gp><gp>805424648</gp><gp>4294967061</gp> </line> <line><base>247</base> <gp>0</gp><gp>2214527058</gp><gp>0</gp><gp>134217727</gp> <gp>0</gp><gp>2165342466</gp><gp>0</gp><gp>4286578687</gp> </line> <line><base>251</base> <gp>31</gp><gp>0</gp><gp>0</gp><gp>0</gp> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> </line> <line><base>255</base> <gp>0</gp><gp>0</gp><gp>0</gp><gp>0</gp> <gp>0</gp><gp>0</gp><gp>0</gp><gp>268435456</gp> </line> </glyphs>







regards

--
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk


Current Thread
Keywords