Skip to content

Instantly share code, notes, and snippets.

@acardona
Created October 3, 2010 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acardona/608905 to your computer and use it in GitHub Desktop.
Save acardona/608905 to your computer and use it in GitHub Desktop.
; find-all-to-all returns a lazy list of lists of object instances
; and we want a map of instance vs. number of appearances
; This one blows up RAM:
(apply merge-with +
(map #(zipmap % (repeat 1))
(find-all-to-all-paths nodes degrees)))
; This one doesn't:
(reduce
#(reduce
(fn [m ^Node nd] (assoc m nd (inc (get m nd 0))))
%1 ; a map
%2) ; a vector of nodes
{}
(find-all-to-all-paths nodes degrees))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment