Better/Faster method to find the next element in tree order with certain GIs

Subject: Better/Faster method to find the next element in tree order with certain GIs
From: "P. Stritzi" <e6g1m6n3@xxxxxx>
Date: Sun, 2 May 1999 20:10:43 +0200 (MEST)
Hi,

I need to find the next element in tree order that has a GI
that is in a specified set.  I need this when producing a
set of HTML pages from a single XML file to build a [Next]
Link.

The code I came up with is not quite fast (it takes about
2/3 of the overall running time) and I have the feeling there should
be a more elegant solution.

; This ist the set of GI's the ``next'' element should be
; in.

(define pageoids
  '("page" "pro-data" "pro-group" "product" "pro-multi" "ib-entry"))
(define (pageoid? snl)
  (if (member (gi snl) pageoids) #t #f)) 


; Here I build a node-list of all elements that follow `snl'
; in tree order.

(define (tree-following-elements snl)
  (let loop ((rest (select-by-class
		    (subtree (tree-root snl)) 'element)))
    (cond ((node-list-empty? rest) (empty-node-list))
	  ((node-list=? (node-list-first rest) snl)
	   (node-list-rest rest))
	  (else (loop (node-list-rest rest))))))

; I get the wanted node by finding the first matching
; element on the list of all elements following `snl'.

(define (next-pageoid snl)
  (let loop ((rest (tree-following-elements snl)))
    (cond ((node-list-empty? rest) (empty-node-list))
	  ((pageoid? (node-list-first rest))
	   (node-list-first rest))
	  (else (loop (node-list-rest rest))))))


One alternative I can think of is to look at the elements in
tree order by looking at the children first then recurse for
the next sibling, if its the last to the siblings of the
parent etc. until I find the wanted element.  But this
doesnt sound very elegant to me even it may be faster for my
data.

Any suggestions?

Thanks
Peer Stritzinger


---
Sent through Global Message Exchange - http://www.gmx.net


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread