Skip to content

Instantly share code, notes, and snippets.

@takscape
Created February 15, 2015 23:09
Show Gist options
  • Save takscape/bac2977f04f80fb0fc2d to your computer and use it in GitHub Desktop.
Save takscape/bac2977f04f80fb0fc2d to your computer and use it in GitHub Desktop.
#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