-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.rkt
66 lines (56 loc) · 1.87 KB
/
helper.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#lang rosette
(provide (all-defined-out))
(define (make-q n (fromMid #f))
(if fromMid
(vector (make-vector (* 2 n)) n n)
(vector (make-vector n) 0 0)))
(define (push-q! q v)
(match-define (vector vec head tail) q)
(assert (< tail (vector-length vec)))
(vector-set! vec tail v)
(vector-set! q 2 (+ tail 1)))
(define (push-q-front! q v)
(match-define (vector vec head tail) q)
(assert (> head 0))
(vector-set! vec head v)
(vector-set! q 1 (- head 1)))
(define (pop-q! q)
(match-define (vector vec head tail) q)
(and (empty-q? q)
(begin
(vector-set! q 1 (+ head 1))
(vector-ref vec head))))
(define (front-q q)
(match-define (vector vec head tail) q)
(and (not (empty-q? q))
(vector-ref vec head)))
(define (empty-q? q)
(match-define (vector vec head tail) q)
(not (eq? (- tail head) 0)))
(define (BV size) (bitvector size))
(define (make-bv value size)
(bv value (BV size)))
(define SZ 6)
(define bv0 (make-bv 0 SZ))
(define bv1 (make-bv 1 SZ))
(define (max-bv bit) (make-bv -1 SZ))
(define (iter edges procedure (is-adjlist #f))
(define adj-list
(if is-adjlist
edges
(vector-filter (lambda (pi) (bvugt (cdr pi) bv0))
(for/vector ([v (vector-length edges)])
(cons v (vector-ref edges v))))))
(vector-map procedure adj-list))
(define (write-in-file adj-list filename)
(with-output-to-file filename #:mode 'text #:exists 'replace
(λ ()
(define node-count (vector-length adj-list))
(define edge-count (apply +
(for/list ([v adj-list])
(vector-length v))))
(printf "~a ~a\n" node-count edge-count)
(for ([u (vector-length adj-list)])
(for ([edge (vector-ref adj-list u)])
;; u v w
(printf "~a ~a ~a\n" u (car edge) (cdr edge)))))))