Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Hash-join/Racket/hash-join.rkt
Normal file
29
Task/Hash-join/Racket/hash-join.rkt
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#lang racket
|
||||
(struct A (age name))
|
||||
(struct B (name nemesis))
|
||||
(struct AB (name age nemesis) #:transparent)
|
||||
|
||||
(define Ages-table
|
||||
(list (A 27 "Jonah") (A 18 "Alan")
|
||||
(A 28 "Glory") (A 18 "Popeye")
|
||||
(A 28 "Alan")))
|
||||
|
||||
(define Nemeses-table
|
||||
(list
|
||||
(B "Jonah" "Whales") (B "Jonah" "Spiders")
|
||||
(B "Alan" "Ghosts") (B "Alan" "Zombies")
|
||||
(B "Glory" "Buffy")))
|
||||
|
||||
;; Hash phase
|
||||
(define name->ages#
|
||||
(for/fold ((rv (hash)))
|
||||
((a (in-list Ages-table)))
|
||||
(match-define (A age name) a)
|
||||
(hash-update rv name (λ (ages) (append ages (list age))) null)))
|
||||
|
||||
;; Join phase
|
||||
(for*/list
|
||||
((b (in-list Nemeses-table))
|
||||
(key (in-value (B-name b)))
|
||||
(age (in-list (hash-ref name->ages# key))))
|
||||
(AB key age (B-nemesis b)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue