diff options
author | Teddy <[email protected]> | 2013-08-13 10:38:21 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2013-08-13 10:38:21 +0800 |
commit | 283cc828e86a7177edbacfe3860ca7765661f811 (patch) | |
tree | f5485a7bb393f48a42d4e80af5d261744d916c60 | |
parent | d6765d8d42bd543b414d6ae54392247dd26da649 (diff) |
add test for circular refgc_sweep
-rw-r--r-- | gc.cpp | 2 | ||||
-rw-r--r-- | test/q.scm | 69 |
2 files changed, 71 insertions, 0 deletions
@@ -66,6 +66,8 @@ void GarbageCollector::force() { { #ifdef GC_DEBUG fprintf(stderr, "GC: !!! destroying space 0x%llx. \n", (ull)*l); +#endif +#ifdef GC_INFO cnt++; #endif delete *l; diff --git a/test/q.scm b/test/q.scm new file mode 100644 index 0000000..498cfad --- /dev/null +++ b/test/q.scm @@ -0,0 +1,69 @@ +(define (shl bits) + (define len (vector-length bits)) + (define res (make-vector len)) + (define (copy i) + (if (= i (- len 1)) + #t + (and + (vector-set! res i + (vector-ref bits (+ i 1))) + (copy (+ i 1))))) + (copy 0) + (set! copy '()) + (vector-set! res (- len 1) #f) + res) + +(define (shr bits) + (define len (vector-length bits)) + (define res (make-vector len)) + (define (copy i) + (if (= i (- len 1)) + #t + (and + (vector-set! res (+ i 1) + (vector-ref bits i)) + (copy (+ i 1))))) + (copy 0) + (set! copy '()) + (vector-set! res 0 #f) + res) + +(define (empty-bits len) (make-vector len #f)) +(define vs vector-set!) +(define vr vector-ref) +(define res 0) +(define (queen n) + + (define (search l m r step) + (define (col-iter c) + (if (= c n) + #f + (and + (if (and (eq? (vr l c) #f) + (eq? (vr r c) #f) + (eq? (vr m c) #f)) + (and + (vs l c #t) + (vs m c #t) + (vs r c #t) + ((lambda () (search l m r (+ step 1)) #t)) + (vs l c #f) + (vs m c #f) + (vs r c #f)) + ) + (col-iter (+ c 1)) + ))) + (set! l (shl l)) + (set! r (shr r)) + (if (= step n) + (set! res (+ res 1)) + (col-iter 0))) + ; (set! col-iter '())) + + (search (empty-bits n) + (empty-bits n) + (empty-bits n) + 0) + res) + +(display (queen 8)) |