{quick,merge}sort -> sort

svn: r2569

original commit: 16f01a1109691d2fa4844b9411410f4794cf0dc1
tokens
Eli Barzilay 18 years ago
parent 97678a2e96
commit 5112a6a054

@ -239,19 +239,19 @@
(cond (cond
((and (null? old-states) (null? new-states)) ((and (null? old-states) (null? new-states))
(make-dfa (get-state-number) (state-index start) (make-dfa (get-state-number) (state-index start)
(mergesort (filter (lambda (x) (cdr x)) (sort (filter (lambda (x) (cdr x))
(map (lambda (state) (map (lambda (state)
(cons (state-index state) (get-final (state-spec state)))) (cons (state-index state) (get-final (state-spec state))))
all-states)) all-states))
(lambda (a b) (< (car a) (car b)))) (lambda (a b) (< (car a) (car b))))
(mergesort (hash-table-map transitions (sort (hash-table-map transitions
(lambda (state trans) (lambda (state trans)
(cons (state-index state) (cons (state-index state)
(map (lambda (t) (map (lambda (t)
(cons (car t) (cons (car t)
(state-index (cdr t)))) (state-index (cdr t))))
trans)))) trans))))
(lambda (a b) (< (car a) (car b)))))) (lambda (a b) (< (car a) (car b))))))
((null? old-states) ((null? old-states)
(loop new-states null all-states (compute-chars new-states))) (loop new-states null all-states (compute-chars new-states)))
((null? cs) ((null? cs)
@ -336,4 +336,4 @@
(repetition 1 +inf.0 "1"))))))) (repetition 1 +inf.0 "1")))))))
(define t14 (build-test-dfa `((complement "1")))) (define t14 (build-test-dfa `((complement "1"))))
|# |#
) )

@ -31,7 +31,7 @@
(let* ((from-state (car trans)) (let* ((from-state (car trans))
(all-chars/to (cdr trans)) (all-chars/to (cdr trans))
(flat-all-chars/to (flat-all-chars/to
(mergesort (sort
(apply append (apply append
(map (lambda (chars/to) (map (lambda (chars/to)
(let ((char-ranges (loc:integer-set-contents (car chars/to))) (let ((char-ranges (loc:integer-set-contents (car chars/to)))

@ -85,7 +85,7 @@
;; Sorts l according to index and removes the entries with duplicate ;; Sorts l according to index and removes the entries with duplicate
;; indexes. ;; indexes.
(define (do-simple-equiv l index) (define (do-simple-equiv l index)
(let ((ordered (mergesort l (lambda (a b) (< (index a) (index b)))))) (let ((ordered (sort l (lambda (a b) (< (index a) (index b))))))
(remove-dups ordered index null))) (remove-dups ordered index null)))
(test-block () (test-block ()

@ -28,7 +28,7 @@
(non-term-index (trans-key-gs b))))))) (non-term-index (trans-key-gs b)))))))
(define (trans-key-list-remove-dups tkl) (define (trans-key-list-remove-dups tkl)
(let loop ((sorted (quicksort tkl trans-key<?))) (let loop ((sorted (sort tkl trans-key<?)))
(cond (cond
((null? sorted) null) ((null? sorted) null)
((null? (cdr sorted)) sorted) ((null? (cdr sorted)) sorted)
@ -39,9 +39,8 @@
(kernel-index (trans-key-st (cadr sorted))))) (kernel-index (trans-key-st (cadr sorted)))))
(loop (cdr sorted)) (loop (cdr sorted))
(cons (car sorted) (loop (cdr sorted)))))))) (cons (car sorted) (loop (cdr sorted))))))))
;; build-transition-table : int (listof (cons/c trans-key X) -> ;; build-transition-table : int (listof (cons/c trans-key X) ->
;; (vectorof (symbol X hashtable)) ;; (vectorof (symbol X hashtable))
(define (build-transition-table num-states assoc) (define (build-transition-table num-states assoc)
@ -279,7 +278,7 @@
(let* ((gs (car i)) (let* ((gs (car i))
(items (cadr i)) (items (cadr i))
(new #f) (new #f)
(new-kernel (quicksort (new-kernel (sort
(filter (lambda (x) x) (filter (lambda (x) x)
(map move-dot-right items)) (map move-dot-right items))
item<?)) item<?))
@ -370,4 +369,4 @@
(car (q-f q)) (car (q-f q))
(set-q-f! q (cdr (q-f q))))) (set-q-f! q (cdr (q-f q)))))
) )

@ -124,8 +124,8 @@
(let ((t (get-token-grammar i))) (let ((t (get-token-grammar i)))
t))))) t)))))
`(begin `(begin
(define-tokens t ,(quicksort (hash-table-map terms (lambda (k v) k)) symbol<?)) (define-tokens t ,(sort (hash-table-map terms (lambda (k v) k)) symbol<?))
(define-empty-tokens et ,(quicksort (hash-table-map eterms (lambda (k v) k)) symbol<?)) (define-empty-tokens et ,(sort (hash-table-map eterms (lambda (k v) k)) symbol<?))
(parser (parser
(start ___) (start ___)
(end ___) (end ___)

Loading…
Cancel
Save