From 35e966cb13943a7c4ba0a98851a4e1309cf24e83 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 18 Aug 2015 20:14:31 -0400 Subject: [PATCH] Switch to arbitrary hash-order. --- prospect/hash-order.rkt | 12 ++++++++++++ prospect/route.rkt | 8 ++++---- prospect/tset.rkt | 8 ++++---- 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 prospect/hash-order.rkt diff --git a/prospect/hash-order.rkt b/prospect/hash-order.rkt new file mode 100644 index 0000000..e34b2a7 --- /dev/null +++ b/prospect/hash-order.rkt @@ -0,0 +1,12 @@ +#lang racket/base + +(provide hash-order) + +(require data/order) +(require racket/contract) + +(define hash-order + (order 'hash-order + any/c + eq? + (lambda (a b) (< (eq-hash-code a) (eq-hash-code b))))) diff --git a/prospect/route.rkt b/prospect/route.rkt index 6c72c06..19bb767 100644 --- a/prospect/route.rkt +++ b/prospect/route.rkt @@ -67,7 +67,7 @@ (require "canonicalize.rkt") (require "treap.rkt") (require "tset.rkt") -(require data/order) +(require "hash-order.rkt") (require rackunit) @@ -187,10 +187,10 @@ (define sta? (struct-type? a)) (define stb? (struct-type? b)) (cond - [(and sta? stb?) (datum-order (struct-type-name a) (struct-type-name b))] + [(and sta? stb?) (hash-order (struct-type-name a) (struct-type-name b))] [sta? '<] [stb? '>] - [else (datum-order a b)])) + [else (hash-order a b)])) ;; (Treap (U Sigma Wildcard) Matcher) ;; The empty branch-matcher @@ -1564,7 +1564,7 @@ (("__") ((2 (((")") (((")") ("" ("A"))))))) (3 (((")") (((")") ("" ("D")))))))))))))) (check-equal? (matcher->jsexpr M (lambda (v) (map symbol->string (tset->list v)))) S) - (check-requal? (jsexpr->matcher S (lambda (v) (make-tset datum-order (map string->symbol v)))) M))) + (check-requal? (jsexpr->matcher S (lambda (v) (make-tset hash-order (map string->symbol v)))) M))) (module+ test (check-requal? (pretty-print-matcher* diff --git a/prospect/tset.rkt b/prospect/tset.rkt index a5f6b42..735f0e1 100644 --- a/prospect/tset.rkt +++ b/prospect/tset.rkt @@ -17,13 +17,13 @@ tset-member? ) -(require data/order) +(require "hash-order.rkt") (define (tset? t) (treap? t)) (define (datum-tset . elts) - (make-tset datum-order elts)) + (make-tset hash-order elts)) (define (make-tset o elts) (for/fold [(t (tset-empty o))] [(e elts)] (tset-add t e))) @@ -75,7 +75,7 @@ (module+ test (require rackunit) (require data/order) - (define (tset . elts) (make-tset datum-order elts)) + (define (tset . elts) (make-tset hash-order elts)) (check-equal? (tset->list (tset 1 2 3 4 5)) '(1 2 3 4 5)) (check-equal? (tset->list (tset 5 4 3 2 1)) '(1 2 3 4 5)) (check-equal? (tset->list (tset-union (tset 1 2 3) (tset 2 3 4))) '(1 2 3 4)) @@ -88,7 +88,7 @@ (check-equal? (tset-count (tset 1 2 3)) 3) (check-equal? (tset-count (tset)) 0) (check-equal? (tset-count (tset-union (tset 1 2 3) (tset 2 3 4))) 4) - (check-true (tset? (tset-empty datum-order))) + (check-true (tset? (tset-empty hash-order))) (check-true (tset? (tset))) (check-false (tset? 123)) (check-false (tset? (list 1 2 3)))