Skip to content

Instantly share code, notes, and snippets.

@jackfirth
Forked from samdphillips/00-README.md
Last active October 16, 2019 17:49
Show Gist options
  • Save jackfirth/9dbd9bf8900282fc0ccd707401f32f29 to your computer and use it in GitHub Desktop.
Save jackfirth/9dbd9bf8900282fc0ccd707401f32f29 to your computer and use it in GitHub Desktop.
Used Rebellion in anger, take 2
#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