Created
February 15, 2015 23:09
-
-
Save takscape/bac2977f04f80fb0fc2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require data/heap) | |
(struct item | |
(timestamp priority id event) | |
#:transparent) | |
; x < yなら#t, x > yなら#fを返す。 | |
; x = yなら、bodyの評価結果を返す。 | |
(define-syntax-rule | |
(<>-or x y body) | |
(let ([rx x] | |
[ry y]) | |
(if (< rx ry) | |
#t | |
(if (> rx ry) | |
#f | |
body)))) | |
(define (event<=? e1 e2) | |
(<>-or (item-timestamp e1) (item-timestamp e2) | |
(<>-or (item-priority e1) (item-priority e2) | |
(<>-or (item-id e1) (item-id e2) | |
#t)))) | |
(define heap (make-heap event<=?)) | |
(heap-add! heap (item 0 0 1 -1)) | |
(heap-add! heap (item 0 0 0 -2)) | |
(displayln (heap-min heap)) | |
(displayln "こんにちは、世界") | |
(flush-output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment