Changeset 27114 in project


Ignore:
Timestamp:
07/23/12 07:47:22 (9 years ago)
Author:
Jim Ursetto
Message:

chicken-doc 0.4.4: Node matching API may now limit size of returned result set.

Location:
release/4/chicken-doc/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/chicken-doc/trunk/chicken-doc.meta

    r23255 r27114  
    88        (fmt 0.706) sxml-transforms ; chicken-doc-text
    99        )
    10  (files "chicken-doc-text.scm" "chicken-doc.meta" "chicken-doc.scm" "chicken-doc-cmd.scm" "chicken-doc.release-info" "chicken-doc.setup"))
     10 )
  • release/4/chicken-doc/trunk/chicken-doc.scm

    r20465 r27114  
    500500
    501501;; Returns list of nodes matching identifier ID.
    502 ;; ID may be a symbol or string.
    503 (define (match-nodes/id id)
     502;; ID may be a symbol or string.  LIMIT is an integer
     503;; indicating the maximum number of results to return,
     504;; or #f for no limit.
     505(define (match-nodes/id id #!optional limit)
    504506  (define (lookup id)
    505507    (id-cache-ref (current-id-cache) id))
     508  (define (take-up-to lim L)
     509    (let loop ((i 0) (L L) (acc '()))
     510      (if (or (>= i lim) (null? L))
     511          (reverse acc)
     512          (loop (add1 i) (cdr L) (cons (car L) acc)))))
    506513  (validate-id-cache! (current-repository))
    507514  (let ((id (if (string? id) (string->symbol id) id)))
    508515    (map (lambda (x)
    509516           (lookup-node (append x (list id))))
    510          (lookup id))))
    511 
    512 (define (vector-filter-map f v)
     517         (if limit
     518             (take-up-to limit (lookup id))
     519             (lookup id)))))
     520
     521(define (vector-filter-map f v #!optional (limit -1))
    513522  ;; filter-map vector V to list.  this is here because
    514   ;; we converted the id-cache-ids to a vector.
     523  ;; we converted the id-cache-ids to a vector.  If limit is
     524  ;; given and non-negative, limits returned results.
    515525  (let ((len (vector-length v)))
    516     (let lp ((i 0) (L '()))
    517       (if (fx>= i len)
     526    (let lp ((i 0) (L '()) (left limit))
     527      (if (or (fx>= i len)
     528              (= 0 left))
    518529          (reverse L)
    519           (lp (fx+ i 1)
    520               (cond ((f i (vector-ref v i))
    521                      => (lambda (x) (cons x L)))
    522                     (else
    523                      L)))))))
     530          (let ((x (f i (vector-ref v i))))
     531            (if x
     532                (lp (fx+ i 1) (cons x L) (fx- left 1))
     533                (lp (fx+ i 1) L left)))))))
    524534(define (vector-copy v #!optional (start 0) (end (vector-length v)) (fill (void)))
    525535  ;; SRFI-43 vector-copy.  Why is vector-lib's implementation so verbose?
     
    537547                (else c)))))))
    538548
    539 
    540 ;; Returns list of nodes whose identifiers
    541 ;; match regex RE.
    542 (define (match-nodes/re re)
     549;; Like append-map, but caps returned list length at LIM, an integer.
     550;; Negative LIM means unlimited.  Also passes the remaining LIM to F
     551;; so F may optionally limit its own output to save computation.
     552;; Note this algorithm is iterative (in both the inner and outer loop)
     553;; unlike SRFI 1 append-map.
     554(define (append-map/limit f L lim)
     555  (let loop ((lim lim) (R '()) (L L))
     556    (if (or (null? L)
     557            (= lim 0))
     558        (reverse R)
     559        (let inner ((lim lim)
     560                    (R R)
     561                    (M (f (car L) lim)))
     562          (if (or (null? M)
     563                  (= lim 0))
     564              (loop lim R (cdr L))
     565              (inner (- lim 1)
     566                     (cons (car M) R)
     567                     (cdr M)))))))
     568
     569;; Returns list of nodes whose identifiers match regex RE.
     570;; Optional LIMIT is an integer indicating maximum number of results to
     571;; return, or #f for unlimited.
     572(define (match-nodes/re re #!optional limit)
    543573  (let ((rx (irregex re)))
    544574    (validate-id-cache! (current-repository))
    545     (append-map (lambda (id)
    546                   (match-nodes id))
    547                 (vector-filter-map (lambda (i k)   ; was filter-map
    548                                      (and (string-search rx k) k))
    549                                    (id-cache-ids (current-id-cache))))))
    550 
    551 ;; Match against full node paths with RE.
    552 (define (match-node-paths/re re)
     575    (append-map/limit
     576     (lambda (id lim) (match-nodes/id id (if (< lim 0) #f lim)))
     577     (vector-filter-map (lambda (i k)   ; was filter-map
     578                          (and (string-search rx k) k))
     579                        (id-cache-ids (current-id-cache))
     580                        ;; Upper bound on results we need, since match-nodes
     581                        ;; will return 1 or more per call.  Thus we do some
     582                        ;; regex work here that may be thrown away.
     583                        (if limit limit -1))
     584     (if limit limit -1))))
     585
     586;; Match against full node paths with RE.  Optional LIMIT is
     587;; an integer indicating maximum number of results to
     588;; return, or #f for unlimited.
     589(define (match-node-paths/re re #!optional limit)
    553590  (let ((rx (irregex re)))
    554591    (validate-id-cache! (current-repository))
     
    557594         (vector-filter-map (lambda (i k)
    558595                              (and (string-search rx k) k))
    559                             (id-cache-paths (current-id-cache))))))
     596                            (id-cache-paths (current-id-cache))
     597                            (if limit limit -1)))))
    560598
    561599;; Search for "nearest" VAL in vector V at start or end of a range.
     
    667705;; Return list of nodes whose identifiers match
    668706;; symbol, string or re.
    669 (define (match-nodes idre)
     707(define (match-nodes idre #!optional limit)
    670708  (if (or (irregex? idre) (regexp? idre))
    671       (match-nodes/re idre)
    672       (match-nodes/id idre)))
     709      (match-nodes/re idre limit)
     710      (match-nodes/id idre limit)))
    673711
    674712(define (search-and-describe id)
  • release/4/chicken-doc/trunk/chicken-doc.setup

    r23058 r27114  
    1 (define version "0.4.3")
     1(define version "0.4.4")
    22
    33(compile -s -O2 -d1 -S chicken-doc.scm -j chicken-doc -j chicken-doc-text)
Note: See TracChangeset for help on using the changeset viewer.