-
-
Save jackfirth/9dbd9bf8900282fc0ccd707401f32f29 to your computer and use it in GitHub Desktop.
Used Rebellion in anger, take 2
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/base | |
(require racket/function | |
racket/match | |
racket/path | |
racket/sequence | |
rebellion/collection/entry | |
rebellion/collection/hash | |
rebellion/streaming/reducer | |
rebellion/streaming/transducer | |
unstable/match) | |
(define (combining-into-hash combiner) | |
(define (update-hash h e) | |
(define k (entry-key e)) | |
(define v (entry-value e)) | |
(hash-update h k (λ (old) (combiner old v)) (λ () v))) | |
(make-fold-reducer update-hash empty-hash #:name 'into-hash)) | |
(struct db-info (hostname path size) #:prefab) | |
(define (db-info-name a-db-info) | |
(match (db-info-path a-db-info) | |
[(pregexp #px"/([^/]+)$" (list _ name)) name])) | |
(define (rktd-file? filename) | |
(bytes=? (path-get-extension filename) #".rktd")) | |
(define (internal-file? filename) | |
(match? filename (regexp #rx"^_") "kvstore" "scratch")) | |
(define (file->records filename) | |
(with-input-from-file filename | |
(λ () (sequence->list (in-port read))))) | |
(define DATA-DIR (build-path (current-directory) "size-data")) | |
(transduce (directory-list DATA-DIR #:build? #t) | |
(filtering rktd-file?) | |
(append-mapping file->records) | |
(bisecting db-info-name db-info-size) | |
(filtering-keys (negate internal-file?)) | |
#:into (combining-into-hash +)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment